Browse Source

F1 Plus: Implement jumperless firmware update

Keir Fraser 4 years ago
parent
commit
e1f280bae0
3 changed files with 13 additions and 16 deletions
  1. 1 1
      scripts/stm32.ld.S
  2. 1 2
      src/floppy.c
  3. 11 13
      src/fw_update.c

+ 1 - 1
scripts/stm32.ld.S

@@ -28,7 +28,7 @@ SECTIONS
     _etext = .;
   } >FLASH
 
-#if MCU == AT32F415
+#if MCU == STM32F1 || MCU == AT32F415
   .flags : {
     _reset_flag = .;
     . = . + 4;

+ 1 - 2
src/floppy.c

@@ -1468,7 +1468,6 @@ static void process_command(void)
         sink_source_prep(&ssb);
         break;
     }
-#if MCU != STM32F1
     case CMD_SWITCH_FW_MODE: {
         uint8_t mode = u_buf[2];
         if ((len != 3) || (mode & ~1))
@@ -1476,13 +1475,13 @@ static void process_command(void)
         if (mode == FW_MODE_BOOTLOADER) {
             usb_deinit();
             delay_ms(500);
-            /* Poke a flag in SRAM1, picked up by the bootloader. */
             _reset_flag = 0xdeadbeef;
             dcache_disable();
             system_reset();
         }
         break;
     }
+#if MCU != STM32F1
     case CMD_TEST_MODE: {
         uint32_t sig1 = *(uint32_t *)&u_buf[2];
         uint32_t sig2 = *(uint32_t *)&u_buf[6];

+ 11 - 13
src/fw_update.c

@@ -159,7 +159,6 @@ static void process_command(void)
         update_prep(u_len);
         break;
     }
-#if MCU != STM32F1
     case CMD_SWITCH_FW_MODE: {
         uint8_t mode = u_buf[2];
         if ((len != 3) || (mode & ~1))
@@ -171,7 +170,6 @@ static void process_command(void)
         }
         break;
     }
-#endif
     default:
         goto bad_command;
     }
@@ -225,7 +223,7 @@ static void update_process(void)
 
 #if MCU == STM32F1
 
-static bool_t enter_bootloader(void)
+static bool_t check_update_strapped(void)
 {
     /* Turn on AFIO and GPIOA clocks. */
     rcc->apb2enr = RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN;
@@ -249,14 +247,6 @@ static bool_t enter_bootloader(void)
 
 #else
 
-static bool_t check_update_requested(void)
-{
-    /* Check-and-clear a magic value poked into SRAM1 by the main firmware. */
-    bool_t match = (_reset_flag == 0xdeadbeef);
-    _reset_flag = 0;
-    return match;
-}
-
 static bool_t check_update_strapped(void)
 {
     int i, j;
@@ -281,6 +271,16 @@ static bool_t check_update_strapped(void)
     return TRUE;
 }
 
+#endif
+
+static bool_t check_update_requested(void)
+{
+    /* Check-and-clear a magic value poked into SRAM1 by the main firmware. */
+    bool_t match = (_reset_flag == 0xdeadbeef);
+    _reset_flag = 0;
+    return match;
+}
+
 static bool_t enter_bootloader(void)
 {
     bool_t upd_requested = check_update_requested();
@@ -288,8 +288,6 @@ static bool_t enter_bootloader(void)
     return upd_requested || upd_strapped;
 }
 
-#endif
-
 int main(void)
 {
     /* Relocate DATA. Initialise BSS. */