diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 6a4a18dc..0f84574a 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -489,10 +489,13 @@ bool init() { chThdSleepMilliseconds(10); - if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { + portapack::cpld::CpldUpdateStatus result = portapack::cpld::update_if_necessary(portapack_cpld_config()); + if ( result == portapack::cpld::CpldUpdateStatus::Program_failed ) { + chThdSleepMilliseconds(10); - // If using a "2021/12 QFP100", press and hold the left button while booting. Should only need to do once. - if (load_config() != 3 && load_config() != 4){ + // Mode left (R1) and right (R2,H2,H2+) bypass going into hackrf mode after failing CPLD update + // Mode center (autodetect), up (R1) and down (R2,H2,H2+) will go into hackrf mode after failing CPLD update + if (load_config() != 3 /* left */ && load_config() != 4 /* right */){ shutdown_base(); return false; } diff --git a/firmware/common/cpld_update.cpp b/firmware/common/cpld_update.cpp index 3055eb3d..fa3e62e5 100644 --- a/firmware/common/cpld_update.cpp +++ b/firmware/common/cpld_update.cpp @@ -33,7 +33,7 @@ namespace portapack { namespace cpld { -bool update_if_necessary( +CpldUpdateStatus update_if_necessary( const Config config ) { jtag::GPIOTarget target { @@ -51,7 +51,7 @@ bool update_if_necessary( /* Run-Test/Idle */ if( !cpld.idcode_ok() ) { - return false; + return CpldUpdateStatus::Idcode_check_failed; } cpld.sample(); @@ -62,7 +62,7 @@ bool update_if_necessary( * in passive state. */ if( !cpld.silicon_id_ok() ) { - return false; + return CpldUpdateStatus::Silicon_id_check_failed; } /* Verify CPLD contents against current bitstream. */ @@ -86,7 +86,7 @@ bool update_if_necessary( cpld.disable(); } - return ok; + return ok ? CpldUpdateStatus::Success : CpldUpdateStatus::Program_failed; } } /* namespace cpld */ diff --git a/firmware/common/cpld_update.hpp b/firmware/common/cpld_update.hpp index 36c87a1b..ea7ad8be 100644 --- a/firmware/common/cpld_update.hpp +++ b/firmware/common/cpld_update.hpp @@ -27,7 +27,14 @@ namespace portapack { namespace cpld { -bool update_if_necessary( +enum class CpldUpdateStatus { + Success = 0, + Idcode_check_failed = 1, + Silicon_id_check_failed = 2, + Program_failed = 3 +}; + +CpldUpdateStatus update_if_necessary( const Config config );