ST STM32WB

From SEGGER Wiki
Revision as of 17:42, 31 March 2023 by Fabian (talk | contribs) (Example - Get FUS state)
Jump to: navigation, search

The ST STM32WB series devices are heterogeneous dual-core MCUs with a Cortex-M4 for the end-user application and a Cortex-M0 for the BLE stack. The STM32WB series currently consists of 3 sub-families:

  • STM32WBx0
  • STM32WBx5
  • STM32WBxM

Internal flash

The STM32WB device series comes with varying sizes of internal flash up to 1 MB, which is generally supported by J-Link.

Device name Range / Size
STM32WBxxxC 0x0800_0000 - 0x0803_FFFF (256 KB)
STM32WB1xxC 0x0800_0000 - 0x0804_FFFF (320 KB)[1]
STM32WBxxxE 0x0800_0000 - 0x0807_FFFF (512 KB)
STM32WBxxxY 0x0800_0000 - 0x0809_FFFF (640 KB)
STM32WBxxxG 0x0800_0000 - 0x080F_FFFF (1 MB)[2]
  1. The ST STM32WB1x devices are special compared to the other STM32WB devices e.g. the sector size is 2KB instead of 4KB.
  2. Partially used for BLE stack image. The section that is reserved for this purpose is read/write protected.
Note:

Concerning STM32WBxxxG (1MB) devices:
A chip erase for these devices will usually fail.

This is because a part of the flash is protected as long as a wireless stack is present, resulting in a write protection error during chip erase.

RSS / FUS

Root Security Service (RSS) and the Firmware Upgrade Service (FUS) are responsible for secure wireless stack updates and encryption key management. This firmware is executed by the secure core (Cortex-M0) and is not accessible by the end user or a debug probe. This firmware is factory installed in the STM32WB flash memory and is marked as secured. Therefore the end-user needs to take into consideration when choosing this device, as part of the memory will be already reserved for the RSS (around 5%) for some devices. The RSS uses between 10 sectors (v0.5.3) and 12 sectors (v1.1.0) and is written in the flash memory end sectors. For example, for a 1MB device, this will be stored starting at the address 0x080F4000 for v1.1.0 and 0x080F6000 for v0.5.3.

How to update the Wireless Stack

Note:
  • Before starting, please make sure that you are using the latest version of the J-Link Software Pack.
  • The upgrade process and the required steps were extensively reworked/changed with J-Link Software V7.86f.
    This section describes this new, reworked process.

Updating FUS and WS stack can automatically be done with J-Link Commander or J-Flash This section describes how this is done via the following steps:

  1. Acquire Wireless Stack binaries and determine the correct flash address.
  2. Select the device <DeviceName>_FUS in the J-Link Commander or J-Flash.
  3. Download the data file to the correct position, specified by the ST documentation.

Acquire Wireless Stack binaries

The wireless stack binaries can be downloaded from https://www.st.com/en/embedded-software/stm32cubewb.html.
After downloading:

  • Unpack the package
  • Navigate to STM32Cube_FW_WB_V<Version>\Projects\STM32WB_Copro_Wireless_Binaries\
  • Open Release_Notes.html, which contains information about:
    • Where each stack starts.
    • The corresponding binary files and where they should be programmed to.

J-Link Commander - Upgrading the image

Open the J-Link commander (%JLinkInstallDir%\JLink.exe) using the following example command line:

Windows:
  JLink.exe -autoconnect 1 -device STM32WB55RG_FUS -if swd -speed 4000
Linux/MacOS:
  JLinkExe  -autoconnect 1 -device STM32WB55RG_FUS -if swd -speed 4000

After connecting to the MCU successfully, download the Update using LoadFile command, followed by the Exit command. The mandatory reset is issued implicitly by the loadfile command.

loadfile <PathToBinary>\stm32wb5x_BLE_Stack_fw.bin, <Address>
Exit
Note:
  • The address the wireless stack has to be downloaded to differs depending on the update version and device.
  • Make sure that the Exit step is executed before severing the connection between J-Link and device, as the option bytes are restored during this step.
Example (STM32WB5xxG, version 1.1.0)
J-Link> loadfile "C:\Users\Fabian\Desktop\STM32Cube_FW_WB_V1.13.0\Projects\STM32WB_Copro_Wireless_Binaries\STM32WB5x\stm32wb5x_BLE_Stack_full_fw.bin" 0x080C7000
J-Link> Exit

J-Flash - Upgrading the image

  1. Create a project for the device you are using (<DeviceName>_FUS)
  2. Add the datafile to the project (make sure to select the correct location for the datafile!)
  3. Important: Check: Options > Project Settings > Production > Actions performed by 'Production Programming' > Disconnect afterwards
  4. Download the image via Target > Production Programming (F7)
  5. Wait for the process to complete (Takes ~30 seconds)

Flasher stand-alone - Upgrading the image

Flasher stand-alone mode programming is not yet supported, but will be supported in the near future.

Starting the wireless stack

The following table shows under which conditions the wireless stack will be running on disconnect (closing J-Link Commander) automatically.

WS State before connect FUS/WS was updated
after connect
Is WS started
on disconnect
Running NO.png YES.png
Not running NO.png NO.png
Running YES.png YES.png
Not running YES.png YES.png

How to delete the Wireless Stack

The WS is deleted during the "Reset"-step. Thus, triggering a reset will delete the WS. This can be done in different ways.

J-Link Commander

  1. Connect to the device.
  2. Issue the Reset command.

J-Flash

  1. Create a project for the device (- FUS!).
  2. Connect to the device. This will implicitly trigger a reset.

How to update FUS

This is done the same way as the WS upgrade, but with a FUS image instead of a WS image.

Note:
  • Once the FUS is updated from the v0.5.3 to v1.0.1 is not possible to reverse RSS or install WS from previous versions. The RSS/FUS can only upload wireless stacks within the same release version.
  • The FUS upgrade will also delete the WS.

How does it work

The process for uploading a Wireless stack to STM32WBxx with J-Link works by uploading the binary to the flash memory and then by requesting a Wireless stack upgrade to the FUS (Firmware Upgrade Service), by means of communication with IPPC and shared tables. The process is described step-by-step below.

Note:
To guarantee that the IPPC can be used and the Info table is setup, the device boot mode will be changed during connect to start the device in system boot mode. The boot mode will be restored on disconnect.
  1. Connect:
    • The device is forced to boot in system bootmode via option bytes.
    • FUS is started through IPPC.
  2. Reset: The wireless stack is deleted by issuing the corresponding IPPC command.
  3. Flash program:
    • The upgrade image is programmed to the device flash
    • The upgrade procedure is triggered by issuing the corresponding IPPC command.
    • The wireless stack is started after a successful upgrade.
  4. Disconnect:
    • If no Reset/Download was executed, the WS state will be restored (running/not running).
    • The option bytes are restored to their original values.

The upgrade process

  1. Before the upgrade is started the J-Link will request the FUS/RSS to delete any current wireless stack that might be installed during the reset step.
  2. The image is downloaded to the target.
  3. The uploaded stack to the flash will be checked by J-Link if it contains a valid image signature.
  4. A WS_UPGRADE request is made to the FUS. During this process, the MCU will reset several times. Until the Cortex-M0 becomes responsive the J-Link will try every second to establish a connection with the FUS.
Note:
This process takes around 20 to 30 seconds depending on the Wireless stack size.

Sending FUS commands manually

In case a command is not supported out of the box, it has to be sent manually. This can be done via the IPCC mailbox system used for FUS communication. To do so, a connection has to be established via the J-Link Commander.

Note:
  • The mailbox buffer addresses depend on the device setup. In the following, the default system bootloader boot mode default locations are used.
  • For a list of available commands and the corresponding responses, please refer to the ST documentation (AN5185).
Reset
Mem32  0x58000C0C, 1          // Channel 2 (CH2bit == bit 1) busy? Wait for it to clear. Otherwise, prcoeed.
Write4 0x20030064, 0          // Clear mailbox message header
Write4 0x20030068, 0          // Clear mailbox message buffer
Write4 0x2003006C, <Cmd>      // Write command packet "<Cmd>"
// Optional: Send payload here.
Write4 0x58000C08, 0x20000    // Set CH2F via CH2S (channel 2 data transmit bit)
Write4 0x58000C04, 0xFFFDFFFD // Unmask Channel 2 interrupt (CH2FM & CH2OM)
Mem32  0x58000C0C, 1          // _IPCC_C1TOC2SR Still busy (bit 1 == 1)? => Repeat this until unoccupied (bit 1 == 0).
Mem32  0x20030064, <8+n>      // Read command response: 8 bytes (header + response message) + n bytes payload.

In case a Payload is required for the command, it has to be added after "Send command <Cmd>". The payload contains 0 - 255 bytes:

Write4 0x20030070, <Payload0-3>
...
Write4 0x20030168, <Payload248-251>
Write1 0x2003016C, <Payload252>
Write1 0x2003016D, <Payload253>
Write1 0x2003016E, <Payload254>

Example - Get FUS state

Reset
Mem32  0x58000C0C, 1          // Channel 2 (CH2F bit == bit 1) busy? Wait for it to clear. Otherwise, prcoeed.
Write4 0x20030064, 0          // Clear mailbox message header
Write4 0x20030068, 0          // Clear mailbox message buffer
Write4 0x2003006C, 0x00FC5210 // Write command packet <Type(Command packet) | Command (FUS_GET_STATE) | payload length == 0>.
Write4 0x58000C08, 0x20000    // Set CH2F via CH2S (channel 2 data transmit bit)
Write4 0x58000C04, 0xFFFDFFFD // Unmask Channel 2 interrupt (CH2FM & CH2OM)
Sleep 500                     // Make sure command had enough time. Alternatively wait for C1TOC2SR bit 1 to turn 0.
Mem32 0x20030064, 2           // Read command response: 8 bytes (header + FUS state).
Note:
Instead of waiting for the channel to turn unoccupied, we simply wait 500ms in the example. Alternative, wait for C1TOC2SR Channel 2 bit (bit 1) to turn 0.

FAQ

How does J-Link communicate with the FUS and performs the Wireless stack upgrade/delete requests?

The communication between the J-Link and the RSS/FUS is performed by use of the IPPC (Inter-Processor Communication Channel) and shared tables that are specified by ST.

Does this mean that the Cortex-M0 is always running the FUS firmware?

No, the FUS firmware is only running when a wireless stack is not installed or a start request is made through the IPCC.

Can I delete the FUS firmware?

No, it is marked as secure so it is not possible to delete it.

Programming the option bytes

Option byte programming is directly supported by J-Link. Alternatively, option bytes can be programmed via the flash registers as shown in the ST STM32 main article.

Evaluation boards

  • TBD