6464#define BOOTMGR_HASH_SIZE 32
6565#define BOOTMGR_BUFF_SIZE 512
6666
67- #define BOOTMGR_WAIT_SAFE_MODE_0_MS 3000
68- #define BOOTMGR_WAIT_SAFE_MODE_0_BLINK_MS 500
67+ #define BOOTMGR_WAIT_SAFE_MODE_0_MS 500
6968
7069#define BOOTMGR_WAIT_SAFE_MODE_1_MS 3000
7170#define BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS 250
7271
73- #define BOOTMGR_WAIT_SAFE_MODE_2_MS 1500
74- #define BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS 100
72+ #define BOOTMGR_WAIT_SAFE_MODE_2_MS 3000
73+ #define BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS 250
74+
75+ #define BOOTMGR_WAIT_SAFE_MODE_3_MS 1500
76+ #define BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS 100
7577
7678//*****************************************************************************
7779// Exported functions declarations
@@ -85,6 +87,7 @@ static void bootmgr_board_init (void);
8587static bool bootmgr_verify (_u8 * image );
8688static void bootmgr_load_and_execute (_u8 * image );
8789static bool wait_while_blinking (uint32_t wait_time , uint32_t period , bool force_wait );
90+ static bool safe_boot_request_start (uint32_t wait_time );
8891static void wait_for_safe_boot (sBootInfo_t * psBootInfo );
8992static void bootmgr_image_loader (sBootInfo_t * psBootInfo );
9093
@@ -260,24 +263,33 @@ static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force
260263 return MAP_GPIOPinRead (MICROPY_SAFE_BOOT_PORT , MICROPY_SAFE_BOOT_PORT_PIN ) ? true : false;
261264}
262265
266+ static bool safe_boot_request_start (uint32_t wait_time ) {
267+ if (MAP_GPIOPinRead (MICROPY_SAFE_BOOT_PORT , MICROPY_SAFE_BOOT_PORT_PIN )) {
268+ UtilsDelay (UTILS_DELAY_US_TO_COUNT (wait_time * 1000 ));
269+ }
270+ return MAP_GPIOPinRead (MICROPY_SAFE_BOOT_PORT , MICROPY_SAFE_BOOT_PORT_PIN ) ? true : false;
271+ }
272+
263273//*****************************************************************************
264274//! Check for the safe mode pin
265275//*****************************************************************************
266276static void wait_for_safe_boot (sBootInfo_t * psBootInfo ) {
267- if (wait_while_blinking (BOOTMGR_WAIT_SAFE_MODE_0_MS , BOOTMGR_WAIT_SAFE_MODE_0_BLINK_MS , false)) {
268- // go back one step in time
269- psBootInfo -> ActiveImg = psBootInfo -> PrevImg ;
277+ if (safe_boot_request_start (BOOTMGR_WAIT_SAFE_MODE_0_MS )) {
270278 if (wait_while_blinking (BOOTMGR_WAIT_SAFE_MODE_1_MS , BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS , false)) {
271- // go back directly to the factory image
272- psBootInfo -> ActiveImg = IMG_ACT_FACTORY ;
273- wait_while_blinking (BOOTMGR_WAIT_SAFE_MODE_2_MS , BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS , true);
279+ // go back one step in time
280+ psBootInfo -> ActiveImg = psBootInfo -> PrevImg ;
281+ if (wait_while_blinking (BOOTMGR_WAIT_SAFE_MODE_2_MS , BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS , false)) {
282+ // go back directly to the factory image
283+ psBootInfo -> ActiveImg = IMG_ACT_FACTORY ;
284+ wait_while_blinking (BOOTMGR_WAIT_SAFE_MODE_3_MS , BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS , true);
285+ }
274286 }
275287 // turn off the system led
276288 MAP_GPIOPinWrite (MICROPY_SYS_LED_PORT , MICROPY_SYS_LED_PORT_PIN , 0 );
277289 // request a safe boot to the application
278290 PRCMRequestSafeBoot ();
279291 }
280- // uninit the safe boot pin
292+ // deinit the safe boot pin
281293 mperror_deinit_sfe_pin ();
282294}
283295
0 commit comments