How to flash firmware: Difference between revisions

From STorM32-BGC Wiki
Jump to navigation Jump to search
No edit summary
 
(97 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The following describes the process of flashing firmware onto v1.1/v1.2/v1.3/v1.31 boards.
This page is for instructions on how to flash firmware into {{WARNING|'''''v3.x'''''}} and {{WARNING|'''''v4.x'''''}} STorM32 boards.


__TOC__
For instructions on how to flash {{WARNING|'''''v1.3x'''''}} STorM32 boards, please consult the article [[How to flash v1.x STorM32 boards]].


== Flashing Firmware using a USB-TTL Adapter ==
For the v3.x/v4.x boards two situations can be distinguished:


'''1.''' You need a standard usb-ttl adapter (FTDI, CP2102, ..., {{WARNING|'''not'''}} PL2303). Ensure that it is working (drivers installed, etc.).
* '''''Upgrading''''': If your v3.x/v4.x board already runs a valid STorM32 firmware which you want to upgrade (or downgrade), then this is the recommended procedure to choose, since it is most simple. Go to [[#Updating Firmware|Updating Firmware]].


'''2.''' You don't have to worry if it is a 5 V adapter or not, the pins on the STorM32-BGC board we are going to connect the adapter to are 5 V tolerant.
* '''''First-time flashing''''': In all other cases, when your v3.x/v4.x board has not yet a STorM32 firmware installed or you don't want to use the upgrade method, this is what needs to be done. Go to [[#First-Time Flashing|First-Time Flashing]].


'''3.''' The adapter has to be connected to UART1, which is {{WARNING|'''not'''}} the port labelled UART on the board, the correct pins are found on the port labelled RC! Namely:
{{COMMENT|The same distinction also exists for flashing NT modules, see [[How to flash NT Modules]].}}


:RC-GND = GND -> connect it to GND of the usb-ttl adapter
__TOC__
 
:RC-0 = Uart1-Rx -> connect it to Tx of the usb-ttl adapter
 
:RC-1 = Uart1-Tx -> connect it to Rx of the usb-ttl adapter
 
The connections between adapter and board are shown for v1.2/v1.3/v1.31 and v1.1 boards in the scheme below.
 
{{COMMENT|Neither a 5 V nor a 3.3 V nor any other power pin on the usb-ttl adapter is used... only three wires running from adapter to board.}}<br/>
 
:[[File:Stom32-bgc-flashing-w-usbttladapter-connections-02.jpg|800px]]
 
'''4.''' The board should be powered via the USB plug or through a battery/power supply connected to the "+" and "-" pads.


{{COMMENT|If the board has already a firmware installed and this is the first-time it is connected via USB to a PC, then Win 7 will start installing the USB driver. {{WARNING|'''Do NOT interrupt the install process'''}}. See also the comments under point '''12''' below.}}
== Updating Firmware ==


'''5.''' Run the GUI and go to the {{GUI|Flash Firmware}} tab (see the screenshot).
If your v3.x/v4.x STorM32 board runs already a firmware, then this is the canonical procedure for upgrading:


{{COMMENT|In principle you can use any GUI version to flash any version of the firmware. However, a GUI which is of the same or higher version than the firmware provides easy access to the firmware via the selector fields on the {{GUI|Flash Firmware}} window.}}
'''1.''' Connect the STorM32 board via its USB port to the PC.


:[[File:Stom32-wiki-flash-firmware-01.jpg|640px]]
:{{COMMENT|If this is the first time the board is connected via USB to the PC, then Win will immediately start with installing the appropriate USB driver. This takes quite a while (several minutes). Please, be patient and wait until Win reports that the device is ready for use. {{WARNING|'''Do not interrupt the driver installation process before it is completed'''}}. Otherwise things can get messed up quite considerably, and installing the driver later can be a challenge.}}


'''6.''' Select the correct board and desired firmware version from the selectors.
'''2.''' Run the GUI and go to the {{GUI|Flash Firmware}} tab (see the screenshot).


{{COMMENT|With these two selectors the correct firmware .hex file is chosen in the {{GUI|Selected Firmware Hex File}} field.}}<br/>
:{{COMMENT|In principle you can use any GUI version to flash any version of the firmware. However, a GUI which is of the same or higher version than the firmware which is to be installed provides easy access to the firmware via the selector fields on the {{GUI|Flash Firmware}} window.}}
{{COMMENT|It is {{WARNING|'''important'''}} to choose the correct board version; otherwise the board will not functions correctly.}}


'''7.''' Select {{GUIPARAM|System Bootloader @ UART1}} in the {{GUI|STM32 Programmer}} field.
::[[File:Storm32-wiki-upgrade-firmware-v3x.jpg|640px]]


'''8.''' In the {{GUI|Com Port}} field select the COM port which your usb-ttl adapter is connected to.
'''3.''' In the combo boxes {{GUIFIELD|Board}} and {{GUIFIELD|Firmware Version}} select the correct board and desired firmware version.


{{COMMENT|We are talking here about the {{GUI|Com Port}} field in the {{GUI|Flash Firmware}} tab, not the {{GUI|Port}} field in the lower left of the main window.}}<br/>
:{{COMMENT|With these two selectors the correct firmware .hex file is chosen in the {{GUIFIELD|Selected Firmware Hex File}} field.}}<br/>
{{COMMENT|If you are not sure which the correct COM port is, then disconnect the usb-ttl adapter from the PC, inspect the drop-down list and memorize the available COM ports, connect your adapter and wait until its enumerated by Win, and finally inspect the drop-down list and chose the newly added COM port.}}
:{{COMMENT|It is {{WARNING|'''important'''}} to choose the correct board version; otherwise you will flash a wrong firmware and the board will not functions correctly.}}


'''9.''' If required or desired check the {{GUI|Perform full chip erase}} check button.
'''4.''' In the {{GUIFIELD|STM32 Programmer}} field select {{GUIPARAM|Upgrade via STorM32 USB port}}.


'''10.''' This is now {{WARNING|'''important'''}}: Before hitting the {{GUI|Flash Firmware}} button one has to ready the board for being flashed. For that, with the board connected to power, one has to
'''5.''' In the {{GUIFIELD|Port}} field select the COM port which your STorM32 board is connected to (it's the same port you choose when connecting to the GUI).
* press and hold down both the Reset and Boot0 buttons (the exact sequence of when which button is pressed is irrelevant, as long as they're both hold down)
* then, release the Reset button while still holding down the Boot0 button
* then, release also the Boot0 button
This may sound complicated, but one will quickly realize that this can be done by "rolling" the finger tip from the left to right.


{{COMMENT|Both LEDs will go off; they should appear "dead".}}
:{{COMMENT|If you are not sure which the correct COM port is, then disconnect the STorM32 board from the PC, inspect the drop-down list and memorize the available COM ports, reconnect the STorM32 board and wait until it is enumerated by Win, inspect the drop-down list again, and chose the newly added COM port.}}


:[[File:Storm32-wiki-flash-firmware-key-sequence-01.jpg|640px]]
'''6.''' If required or desired check the {{GUIFIELD|Perform full chip erase}} check button.


'''11.''' Finally, hit the {{GUI|Flash Firmware}} button.
'''7.''' Remind you about the upgrading process by reading the usage information.


Now a black window (DOS console) should open and run the flash loader program, as shown in the screenshot. Wait until it's finished (takes some seconds). If the program doesn't proceed and asks to "Press any key to continue" the board is write protected. See "Removing Write Protection" below.
'''8.''' Finally, hit the {{GUIFIELD|Flash Firmware}} button.


:[[File:flash.png|640px]]
'''9.''' Now a black window (DOS console) should open and run the STM32CubeProgrammer flash program, as shown in the screenshot. Wait until it is finished (takes some seconds). The STorM32 board will be reset and start running.


'''12.''' The STorM32 board will be reset and start running. If this is the first-time flash of the firmware and if the board is connected via USB to a PC, then Win 7 will immediately start with installing the appropriate USB driver. This takes quite a while (several minutes). Please, be patient and wait until Win 7 reports that the device is ready for use. {{WARNING|'''Do not disconnect the board from the PC or otherwise interrupt the driver installation process before it is completed'''}}. This can mess up things quite considerably, and installing the driver later can be a challenge.
::[[File:Storm32-wiki-flash-firmware-dosbox.jpg|640px]]


=== Trouble Shooting ===
==== Trouble Shooting ====
----
* The STorM32 board has no power: Connect the board to the computer via USB to power it.
* Wrong serial port is selected in the tool.
* The black DOS box does not show up: Typically this happens because the firmware .zip file was not extracted.
* The black DOS box shows up, displaying a [OK] and [KO] together with an error message "No response from target, the bootloader cannot be started": The error message is correct, the bootloader could not be started, because e.g. a wrong COM port was selected, the STorM32 board wasn't put into bootloader mode, the connections are incorrect, and so on.
* The above steps run and the black DOS box shows the first two [OK] messages, but the downloading and verifying message lines are not be present and a firmware is not flashed: Go to [http://www.olliw.eu/storm32bgc-v1-wiki/How_to_flash_firmware#Removing_Read.26Write_Protections Removing Read&Write Protections].
* The verify fails: First double-check that you are not using an outdated GUI version. Otherwise, click the {{GUIFIELD|Perform full chip erase}} check button and repeat. Note: This will also erase any setting; if needed save the settings to a file beforehand using the option in the "Setting" menu.
* The USB is not working: Please double-check that you've selected the correct board version in the {{GUIFIELD|STorM32-BGC board}} field.
* In case of troubles with the USB driver, consult the [[STorM32_FAQ#Which_drivers_are_needed_for_the_USB.3F|FAQ: Which drivers are needed for the USB?]].
* On Win XP flashing via the GUI using the USB-TTL adapter will fail. See the section [[#Flashing Procedure for Win XP|Flashing Procedure for Win XP]].
* In order to test if the USB-TTL adapter is working properly, one can connect its Rx and Tx pins with each other, and use a terminal program, such as HTerm. When you send characters they should be immediately received.


* In order to test if the usb-ttl adapter is working properly, you can connect its Rx and Tx pins with each other, and use a terminal program, such as Hterm. When you send characters they should be immediately received.
== First-Time Flashing ==
* If the USB is not working, please double-check that you've selected the correct board version in the {{GUI|STorM32-BGC board}} field.
* In case you have troubles with the USB driver, it can be downloaded from [http://www.st.com/web/en/catalog/tools/PF257938 here], see also the [[STorM32_FAQ#Which_drivers_are_needed_for_the_USB.3F|FAQ: Which drivers are needed for the USB?]].
* In case the black DOS box doesn't show up, check if the firmware .zip file was extracted.
* Some few boards are shipped with a read&write protection of the flash enabled. In that case all the above steps will successfully run though, except that a firmware is not actually flashed (the black DOS box will show [OK]s, but the flashing and verifying lines will not show up). Go to [[#Removing Read&Write Protections|Removing Read&Write Protections]].
* On Win XP flashing via the GUI using the usb-ttl adapter will fail (the compiled .exe version of the flashloader doesn't work on XP, sorry for that). See the next sub section [[#Flashing Procedure for Win XP|Flashing Procedure for Win XP]].
* If the verify fails then first check that you are not using an outdated GUI version. Otherwise, check the {{GUI|Perform full chip erase}} check button and repeat. This will however also erase any setting which you might have stored before. In that case save the settings to a file beforehand using the option in the "Setting" menu.


=== Flashing the Micro STorM32 Board ===
If your v3.x/v4.x STorM32 board has not yet been flashed with a STorM32 firmware, or runs a different firmware, then one needs to resort to grass roots flashing methods for flashing the firmware (first-time flashing).
----


The Micro STorM32 board doesn't provide BOOT0 and RESET buttons. Here, BOOT0 must be shortcut to 3.3 V by e.g. soldering a wire as shown in the picture below, and powering up the board to bring it into bootloader mode.
In general, the STM32 micro-controllers which are used in the STorM32 boards provide two different built-in methods for flashing firmware:  
:[[File:MicroStorm32.png|387px]]


=== Flashing Procedure for Win XP ===
# via the serial system bootloader using a USB-TTL adapter
----
# via SWD using a ST-Link programmer


'''1.''' Download and install the Flash Loader Demonstrator from [http://www.st.com/web/en/catalog/tools/PF257525].
For v3.x/v4.x boards method 1. is relatively convenient, since these boards have the USB-TTL adapter integrated and thus no additional hardware is needed for doing this. However, the grain of salt is that the BOOT0 pin needs to be temporarily shortened to GND by closing the solder jumper.


'''2.''' Do step 1 to 4 under [[#Flashing Firmware using a USB-TTL Adapter|Flashing Firmware using a USB-TTL Adapter]].
Method 2. requires a dedicated ST-Link programmer device. These are cheaply available, but nevertheless it is an additional piece of hardware, which one needs.


'''3.''' Start the Flash Loader Demonstrator, choose the correct COM port and then press the Boot0 and Reset buttons on the controller as described in step 10 under [[#Flashing Firmware using a USB-TTL Adapter|Flashing Firmware using a USB-TTL Adapter]]. Click next.
=== Flashing via System Bootloader ===


{{COMMENT|The usb-ttl adapter needs to be connected to the PC before the Flash Loader Demonstrator is started}}.
'''1.''' '''''Important''''': Find the BOOT0 solder jumper on the STorM32 board, and close it with a drop of solder.


:[[File:XPFirmware1.jpg]]
'''2.''' Connect the STorM32 board via the USB plug to the PC (it is important to do that after step 1, alternatively you can reset/repower the board).


'''4.''' If you have connected the usb-ttl adapter correctly and pressed the buttons you should see a green light and it should say that the target is readable. Click next.
'''3.''' Run the GUI and go to the {{GUI|Flash Firmware}} tab and choose your settings:


:[[File:XPFirmware2.jpg]]
:* In the combo boxes {{GUIFIELD|Board}} and {{GUIFIELD|Firmware Version}} select the correct board and desired firmware version.
:* In the {{GUIFIELD|STM32 Programmer}} field Select {{GUIPARAM|System Bootloader @ UART1}}.
:* In the {{GUIFIELD|Port}} field select the COM port which your STorM32 board is connected to.


'''5.''' The target on the next page should be correct, otherwise you will have to choose the controller and click next.
::[[File:Storm32-wiki-flash-firmware-systembootloader-v3x.jpg|640px]]


:[[File:XPFirmware3.jpg]]
'''4.''' Finally, hit the {{GUIFIELD|Flash Firmware}} button.


'''6.''' Browse to the correct firmware file and click next. The upgrade will start.
'''5.''' Now a black window (DOS console) should open and run the STM32CubeProgrammer flash program, as shown in the above. Wait until it is finished (takes some seconds).


:[[File:XPFirmware4.jpg]]
'''6.''' '''''Important''''': Do not forget to open the BOOT0 solder jumper.


'''7.''' After the firmware is downloaded to the controller you must restart it and it is now ready for use.
=== Flashing via SWD ===


:[[File:ready.jpg]]
'''1.''' You need a STLink/V2 programmer. To buy one just search for e.g. "STlink" on ebay, aliexpress, etc. They look something like this:
::[[File:ST_Link_V2.jpg|250px]]


=== Removing Read&Write Protections ===
'''2.''' Connect the SWD pins from the STorM32 board to the pins of your ST-Link programmer. The SWD pins on the v3.3 board are near the USB plug, anf on the v4.1 board near the LEDs.
----


Some boards are unfortunately shipped with a read/write protection on the flash. As a result, storing parameters permanently in the board and flashing new firmware will fail. To remove the protections do the following:
:"SWDIO" to "SWDIO"


'''1.''' Follow steps 1-3 of [[#Flashing Procedure for Win XP|Flashing Procedure for Win XP]] for downloading, installing and starting the Flash Loader Demonstrator of STMicroelectronics.
:"SWCLK" to "SWCLK"


'''2.''' Do also step 4, you will now however see the message '''WARNING: When you click "Remove Protection" the flash will be mass erased and all data will be lost.'''. Click on '''Remove Protection'''. This will remove the protections, as well as fully erase the flash memory.
:"GND" to "GND"


'''3.''' Close the Flash Loader Demonstrator after it has completed and restart the STorM32 board. The LEDs are not operational since also any firmware got erased in the previous step.  
'''3.''' Power up your STorM32 over USB, and connect your ST-Link programmer over USB to a PC.


'''4.''' Go back to the [[#Flashing Firmware using a USB-TTL Adapter|Flashing Firmware using a USB-TTL Adapter]] section in the above and flash the firmware anew.  
'''4.''' In the GUI go to the {{GUI|Flash Firmware}} tab and choose your settings. It should look something like this:
::[[File:Storm32-wiki-flash-firmware-swd.jpg|640px]]


== Flashing Firmware using a STLink/V2 (SWD) Programmer ==
'''5.''' Push the {{GUIFIELD|Flash Firmware}} button.


PLEASE ADD
'''6.''' Now a black window (DOS console) should open and run the STM32CubeProgrammer flash program, as shown in the screenshot. Wait until it is finished (takes some seconds). The STorM32 board will be reset and start running.
::[[File:Storm32-wiki-flash-firmware-swd-dosbox.jpg|640px]]

Latest revision as of 17:25, 19 January 2024

This page is for instructions on how to flash firmware into v3.x and v4.x STorM32 boards.

For instructions on how to flash v1.3x STorM32 boards, please consult the article How to flash v1.x STorM32 boards.

For the v3.x/v4.x boards two situations can be distinguished:

  • Upgrading: If your v3.x/v4.x board already runs a valid STorM32 firmware which you want to upgrade (or downgrade), then this is the recommended procedure to choose, since it is most simple. Go to Updating Firmware.
  • First-time flashing: In all other cases, when your v3.x/v4.x board has not yet a STorM32 firmware installed or you don't want to use the upgrade method, this is what needs to be done. Go to First-Time Flashing.

Comment: The same distinction also exists for flashing NT modules, see How to flash NT Modules.

Updating Firmware

If your v3.x/v4.x STorM32 board runs already a firmware, then this is the canonical procedure for upgrading:

1. Connect the STorM32 board via its USB port to the PC.

Comment: If this is the first time the board is connected via USB to the PC, then Win will immediately start with installing the appropriate USB driver. This takes quite a while (several minutes). Please, be patient and wait until Win reports that the device is ready for use. Do not interrupt the driver installation process before it is completed. Otherwise things can get messed up quite considerably, and installing the driver later can be a challenge.

2. Run the GUI and go to the [GUI:Flash Firmware] tab (see the screenshot).

Comment: In principle you can use any GUI version to flash any version of the firmware. However, a GUI which is of the same or higher version than the firmware which is to be installed provides easy access to the firmware via the selector fields on the [GUI:Flash Firmware] window.
Storm32-wiki-upgrade-firmware-v3x.jpg

3. In the combo boxes [Board] and [Firmware Version] select the correct board and desired firmware version.

Comment: With these two selectors the correct firmware .hex file is chosen in the [Selected Firmware Hex File] field.
Comment: It is important to choose the correct board version; otherwise you will flash a wrong firmware and the board will not functions correctly.

4. In the [STM32 Programmer] field select "Upgrade via STorM32 USB port".

5. In the [Port] field select the COM port which your STorM32 board is connected to (it's the same port you choose when connecting to the GUI).

Comment: If you are not sure which the correct COM port is, then disconnect the STorM32 board from the PC, inspect the drop-down list and memorize the available COM ports, reconnect the STorM32 board and wait until it is enumerated by Win, inspect the drop-down list again, and chose the newly added COM port.

6. If required or desired check the [Perform full chip erase] check button.

7. Remind you about the upgrading process by reading the usage information.

8. Finally, hit the [Flash Firmware] button.

9. Now a black window (DOS console) should open and run the STM32CubeProgrammer flash program, as shown in the screenshot. Wait until it is finished (takes some seconds). The STorM32 board will be reset and start running.

Storm32-wiki-flash-firmware-dosbox.jpg

Trouble Shooting

  • The STorM32 board has no power: Connect the board to the computer via USB to power it.
  • Wrong serial port is selected in the tool.
  • The black DOS box does not show up: Typically this happens because the firmware .zip file was not extracted.
  • The black DOS box shows up, displaying a [OK] and [KO] together with an error message "No response from target, the bootloader cannot be started": The error message is correct, the bootloader could not be started, because e.g. a wrong COM port was selected, the STorM32 board wasn't put into bootloader mode, the connections are incorrect, and so on.
  • The above steps run and the black DOS box shows the first two [OK] messages, but the downloading and verifying message lines are not be present and a firmware is not flashed: Go to Removing Read&Write Protections.
  • The verify fails: First double-check that you are not using an outdated GUI version. Otherwise, click the [Perform full chip erase] check button and repeat. Note: This will also erase any setting; if needed save the settings to a file beforehand using the option in the "Setting" menu.
  • The USB is not working: Please double-check that you've selected the correct board version in the [STorM32-BGC board] field.
  • In case of troubles with the USB driver, consult the FAQ: Which drivers are needed for the USB?.
  • On Win XP flashing via the GUI using the USB-TTL adapter will fail. See the section Flashing Procedure for Win XP.
  • In order to test if the USB-TTL adapter is working properly, one can connect its Rx and Tx pins with each other, and use a terminal program, such as HTerm. When you send characters they should be immediately received.

First-Time Flashing

If your v3.x/v4.x STorM32 board has not yet been flashed with a STorM32 firmware, or runs a different firmware, then one needs to resort to grass roots flashing methods for flashing the firmware (first-time flashing).

In general, the STM32 micro-controllers which are used in the STorM32 boards provide two different built-in methods for flashing firmware:

  1. via the serial system bootloader using a USB-TTL adapter
  2. via SWD using a ST-Link programmer

For v3.x/v4.x boards method 1. is relatively convenient, since these boards have the USB-TTL adapter integrated and thus no additional hardware is needed for doing this. However, the grain of salt is that the BOOT0 pin needs to be temporarily shortened to GND by closing the solder jumper.

Method 2. requires a dedicated ST-Link programmer device. These are cheaply available, but nevertheless it is an additional piece of hardware, which one needs.

Flashing via System Bootloader

1. Important: Find the BOOT0 solder jumper on the STorM32 board, and close it with a drop of solder.

2. Connect the STorM32 board via the USB plug to the PC (it is important to do that after step 1, alternatively you can reset/repower the board).

3. Run the GUI and go to the [GUI:Flash Firmware] tab and choose your settings:

  • In the combo boxes [Board] and [Firmware Version] select the correct board and desired firmware version.
  • In the [STM32 Programmer] field Select "System Bootloader @ UART1".
  • In the [Port] field select the COM port which your STorM32 board is connected to.
Storm32-wiki-flash-firmware-systembootloader-v3x.jpg

4. Finally, hit the [Flash Firmware] button.

5. Now a black window (DOS console) should open and run the STM32CubeProgrammer flash program, as shown in the above. Wait until it is finished (takes some seconds).

6. Important: Do not forget to open the BOOT0 solder jumper.

Flashing via SWD

1. You need a STLink/V2 programmer. To buy one just search for e.g. "STlink" on ebay, aliexpress, etc. They look something like this:

ST Link V2.jpg

2. Connect the SWD pins from the STorM32 board to the pins of your ST-Link programmer. The SWD pins on the v3.3 board are near the USB plug, anf on the v4.1 board near the LEDs.

"SWDIO" to "SWDIO"
"SWCLK" to "SWCLK"
"GND" to "GND"

3. Power up your STorM32 over USB, and connect your ST-Link programmer over USB to a PC.

4. In the GUI go to the [GUI:Flash Firmware] tab and choose your settings. It should look something like this:

Storm32-wiki-flash-firmware-swd.jpg

5. Push the [Flash Firmware] button.

6. Now a black window (DOS console) should open and run the STM32CubeProgrammer flash program, as shown in the screenshot. Wait until it is finished (takes some seconds). The STorM32 board will be reset and start running.

Storm32-wiki-flash-firmware-swd-dosbox.jpg