For detailed explanation of concepts see this document
Term | Explanation |
---|---|
BOOT_ADD0 & BOOT_ADD1 | An option byte (programmable setting) ; set in STM32 Cube Programmer |
Boot Pin | A hardware pin on the STM32F767ZI ; controls which memory area to boot into |
STM32 Cube Programmer | An application which allows the flashing, and memory manipulation of STM32 MCU’s |
System Bootloader | A bootloader made by STM located at memory address: 0x0100 0000. Enables flashing the MCU via CAN, UART, SPI and more… |
-
Boot Option Bytes:
- There are two option bytes relevant to CAN Flash, these are BOOT_ADD0 and BOOT_ADD1
- Set BOOT_ADD0 to value 0x80 (address 0x00200000), and BOOT_ADD1 to value 0x40 (address 0x00100000) in Option Bytes of STM32CubeProgrammer. If option byte values are already configured as such, leave as is. See Figure 1 to see different boot addresses
- These options bytes are chosen by the firmware on reset via the boot pin. If the boot pin is LOW, BOOT_ADD0 is chosen and vice versa.
- Verify:
- Tie the boot pin to high ; choose BOOT_ADD1
- In STM32 Cube Programmer: go into MCU Core tab > press any reset option
- In STM32 Cube Programmer: go into MCU Core tab > press run and then halt
- In STM32 Cube Programmer: go into MCU Core tab > check if the LR ( instruction pointer ) register is in the memory range of 0x1FFX XXXX
- If so, the MCU is currently in system bootloader
-
Read/Write protection option bytes:
- While BOOT_ADD0 and BOOT_ADD1 are the most important, other option bytes must be left in their DEFAULT to enable reading and writing to flash memory
- These are the write protection option bytes: nWRP# and read protection option byte: RDP
- Ensure all these option bytes are left as their default configuration. See Figure 2 for default option bytes.
- For RDP: DO NOT CHANGE IT TO CC (Level 3 Protection) → DEBUG OPTIONS WILL BE DISABLED FOREVER
- Verify:
- Check with Figure 2
- In STM32 Cube Programmer : go into Erasing & Programming tab > do a full chip erase for flash memory
- If it doesn’t work, your read/write protections are set wrong
-
Can-prog download, and raspberry pi setup:
- In order to program the STM32 MCU with can-prog you will need a computer with a CAN interface → in testing we used a raspberry pi with a CAN Hat for our CAN bus setup
- For flashing with CAN we will need a bitrate of 125000 for our CAN network
- Using
ifconfig
you can check which networks are set up on your system → you should see either can0 or can1 ; either is fine to use, we will use can1 - Verify:
- Using
ip -details -statistics link show can1
; see if the CAN network is configured at the required bitrate of 125000. If so, skip the steps below - Using
sudo ip link set can1 down
; pull the CAN network down - Using
sudo ip link set can1 type can bitrate 125000
; configure the CAN network to use the required bitrate of 125000 - Using
sudo ip link set can1 up
; bring the CAN network up again
- Using
- Git clone this repo’s version of can-prog and install
-
CAN - 2 Wiring, BOOT pin setup and CAN Transceiver:
- You will need a CAN transceiver for the STM32. We require the CAN-2 interface on the STM32, specifically pins PB_5 for CAN_RX and PB_13 for CAN_TX.
- Drive BOOT pin high (See Figure 3)
- Connect the CAN bus by connecting CAN2_RD from PB_5 and CAN2_TD from PB_13 into CAN_RX and CAN_TX on the CAN transceiver. Note that there are other CAN2_RD and CAN2_TD pins, but it must be from PB_5 and PB_13. Also note that there are multiple PB_5 and PB_13 pins, and that PB_5 and PB_13 must be connected to the ones in Figure 4.a OR Figure 4.b, but must not be combined (i.e. do not connect PB_5 from Figure 4.a, and PB_13 from Figure 4.b)
- Write the binary to the board
- i.e canprog -n can0 -f bin stm32 write [file_name] -a 0x08000000
- -n → interface name
- -f → file format (hex, bin)
- -a → address to write → default is 0x0800 0000 DON’T CHANGE
- [file_name] → file to write
- i.e canprog -n can0 -f bin stm32 write [file_name] -a 0x08000000
- Run the flashed application
- i.e canprog -n can0 stm32 go -a 0x08000000
- Unlock, lock, and speed commands with can-prog tool are not necessary
- The unlock and lock commands change the readout protection and option bytes ; in our use case we do not need to lock the chip after flashing → therefore do not use
- The speed command changes the bitrate of the CAN-2 interface on the STM32, however the default is already set correctly upon system reset → therefore do not use