From 75718c79b9de9ae9ea34a488c2184f79e6cbfbbc Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Fri, 5 May 2023 11:15:49 +0200 Subject: [PATCH 1/5] removed need for cpld mode setup for QFP100 --- firmware/application/portapack.cpp | 20 +++++++++++----- firmware/common/cpld_update.cpp | 37 +++++++++++++++++++++++++----- firmware/common/cpld_update.hpp | 8 ++++++- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 6a4a18dc..9d0fd50f 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -489,12 +489,20 @@ bool init() { chThdSleepMilliseconds(10); - if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { - 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){ - shutdown_base(); - return false; + auto pp_config = portapack_cpld_config(); + auto cpld_update_possible = portapack::cpld::update_possible(); //QFP100 CPLD fails this check. skip CPLD update + auto cpld_update_necessary = cpld_update_possible && portapack::cpld::update_necessary(pp_config); + if ( cpld_update_necessary ) { + auto ok = portapack::cpld::update(pp_config); + + if( !ok ) { + chThdSleepMilliseconds(10); + // 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..6eae8f00 100644 --- a/firmware/common/cpld_update.cpp +++ b/firmware/common/cpld_update.cpp @@ -33,9 +33,7 @@ namespace portapack { namespace cpld { -bool update_if_necessary( - const Config config -) { +bool update_possible() { jtag::GPIOTarget target { portapack::gpio_cpld_tck, portapack::gpio_cpld_tms, @@ -65,13 +63,40 @@ bool update_if_necessary( return false; } + return true; +} + +bool update_necessary( + const Config config +) { + jtag::GPIOTarget target { + portapack::gpio_cpld_tck, + portapack::gpio_cpld_tms, + portapack::gpio_cpld_tdi, + portapack::gpio_cpld_tdo + }; + jtag::JTAG jtag { target }; + CPLD cpld { jtag }; + /* Verify CPLD contents against current bitstream. */ auto ok = cpld.verify(config.block_0, config.block_1); + return !ok; +} + +bool update( + const Config config +) { + jtag::GPIOTarget target { + portapack::gpio_cpld_tck, + portapack::gpio_cpld_tms, + portapack::gpio_cpld_tdi, + portapack::gpio_cpld_tdo + }; + jtag::JTAG jtag { target }; + CPLD cpld { jtag }; /* CPLD verifies incorrectly. Erase and program with current bitstream. */ - if( !ok ) { - ok = cpld.program(config.block_0, config.block_1); - } + auto ok = cpld.program(config.block_0, config.block_1); /* If programming OK, reset CPLD to user mode. Otherwise leave it in * passive (ISP) state. diff --git a/firmware/common/cpld_update.hpp b/firmware/common/cpld_update.hpp index 36c87a1b..f16ed993 100644 --- a/firmware/common/cpld_update.hpp +++ b/firmware/common/cpld_update.hpp @@ -27,7 +27,13 @@ namespace portapack { namespace cpld { -bool update_if_necessary( +bool update_possible(); + +bool update_necessary( + const Config config +); + +bool update( const Config config ); From da6c6bb03c4b2d3f0998215b7bebb3597b8e50ce Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Fri, 5 May 2023 12:46:59 +0200 Subject: [PATCH 2/5] refactoring --- firmware/application/portapack.cpp | 22 ++++++--------- firmware/common/cpld_update.cpp | 43 +++++++----------------------- firmware/common/cpld_update.hpp | 7 +---- 3 files changed, 18 insertions(+), 54 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 9d0fd50f..c2fef913 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -489,20 +489,14 @@ bool init() { chThdSleepMilliseconds(10); - auto pp_config = portapack_cpld_config(); - auto cpld_update_possible = portapack::cpld::update_possible(); //QFP100 CPLD fails this check. skip CPLD update - auto cpld_update_necessary = cpld_update_possible && portapack::cpld::update_necessary(pp_config); - if ( cpld_update_necessary ) { - auto ok = portapack::cpld::update(pp_config); - - if( !ok ) { - chThdSleepMilliseconds(10); - // 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; - } + uint32_t result = portapack::cpld::update_if_necessary(portapack_cpld_config()); + if ( result == 3 /* program failed */ ) { + chThdSleepMilliseconds(10); + // 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 6eae8f00..6baeb68a 100644 --- a/firmware/common/cpld_update.cpp +++ b/firmware/common/cpld_update.cpp @@ -33,7 +33,9 @@ namespace portapack { namespace cpld { -bool update_possible() { +uint32_t update_if_necessary( + const Config config +) { jtag::GPIOTarget target { portapack::gpio_cpld_tck, portapack::gpio_cpld_tms, @@ -49,7 +51,7 @@ bool update_possible() { /* Run-Test/Idle */ if( !cpld.idcode_ok() ) { - return false; + return 1; } cpld.sample(); @@ -60,43 +62,16 @@ bool update_possible() { * in passive state. */ if( !cpld.silicon_id_ok() ) { - return false; + return 2; } - return true; -} - -bool update_necessary( - const Config config -) { - jtag::GPIOTarget target { - portapack::gpio_cpld_tck, - portapack::gpio_cpld_tms, - portapack::gpio_cpld_tdi, - portapack::gpio_cpld_tdo - }; - jtag::JTAG jtag { target }; - CPLD cpld { jtag }; - /* Verify CPLD contents against current bitstream. */ auto ok = cpld.verify(config.block_0, config.block_1); - return !ok; -} - -bool update( - const Config config -) { - jtag::GPIOTarget target { - portapack::gpio_cpld_tck, - portapack::gpio_cpld_tms, - portapack::gpio_cpld_tdi, - portapack::gpio_cpld_tdo - }; - jtag::JTAG jtag { target }; - CPLD cpld { jtag }; /* CPLD verifies incorrectly. Erase and program with current bitstream. */ - auto ok = cpld.program(config.block_0, config.block_1); + if( !ok ) { + ok = cpld.program(config.block_0, config.block_1); + } /* If programming OK, reset CPLD to user mode. Otherwise leave it in * passive (ISP) state. @@ -111,7 +86,7 @@ bool update( cpld.disable(); } - return ok; + return ok ? 0 : 3; } } /* namespace cpld */ diff --git a/firmware/common/cpld_update.hpp b/firmware/common/cpld_update.hpp index f16ed993..4e151932 100644 --- a/firmware/common/cpld_update.hpp +++ b/firmware/common/cpld_update.hpp @@ -27,13 +27,8 @@ namespace portapack { namespace cpld { -bool update_possible(); -bool update_necessary( - const Config config -); - -bool update( +uint32_t update_if_necessary( const Config config ); From e80e4e3bfde2331702cd17f433cfa978d154934a Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Fri, 5 May 2023 12:58:14 +0200 Subject: [PATCH 3/5] refactoring --- firmware/application/portapack.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index c2fef913..2d460157 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -489,8 +489,9 @@ bool init() { chThdSleepMilliseconds(10); - uint32_t result = portapack::cpld::update_if_necessary(portapack_cpld_config()); - if ( result == 3 /* program failed */ ) { + portapack::cpld::CpldUpdateStatus result = portapack::cpld::update_if_necessary(portapack_cpld_config()); + if ( result == portapack::cpld::CpldUpdateStatus::Program_failed ) { + chThdSleepMilliseconds(10); // 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 From df8e79f9e6a2ba205c5e40b8aaaabc2513ff48e5 Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Fri, 5 May 2023 12:58:28 +0200 Subject: [PATCH 4/5] refactoring --- firmware/common/cpld_update.cpp | 8 ++++---- firmware/common/cpld_update.hpp | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/firmware/common/cpld_update.cpp b/firmware/common/cpld_update.cpp index 6baeb68a..fa3e62e5 100644 --- a/firmware/common/cpld_update.cpp +++ b/firmware/common/cpld_update.cpp @@ -33,7 +33,7 @@ namespace portapack { namespace cpld { -uint32_t update_if_necessary( +CpldUpdateStatus update_if_necessary( const Config config ) { jtag::GPIOTarget target { @@ -51,7 +51,7 @@ uint32_t update_if_necessary( /* Run-Test/Idle */ if( !cpld.idcode_ok() ) { - return 1; + return CpldUpdateStatus::Idcode_check_failed; } cpld.sample(); @@ -62,7 +62,7 @@ uint32_t update_if_necessary( * in passive state. */ if( !cpld.silicon_id_ok() ) { - return 2; + return CpldUpdateStatus::Silicon_id_check_failed; } /* Verify CPLD contents against current bitstream. */ @@ -86,7 +86,7 @@ uint32_t update_if_necessary( cpld.disable(); } - return ok ? 0 : 3; + return ok ? CpldUpdateStatus::Success : CpldUpdateStatus::Program_failed; } } /* namespace cpld */ diff --git a/firmware/common/cpld_update.hpp b/firmware/common/cpld_update.hpp index 4e151932..ea7ad8be 100644 --- a/firmware/common/cpld_update.hpp +++ b/firmware/common/cpld_update.hpp @@ -27,8 +27,14 @@ namespace portapack { namespace cpld { +enum class CpldUpdateStatus { + Success = 0, + Idcode_check_failed = 1, + Silicon_id_check_failed = 2, + Program_failed = 3 +}; -uint32_t update_if_necessary( +CpldUpdateStatus update_if_necessary( const Config config ); From 7116f92d07c6984e8d50fbe7008ef74f32d996bb Mon Sep 17 00:00:00 2001 From: bernd-herzog Date: Fri, 5 May 2023 13:39:04 +0200 Subject: [PATCH 5/5] fixed spelling --- firmware/application/portapack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 2d460157..0f84574a 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -494,7 +494,7 @@ bool init() { chThdSleepMilliseconds(10); // 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 + // 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;