[riot-notifications] [RIOT-OS/RIOT] cpu/stm32: implement reset to bootloader (#14119)

benpicco notifications at github.com
Fri May 22 23:24:43 CEST 2020


### Contribution description

The STM32 line of microcontrollers comes with a [bootloader](https://www.st.com/resource/en/application_note/cd00167594-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf) in the ROM.
It provides the option to flash the device firmware in DFU mode (USB) or via UART or SPI.

To enter the bootloader we have to jump to a specific address in memory, but before reset the CPU to make sure the system is in a known state.

This enables us to use the `usb_board_reset` module on all STM32 platforms.

### Testing procedure

You can use this patch to `examples/default` to add a `dfu` shell command that will restart the board in DFU mode.

```patch
--- a/examples/default/main.c
+++ b/examples/default/main.c
@@ -34,6 +34,24 @@
 #include "net/gnrc.h"
 #endif
 
+extern void usb_board_reset_in_bootloader(void);
+
+static int _dfu_reset(int argc, char** argv)
+{
+    (void) argc;
+    (void) argv;
+
+    usb_board_reset_in_bootloader();
+
+    return 0;
+}
+
+
+static const shell_command_t shell_commands[] = {
+    { "dfu", "enter DFU mode", _dfu_reset},
+    { NULL, NULL, NULL }
+};
+
 int main(void)
 {
 #ifdef MODULE_NETIF
@@ -45,7 +63,7 @@ int main(void)
     (void) puts("Welcome to RIOT!");
 
     char line_buf[SHELL_DEFAULT_BUFSIZE];
-    shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
+    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
 
     return 0;
 }
```

### Issues/PRs references

Always having to press the reset button is tiring after a while (and ESD seems to get the board in bad states sometimes), so this will make working with #12778 much more comfortable. 

You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/14119

-- Commit Summary --

  * cpu/stm32: implement reset to bootloader

-- File Changes --

    A cpu/stm32/bootloader.c (56)
    M cpu/stm32/include/periph/f0/periph_cpu.h (15)
    M cpu/stm32/include/periph/f1/periph_cpu.h (8)
    M cpu/stm32/include/periph/f2/periph_cpu.h (6)
    M cpu/stm32/include/periph/f3/periph_cpu.h (6)
    M cpu/stm32/include/periph/f4/periph_cpu.h (6)
    M cpu/stm32/include/periph/f7/periph_cpu.h (6)
    M cpu/stm32/include/periph/l0/periph_cpu.h (6)
    M cpu/stm32/include/periph/l1/periph_cpu.h (6)
    M cpu/stm32/include/periph/l4/periph_cpu.h (6)
    M cpu/stm32/include/periph/wb/periph_cpu.h (6)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/14119.patch
https://github.com/RIOT-OS/RIOT/pull/14119.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/14119
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20200522/6af1c8ac/attachment-0001.htm>


More information about the notifications mailing list