|
1 | 1 | # Bluepill CAN Bootloader |
2 | 2 |
|
3 | | -A minimal CAN bootloader for Blue Pill STM32F103C8T6 boards. It occupies only the first 2 kB of flash, leaving ~62 kB free for the user application. The bootloader speaks a compact CAN protocol with segmentation identical to the Bluetooth ACS scheme and integrates cleanly with Zephyr via sysbuild; the `app/` folder shows a minimal Zephyr client that can request an update. |
| 3 | +> *The cheapest of bootloaders for the cheapest of STM32 boards!* |
| 4 | +
|
| 5 | +If you are shopping for the cheapest STM32 that can do CAN, you might just end up with the STM32F103C8T6 chip, |
| 6 | +which is also prominently featured on the famous [*Blue Pill*](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html) boards. |
| 7 | +Once you start developing the firmware, you might quickly find that 64kB of flash code space |
| 8 | +is not that much. Then you realize that you still need a bootloader for firmware update, |
| 9 | +so you search around / try to put something with an LLM, and end up with a quarter of the flash |
| 10 | +reserved for the bootloader. |
| 11 | + |
| 12 | +**How about this instead: a CAN bootloader that only takes up 2kB of flash, and is effortlessly integrating into your zephyr RTOS application?** |
4 | 13 |
|
5 | 14 | ## Highlights |
6 | 15 | - 2 kB flash footprint; rest is available for the application. |
7 | | -- Simple CAN protocol with 1 kB page transfers and ACS-style segmentation. |
| 16 | +- Simple CAN protocol using Bluetooth ACS packet segmentation scheme. |
8 | 17 | - Default CAN IDs: prefix `0x7E5` (updater: `prefix+0`, loader: `prefix+1`); standard frames by default (IDE=0). |
9 | | -- App validity ensured by flashing MSP and reset vector **after** all payload pages are written. |
10 | | -- Zephyr module with sysbuild application example; shell command `image update` triggers bootloader mode. |
| 18 | +- Application integrity ensured by flashing MSP and reset vector **after** all payload pages are written. |
| 19 | +- Zephyr module with full sysbuild integration, see [app](./app) example (try `image update` shell command). |
11 | 20 |
|
12 | 21 | ## Flash layout |
13 | 22 | - Bootloader: 0x0800_0000 – 0x0800_07FF (2 kB) |
@@ -53,6 +62,13 @@ Notes: |
53 | 62 | - The sample enables shell and adds `image update` ([app/src/main.cpp](app/src/main.cpp)) which sets the update request flag and reboots. |
54 | 63 | - Partitioning comes from [zephyr/bluepill_partitions.overlay](zephyr/bluepill_partitions.overlay). |
55 | 64 |
|
| 65 | +## Non-zephyr application |
| 66 | + |
| 67 | +When building a non-zephyr application, two things have to be adapted for bootloader support |
| 68 | +(this is true in general): |
| 69 | +1. Modify the linker script to ensure the application's flash area starts where the bootloader's ends. |
| 70 | +2. Write the flash start address to the VTOR register (update vector table address). |
| 71 | + |
56 | 72 | ## Update flow |
57 | 73 | 1. Application sets the update request flag (see `can_bl::set_update_request()` or run `image update` in the sample shell), then resets. |
58 | 74 | 2. Bootloader stays if no valid app or an update was requested; otherwise it jumps to the app. |
|
0 commit comments