cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect to the STM32 CAN Bootloader interface

Filip SCHWANK
ST Employee

The bootloader inside STM32 families uses the protocol described in AN3154. It is supported by the STM32F1, F2, F4, F7, L4 series.

The purpose of this article is to give a guide on how to connect to a STM32 CAN bootloader Target, to erase and program the device through this interface.
First, one needs to identify if the targeted MCU supports the CAN bootloader. The CAN peripheral on the device is condition necessary, but not sufficient. In this guide the STM32F429ZI Nucleo will be used as an example.

10.jpg


The procedure can be summed up in couple of steps:

1.    How to activate the bootloader mode on target device.
2.    How to identify the CAN bootloader pins.
3.    How to connect to the CAN interface.
4.    How to program the MCU using CAN Bootloader
5.    How to program the MCU using CAN Bootloader – from a script
6.    How to connect to the FDCAN bootloader
 


 

  1. How to activate the bootloader mode on target device

  • The starting point is AN2606. There one can find the version of the bootloader inside the MCU, supported peripherals and pinout. For the F429 it is the Chapter 33.
  • At the start of the Chapter 33 a Pattern 5 is mentioned
11.png
  • Referring to the pattern, one of the options is to set the hardware BOOT0 pin to logic ‘1’, activating the bootloader after Reset of the MCU
  • The BOOT0 pin location can be found in the schematic of the Nucleo
 
12.png
 
  • The pin is on the unmounted CN11 connector, right next to VDD so it can be easily tied up by a wire.
  • One can also verify that the bootloader is indeed running, by connecting to the onboard ST-Link with CubeProgrammer
  • The connection to the debugger can be done by SWD with default parameters.

  • In the CPU tab, when the core is Run and then Halted, the ProgramCounter should be in the 0x1FFF XXXX range, as opposed to 0x0800 XXXX range for normal Flash execution.
 
13.png
 
  • Now that the bootloader is ready, one can move to the next step.

 
  1. How to identify the CAN bootloader pins

  • Back in AN2606, Table 69 tells that the CAN(2) peripheral is indeed supported by the bootloader FW and is on pins PB5, PB13.
 
14.png
 
 
15.png
 
  • This step is crucial, as some bootloaders support CAN, but then the pins that are used (CAN interface can be used by couple of sets of pins, but only one set is selected for the BL) are not routed out on some package versions (usually smaller), or omitted on the certain evaluation PCB.

 
  1. How to connect to the CAN interface

  • Now that the MCU is running in bootloader mode, pins are identified, it is time to connect the interface.
  • The ideal case is when the PCB has CAN transceivers, then it should be unplugged from the bus and connected only with the bootloader host (as some message IDs may be shared with the IDs described in the AN3154). However, the majority of STM32 evaluation PCBs (Nucleo, Discovery, Eval) has no transceiver.
  • The tool that can act as bootloader host is the PC with CubeProgrammer and ST-LinkV3
 
16.jpg
 
  • This tool features no transceivers either, so to connect to a PCB with transceivers an add-in board with transceiver is required, or the CAN Rx, Tx pins should be accessible on the PCB. Connection without transceivers also ensures that there are only two nodes on the ‘bus’ (bootloader target and host).
  • The ST-LinkV3 comes with a daughterboard, which features CAN pins with diodes for the connection to the target. No other tools are needed, only a set of wires to connect the CAN (T_CAN_RX, T_CAN_TX) pins, GND (accessible on headers of the daughterboard) and VCC (T_CAN_VCC).
17.png
 
  • As opposed to for example UART, the Rx and Rx must be connected together (to ensure that the 'bus' can hear the message on both sides) and Tx lines connected through the diodes. 
 
18.jpg
 
  • Using the ST-Link V3 with the daughterboard mounted, 4 wires and a jumper, connection to the CAN BL can be achieved. On the picture above, GND, VCC, Rx, Tx must be connected and CAN_ON jumper fitted.

 
  1. How to program the MCU using CAN Bootloader

With the hardware connection set up, both boards connected to power via USB, the connection can be now established. Moving back to CubeProgrammer, the connection is as simple as selecting the CAN interface. If the connection is successful, the content of the memory should appear.

  • Select the ST-Link V3
 
19.png
 
  • Port is the CAN
 
20.png
 
  • Baudrate and other settings should be kept at default values

 
21.png
 
  • When the connection is successful, content of the memory should appear

22.png
 
  • The device can now be programmed as when using the CubeProgrammer with SWD/JTAG connection, only without the debug capability. Binary can be loaded through the Erasing and Programming tab, Option bytes can be modified, only the CPU tab will not work.

 

  1. How to program the MCU using CAN Bootloader – from a script

The CubeProgrammer also comes with CLI version (command-line-interface). That can be used for automation of the programming process through the bootloader.
The CLI version is in the same installation folder as the CubeProgrammer GUI. Usually:
 

C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ STM32_Programmer_CLI.exe


 Invoking the CubeProgrammer CLI from command line without any parameters will list all possible configurations.
 

23.png
 

In this example, the CAN configuration can be used as follows:
 

STM32_Programmer_CLI.exe -c port=CAN 

 

24.png


Downloading a binary to the device is then as simple as providing the connection parameters and a path to the binary:
 

STM32_Programmer_CLI.exe -c port=CAN -d C:\STM32F429ZI_Nucleo_144.hex   

 

25.png


These commands can be used in a script on the host PC, allowing the automation of e.g. programming process.
 

  1. How to connect to the FDCAN bootloader

Unfortunately, currently there is no such solution as for the standard CAN. The FDCAN bootloader protocol described by the AN5405 is slightly different from the CAN BL protocol, therefore ST-Link V3 bridge cannot be used. ST-Link V3 would also require an interface (another MCU) to forward the CAN messages to the FDCAN bus.
Since the FDCAN BL is using the full features of the FDCAN bus in the default configuration (FD mode with Bit Rate Switching), any old CAN solution cannot be used.
There are two options what to use.

  • Second MCU acting as FDCAN BL host and providing the BL commands on e.g. UART. This solution is in preparation and needs to be validated.
  • OpenBootloader, or different type of custom bootloader – sacrificing part of the user Flash for the BL.
    •  OpenBootloader is currently supported by the G4 family within the STM32G4Cube \STM32Cube_FW_G4_V1.x.0\Projects\STM32G474E-EVAL\Applications\OpenBootloader
Comments
Gsing.2
Associate II

Hii

I am having problem with communication to CAN Bootloader.

Can you help me in sorting out the problem?

thanks

GhostSherry
Associate II

Goodday,

Can you please clarify this statement: "This tool features no transceivers either, so to connect to a PCB with transceivers an add-in board with transceiver is required", what do you mean by an add-in board?

mantoz
Associate

Hi and thanks for the nice article!

After some time I'd like to know if something new is available regarding point 6.

Is some ready-to-use solution available to connect to the FDCAN bootloader? @Filip SCHWANK 

Thanks!

johnsonDeng
Associate

Could you please inform me of the version of CubeProgrammer you used in this article? The latest 2.16.0 interface is different from the CubeProgrammer you used in this article

Zeeshan3154
Associate

Hello! Where did you get the Bridge CAN schematic? The figure name is "17.png" in this article.

Filip SCHWANK
ST Employee

Hi,

@Gsing.2 ,

You can submit your issue to the community forum or our ticket system https://st.com/ols

 

@GhostSherry 

The STLinkV3 does not feature any transceivers onboard, only the CAN pins directly from the MCU, therefore if a PCB you want to connect to has the standard 9 pin connector for example, there is usually a transceiver. In which case you would need another board between STLink and the PCB with transceiver for the STLink so that both boards can communicate with each other through CAN.

 

@mantoz 

The STLinkV3PWR features the STM32H7 that supports FDCAN, however the CubeProrammer support is still under development. The latest release target is Q3 2024. 

 

@johnsonDeng 

The CubeProrammer version used in this article was 2.7.0.

 

@Zeeshan3154 

The diagram comes from the documentation for the STLinkV3. I took a snippet to depict the circuitry of the CAN bridge. 

 

 

Best regards,

Filip Schwank & TOMAS Team

 

 

andrewmu
Associate

Hello, can the PB12 pin be configured as the CAN2 Rx instead of the PB5 pin for the Bootloader? I'm using the STM32F446RE for my application.

Version history
Last update:
‎2024-08-04 11:44 PM
Updated by:
Contributors