Skip to content

Commit 9fbb89e

Browse files
authored
Merge pull request #14692 from jeromecoutant/PR_WB_HCI
STM32WB: improve FLASH size
2 parents 5047bd3 + 645fed5 commit 9fbb89e

File tree

14 files changed

+110
-158
lines changed

14 files changed

+110
-158
lines changed

connectivity/drivers/ble/FEATURE_BLE/TARGET_STM32WB/HCIDriver.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "bstream.h"
2929
#include "hci_mbed_os_adaptation.h"
3030
#include "mbed_trace.h"
31+
#include "platform/mbed_error.h"
3132

3233
/* STM32WB include files */
3334
#include "stm32wbxx_ll_ipcc.h"
@@ -130,7 +131,8 @@ class HCIDriver : public CordioHCIDriver {
130131
HciResetCmd();
131132
}
132133

133-
static uint8_t convert_db_to_tx_power_index(int8_t level_db) {
134+
static uint8_t convert_db_to_tx_power_index(int8_t level_db)
135+
{
134136
const int8_t conversion[] = {
135137
-40, -21, -20, -19,
136138
-18, -16, -15, -14,
@@ -151,7 +153,8 @@ class HCIDriver : public CordioHCIDriver {
151153
return index;
152154
}
153155

154-
virtual ble_error_t set_tx_power(int8_t level_db) {
156+
virtual ble_error_t set_tx_power(int8_t level_db)
157+
{
155158

156159

157160
uint8_t buf[2];
@@ -480,10 +483,29 @@ class TransportDriver : public CordioHCITransportDriver {
480483
WirelessFwInfo_t wireless_info_instance;
481484
WirelessFwInfo_t *p_wireless_info = &wireless_info_instance;
482485
if (SHCI_GetWirelessFwInfo(p_wireless_info) != SHCI_Success) {
483-
tr_info("SHCI_GetWirelessFwInfo error");
486+
tr_error("SHCI_GetWirelessFwInfo error");
484487
} else {
488+
// https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries
489+
// Be sure that you are using the latest BLE FW version
485490
tr_info("WIRELESS COPROCESSOR FW VERSION ID = %d.%d.%d", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub);
486-
tr_info("WIRELESS COPROCESSOR FW STACK TYPE = %d", p_wireless_info->StackType);
491+
tr_info("WIRELESS COPROCESSOR FW STACK TYPE = %d (ROM size 0x%x)", p_wireless_info->StackType, MBED_ROM_SIZE);
492+
493+
#if STM32WB55xx
494+
switch (p_wireless_info->StackType) {
495+
case INFO_STACK_TYPE_BLE_FULL:
496+
if (MBED_ROM_SIZE > 0xCA000) {
497+
error("Wrong MBED_ROM_SIZE with BLE FW\n");
498+
}
499+
break;
500+
case INFO_STACK_TYPE_BLE_HCI:
501+
if (MBED_ROM_SIZE > 0xE0000) {
502+
error("Wrong MBED_ROM_SIZE with HCI FW\n");
503+
}
504+
break;
505+
default:
506+
tr_error("StackType %u not expected\n", p_wireless_info->StackType);
507+
}
508+
#endif
487509
}
488510
}
489511
}
@@ -532,7 +554,7 @@ class TransportDriver : public CordioHCITransportDriver {
532554
/* At this stage, we'll need to wait for ready event,
533555
* passed thru TL_SYS_EvtReceived */
534556
if (!sysevt_wait()) {
535-
tr_info("ERROR booting WB controler");
557+
error("ERROR booting WB controler\n");
536558
return;
537559
}
538560

Lines changed: 52 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
* [STM32WB family](#stm32wb-family)
22
* [Supported boards](#supported-boards)
3-
* [NUCLEO_WB55RG](#nucleo_wb55rg)
3+
* [NUCLEO_WB55RG (NUCLEO-WB55RG)](#nucleo_wb55rg-nucleo-wb55rg)
44
* [DISCO_WB5MMG (STM32WB5MM-DK)](#disco_wb5mmg-stm32wb5mm-dk)
55
* [BLE](#ble)
66
* [MBED-OS support](#mbed-os-support)
7-
* [mbed-trace support](#mbed-trace-support)
7+
* [BLE FW](#ble-fw)
88
* [BLE FW update](#ble-fw-update)
99
* [BLE FW flashing procedure](#ble-fw-flashing-procedure)
10+
* [mbed-trace support](#mbed-trace-support)
1011

1112

1213
# STM32WB family
@@ -30,8 +31,9 @@ This ST MCU family is dual-core : based on an Arm Cortex-M4 core and an Arm Cort
3031

3132
[mbed.com platform page](https://os.mbed.com/platforms/ST-Nucleo-WB55RG/)
3233

33-
- Total FLASH is 1MB, but note that it is shared by M4 and M0 cores.
34-
- mbed-os application size is then limited to 768 KB
34+
- Total FLASH is 1MB
35+
36+
But FLASH is shared by M4 and M0 cores, [see BLE FW](#ble-fw)
3537

3638
- RAM: 256 KB
3739
- SRAM1: 192 KB
@@ -51,8 +53,9 @@ SRAM2 is dedicated for M0 core and inter CPU communication, and then can not be
5153

5254
[mbed.com platform page](https://os.mbed.com/platforms/DISCO-WB5MMG/)
5355

54-
- Total FLASH is 1MB, but note that it is shared by M4 and M0 cores.
55-
- mbed-os application size is then limited to 768 KB
56+
- Total FLASH is 1MB
57+
58+
But FLASH is shared by M4 and M0 cores, [see BLE FW](#ble-fw)
5659

5760
- RAM: 256 KB
5861
- SRAM1: 192 KB
@@ -83,120 +86,67 @@ Note that the BLE controller firmware running on the cortex-M0 is the same as in
8386
Official ST Application Note :
8487
[AN5289: Building wireless applications with STM32WB Series microcontrollers](https://www.st.com/resource/en/application_note/dm00598033-building-wireless-applications-with-stm32wb-series-microcontrollers-stmicroelectronics.pdf)
8588

89+
## BLE FW
8690

91+
All available BLE FW for M0 core are provided in ths ST STM32CubeWB repo:
8792

88-
## mbed-trace support
93+
https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
8994

90-
trace group: BLE_WB
95+
Default BLE FW in ST boards is **stm32wb5x_BLE_Stack_full_fw.bin**
96+
- As explained in Release_Notes.html, this FW is flashed at @ 0x080CA000
97+
- Default "mbed_rom_size" in targets.json is then "0xCA000" (808K)
98+
99+
To optimize FLASH size, **stm32wb5x_BLE_HCILayer_fw.bin** is supported for MBED-OS use case
100+
- As explained in Release_Notes.html, this FW is flashed at @ 0x080E0000
101+
- Then "mbed_rom_size" can be updated to "0xE0000" (896K)
102+
103+
Example in your local mbed_app.json:
104+
```
105+
"target_overrides": {
106+
"NUCLEO_WB55RG": {
107+
"target.mbed_rom_size": "0xE0000"
108+
}
109+
```
91110

92-
example:
93-
````
94-
[INFO][BLWB]: WIRELESS COPROCESSOR FW VERSION ID = 1.11.1
95-
[INFO][BLWB]: WIRELESS COPROCESSOR FW STACK TYPE = 1
96-
[DBG ][BLWB]: mbox_write type:1, len:3
97-
[INFO][BLWB]: TX>> BLE CMD
98-
[DBG ][BLWB]: Type 0x1
99-
[DBG ][BLWB]: Cmd 0xc03
100-
[DBG ][BLWB]: Len 0D]
101-
````
102111

103112
## BLE FW update
104113

105114
Official ST Application Note :
106115
[AN5185: ST firmware upgrade services for STM32WB Series](http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00513965.pdf)
107116

108-
Latest BLE FW :
109-
https://github.com/STMicroelectronics/STM32CubeWB/blob/master/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_BLE_Stack_full_fw.bin
110117

111118
## BLE FW flashing procedure
112119

113-
Release Note and complete flashing procedure:
114-
https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeWB/blob/master/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/Release_Notes.html
115-
116-
117-
- STEP 1: Use STM32CubeProgrammer
120+
STM32CubeProgrammer needs to be used:
118121

119122
https://www.st.com/en/development-tools/stm32cubeprog.html
120123

121-
````
122-
FLASHPATH="C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin"
123-
export PATH=$FLASHPATH:$PATH
124-
````
125-
126-
- STEP 2: Access to Bootloader USB Interface (system flash)
127-
128-
* Boot0 pin set to VDD : Jumper between CN7.5(VDD) and CN7.7(Boot0)
129-
* Jumper JP1 on USB_MCU
130-
* Power ON via USB_USER
131-
132-
![Image description](stm32wb_ble_update.jpg)
133-
134-
- STEP 3 : Delete current wireless stack :
135-
136-
```
137-
$ STM32_Programmer_CLI.exe -c port=usb1 -fwdelete
138-
...
139-
FUS state is FUS_IDLE
140-
141-
FUS status is FUS_NO_ERROR
142-
Deleting firmware ...
143-
Firmware delete finished
144-
fwdelete command execution finished
145-
```
146-
147-
- STEP 4 : Read FUS Version
148-
149-
```
150-
$ STM32_Programmer_CLI.exe -c port=usb1 -r32 0x20030030 1
151-
...
152-
153-
Reading 32-bit memory content
154-
Size : 4 Bytes
155-
Address: : 0x20030030
156-
157-
0x20030030 : 00050300
158-
```
159-
160-
- STEP 5A if last result is 00050300 : Download new FUS :
161-
162-
```
163-
$ ./STM32_Programmer_CLI.exe -c port=usb1 -fwupgrade stm32wb5x_FUS_fw_for_fus_0_5_3.bin 0x080EC000 firstinstall=0
164-
```
165-
166-
- STEP 5B if last result is 01000100 or 01000200 : Download new FUS :
167-
168-
```
169-
$ STM32_Programmer_CLI.exe -c port=usb1 -fwupgrade stm32wb5x_FUS_fw.bin 0x080EC000 firstinstall=0
170-
...
171-
Firmware Upgrade Success
172-
```
173-
174-
175-
- STEP 4 (to check) : Read FUS Version
176-
177-
```
178-
$ STM32_Programmer_CLI.exe -c port=usb1 -r32 0x20030030 1
179-
180-
Reading 32-bit memory content
181-
Size : 4 Bytes
182-
Address: : 0x20030030
183-
184-
0x20030030 : 01020000
185-
```
124+
Please check the Release Note and complete flashing procedure:
125+
https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeWB/blob/master/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/Release_Notes.html
186126

187-
- STEP 6 : Download new wireless stack :
127+
- connect the board with ST-LINK
128+
- In the left column, go to "Firmware Upgrade Services"
129+
- "Start FUS"
130+
- "Read FUS infos" => version v1.2.0 is expected
131+
- Firmware Upgrade / "Browse" : select the chosen FW (see above)
132+
- Firmware Upgrade / Start address : depends on the chosen FW (see above)
133+
- Firmware Upgrade / "Firmware Upgrade"
134+
- In the left column, go to "Option bytes"
135+
- User Configuration => "Read"
136+
- User Configuration / enable nSWBOOT0 => "Apply"
188137

189138

190-
```
191-
$ STM32_Programmer_CLI.exe -c port=usb1 -fwupgrade stm32wb5x_BLE_Stack_full_fw.bin 0x080CA000 firstinstall=1
192-
193-
...
194-
Download firmware image at address 0x80cb000 ...
195-
...
196-
File download complete
197-
...
198-
Firmware Upgrade Success
199-
```
139+
## mbed-trace support
200140

201-
- STEP 7 : Revert STEP 2 procedure to put back device in normal mode.
141+
trace group: BLWB
202142

143+
example:
144+
````
145+
[INFO][BLWB]: WIRELESS COPROCESSOR FW VERSION ID = 1.11.1
146+
[INFO][BLWB]: WIRELESS COPROCESSOR FW STACK TYPE = 1
147+
[DBG ][BLWB]: mbox_write type:1, len:3
148+
[INFO][BLWB]: TX>> BLE CMD
149+
[DBG ][BLWB]: Type 0x1
150+
[DBG ][BLWB]: Cmd 0xc03
151+
[DBG ][BLWB]: Len 0D]
152+
````

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB55xG/TOOLCHAIN_ARM/stm32wb55xg.sct

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#endif
2323

2424
#if !defined(MBED_APP_SIZE)
25-
; 768KB FLASH // BLE firmware is being flashed strating from @ 0x080C0000
26-
#define MBED_APP_SIZE 0xC0000
25+
// MBED_APP_SIZE cannot be full ROM size as core M0 FW is using the end of FLASH
26+
// Size is defined in json with "mbed_rom_size"
27+
#define MBED_APP_SIZE MBED_ROM_SIZE
2728
#endif
2829

2930
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
@@ -38,7 +39,7 @@
3839
/* Round up VECTORS_SIZE to 8 bytes */
3940
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) AND ~7)
4041

41-
; RAM_SIZE = 192KB SRAM (0x30000) + Shared mem
42+
; RAM_SIZE = 192KB SRAM1 (0x30000) + Shared mem (part of SRAM2)
4243
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
4344

4445
ER_IROM1 MBED_APP_START MBED_APP_SIZE {

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB55xG/TOOLCHAIN_GCC_ARM/stm32wb55xg.ld

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#endif
2424

2525
#if !defined(MBED_APP_SIZE)
26-
/* 768KB FLASH - BLE firmware is being flashed strating from @ 0x080C0000 */
27-
#define MBED_APP_SIZE 768K
26+
// MBED_APP_SIZE cannot be full ROM size as core M0 FW is using the end of FLASH
27+
// Size is defined in json with "mbed_rom_size"
28+
#define MBED_APP_SIZE MBED_ROM_SIZE
2829
#endif
2930

3031
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
@@ -36,7 +37,7 @@
3637
/* Round up VECTORS_SIZE to 8 bytes */
3738
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8)
3839

39-
/* RAM_SIZE = 192KB SRAM (0x30000) + Shared mem */
40+
/* RAM_SIZE = 192KB SRAM1 (0x30000) + Shared mem (part of SRAM2) */
4041
MEMORY
4142
{
4243
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB55xG/TOOLCHAIN_IAR/stm32wb55xg.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* Device specific values */
1818

1919
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x08000000; }
20-
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0xC0000; }
20+
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = MBED_ROM_START; }
2121

2222
/* [ROM = 768kb = 0xC0000] */
2323
define symbol __intvec_start__ = MBED_APP_START;

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB55xG/cmsis_nvic.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#endif
2323

2424
#if !defined(MBED_ROM_SIZE)
25-
#define MBED_ROM_SIZE 0x100000 // 1.0 MB
25+
// MBED_ROM_SIZE cannot be full ROM size as core M0 FW is using the end of FLASH
26+
// Size is defined in json with "mbed_rom_size"
27+
#error "mbed_rom_size is missing"
2628
#endif
2729

2830
#if !defined(MBED_RAM_START)

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB5MxG/TOOLCHAIN_ARM/stm32wb5mxg.sct

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#endif
2323

2424
#if !defined(MBED_APP_SIZE)
25-
; 768KB FLASH // BLE firmware is being flashed strating from @ 0x080C0000
26-
#define MBED_APP_SIZE 0xC0000
25+
// MBED_APP_SIZE cannot be full ROM size as core M0 FW is using the end of FLASH
26+
// Size is defined in json with "mbed_rom_size"
27+
#define MBED_APP_SIZE MBED_ROM_SIZE
2728
#endif
2829

2930
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
@@ -38,6 +39,7 @@
3839
/* Round up VECTORS_SIZE to 8 bytes */
3940
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) AND ~7)
4041

42+
; RAM_SIZE = 192KB SRAM1 (0x30000) + Shared mem (part of SRAM2)
4143
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
4244

4345
ER_IROM1 MBED_APP_START MBED_APP_SIZE {

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB5MxG/TOOLCHAIN_GCC_ARM/stm32wb5mxg.ld

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#endif
2424

2525
#if !defined(MBED_APP_SIZE)
26-
/* 768KB FLASH - BLE firmware is being flashed strating from @ 0x080C0000 */
27-
#define MBED_APP_SIZE 768K
26+
// MBED_APP_SIZE cannot be full ROM size as core M0 FW is using the end of FLASH
27+
// Size is defined in json with "mbed_rom_size"
28+
#define MBED_APP_SIZE MBED_ROM_SIZE
2829
#endif
2930

3031
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
@@ -36,7 +37,7 @@
3637
/* Round up VECTORS_SIZE to 8 bytes */
3738
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8)
3839

39-
/* RAM_SIZE = 192KB SRAM (0x30000) + Shared mem */
40+
/* RAM_SIZE = 192KB SRAM1 (0x30000) + Shared mem (part of SRAM2) */
4041
MEMORY
4142
{
4243
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB5MxG/TOOLCHAIN_IAR/stm32wb5mxg.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* Device specific values */
1818

1919
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x08000000; }
20-
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0xC0000; }
20+
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = MBED_ROM_START; }
2121

2222
/* [ROM = 768kb = 0xC0000] */
2323
define symbol __intvec_start__ = MBED_APP_START;

targets/TARGET_STM/TARGET_STM32WB/TARGET_STM32WB5MxG/cmsis_nvic.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#endif
2323

2424
#if !defined(MBED_ROM_SIZE)
25-
#define MBED_ROM_SIZE 0x100000 // 1.0 MB
25+
// MBED_ROM_SIZE cannot be full ROM size as core M0 FW is using the end of FLASH
26+
// Size is defined in json with "mbed_rom_size"
27+
#error "mbed_rom_size is missing"
2628
#endif
2729

2830
#if !defined(MBED_RAM_START)

0 commit comments

Comments
 (0)