Skip to content

Commit 5ef6cdb

Browse files
Add MicroMod-WB5MMG / Sasquatch-WB5MMG variants, plus secure boot, plus secure firmware update
1 parent c9865e8 commit 5ef6cdb

File tree

232 files changed

+232325
-5976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+232325
-5976
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ ArduinoCore-stm32wb is targeted at ultra low power scenarios, sensor hubs, with
1111
* [Firefly-STM32WB55CG](https://www.tindie.com/products/TleraCorp/firefly-ble-development-board)
1212
* [Katydid-STM32WB55CG](https://www.tindie.com/products/tleracorp/katydid-wearable-ble-sensor-board)
1313

14+
### Sparkfun
15+
* [MicroMod-STM32WB5MMG](https://www.sparkfun.com/products/21438)
16+
1417
### STMicroelectronics
1518
* [NUCLEO-WB55RG](https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/stm32-nucleo-expansion-boards/p-nucleo-wb55.html)
1619

1720

1821
## Installing
1922

23+
The Arduino Core for STM32WB does use Secure Boot / Secure Firmware Update. To do so, a special bootloader is installed the first time a sketch is uploaded. To change the bootloader to a newer version, or to switch security settings between `None` and `Signature & Encryption` the STM32WB board has to be reset by toggle the RESET button while holding down the BOOT button, and then uploading a sketch with the new boot code or settings.
24+
25+
PLEASE ALWAYS WHEN UGRADING, TOGGLE THE RESET BUTTON WHILE HOLDING DOWN THE BOOT BUTTON BEFORE UPLOADING THE FIRST SKETCH.
26+
27+
2028
### Board Manager
2129

2230
1. [Download and install the Arduino IDE](https://www.arduino.cc/en/Main/Software) (at least version v1.8.13)
@@ -60,11 +68,15 @@ ArduinoCore-stm32wb is targeted at ultra low power scenarios, sensor hubs, with
6068

6169
## BLE / Wireless stack firmware installation
6270

63-
STM32WB uses encrypted/signed firmware images for the BLE stack. Please flash the `FWUpdate` sketch under the `STM32WB` examples before using BLE. The update will take up few seconds/minutes. During that time the LED will stay on, while the serial monitor will say disconnected. When done the LED will blink if the update was succesful, or simply be turned off if an error was encountered. The serial monitor should pop up again and report back the newly updated firmware versions. The `FWInfo` sketch can be used to verify what version is installed. At this time it should report back 1.10.0 for the BLE stack.
71+
STM32WB uses a signed/encrypted firmware image for the BLE stack. Please flash the `FWUpdate` sketch under the `STM32WB` examples before using BLE. The update will take up few seconds/minutes. During that time the LED will stay on, while the serial monitor will say disconnected. When done the LED will blink if the update was succesful, or simply be turned off if an error was encountered. The serial monitor should pop up again and report back the newly updated firmware versions. The `FWInfo` sketch can be used to verify what version is installed. At this time it should report back 1.14.2 for the BLE stack.
72+
73+
## Secure Boot / Secure Firmware Update / BLE OTA
74+
75+
STM32WB can use a signed/encrypted firmware image for the Arduino application/sketche. With the `Export compiled Binary` entry in the `Sketch` menu 5 files are exported. The *.dfu file is used for secure firmware update via USB/DFU, while the *.ota file is use BLE/OTA. This can be used/tested with either the "ST BLE Toolbox" application for Android/iOS (the file might have to be renamed to fit ST's naming conventions), or with the supplied `stm32wb-ota.py` python3 script (requires `python3` and `bleak`). USB/DFU uses signature/encryption, while BLE/OTA uses signature/encryption/compression.
6476

65-
## Recovering from a faulty sketch for Tlera Corp Boards
77+
## Recovering from a faulty sketch for Tlera Corp / Sparkfun Boards
6678

67-
Sometimes a faulty sketch can render the normal USB Serial based integration into the Arduindo IDE not working. In this case plugin the STM32WB board and toggle the RESET button while holding down the BOOT button and program a known to be working sketch to go ack to a working USB Serial setup.
79+
Sometimes a faulty sketch can render the normal USB DUF based integration into the Arduindo IDE not working. In this case plugin the STM32WB board and toggle the RESET button while holding down the BOOT button and program a known to be working sketch to go back to a working USB DFU setup.
6880

6981
## Credits
7082

boards.txt

Lines changed: 318 additions & 25 deletions
Large diffs are not rendered by default.

cores/arduino/CDC.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ int CDC::read(uint8_t *buffer, size_t size) {
133133
}
134134

135135
void CDC::flush() {
136-
if (k_task_is_in_progress()) {
136+
if (!armv7m_core_is_in_interrupt()) {
137137
while (m_tx_busy) {
138-
k_sem_acquire(&m_sem, K_TIMEOUT_FOREVER);
138+
if (k_sem_acquire(&m_sem, K_TIMEOUT_FOREVER) != K_NO_ERROR) {
139+
break;
140+
}
139141
}
140142
}
141143
}
@@ -145,11 +147,10 @@ size_t CDC::write(const uint8_t data) {
145147
}
146148

147149
size_t CDC::write(const uint8_t *buffer, size_t size) {
148-
k_task_t *self = nullptr;
149150
uint32_t tx_read, tx_write, tx_write_next, tx_count, tx_size;
150151
uint8_t tx_lock;
151152
size_t count;
152-
153+
153154
if (!m_enabled) {
154155
return 0;
155156
}
@@ -160,10 +161,6 @@ size_t CDC::write(const uint8_t *buffer, size_t size) {
160161

161162
count = 0;
162163

163-
if (k_task_is_in_progress()) {
164-
self = k_task_self();
165-
}
166-
167164
tx_lock = __armv7m_atomic_swapb(&m_tx_lock, 1);
168165

169166
do {
@@ -182,7 +179,7 @@ size_t CDC::write(const uint8_t *buffer, size_t size) {
182179
}
183180

184181
if (tx_size == 0) {
185-
if (m_nonblocking || !self) {
182+
if (m_nonblocking || armv7m_core_is_in_interrupt()) {
186183
goto finish;
187184
}
188185

@@ -217,7 +214,9 @@ size_t CDC::write(const uint8_t *buffer, size_t size) {
217214
}
218215

219216
if (m_tx_busy) {
220-
k_sem_acquire(&m_sem, K_TIMEOUT_FOREVER);
217+
if (k_sem_acquire(&m_sem, K_TIMEOUT_FOREVER) != K_NO_ERROR) {
218+
goto finish;
219+
}
221220
}
222221
}
223222
} while (tx_size == 0);

cores/arduino/Callback.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
class Callback {
3434
public:
35-
Callback() : m_callback(nullptr), m_context(nullptr) { }
35+
// Callback() : m_callback(nullptr), m_context(nullptr) { }
36+
Callback() = default;
3637
Callback(void (*function)(void)) : m_callback((void (*)(void*))function), m_context(nullptr) { }
3738
Callback(const Callback &other) : m_callback(other.m_callback), m_context(other.m_context) { }
3839

cores/arduino/Makefile

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ OBJCOPY = $(TOOLS)/bin/arm-none-eabi-objcopy
1010
CFLAGS = -c -g3 -Os $(WARNINGS) -std=gnu11 -ffast-math -ffunction-sections -fdata-sections -nostdlib -MMD $(EXTRAS) $(DEFINES) $(INCLUDES)
1111
CXXFLAGS = -c -g3 -Os $(WARNINGS) -std=gnu++11 -ffast-math -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib -fno-use-cxa-atexit -fno-rtti -fno-exceptions -MMD $(EXTRAS) $(DEFINES) $(INCLUDES)
1212
ASFLAGS = -c -g -x assembler-with-cpp $(EXTRAS) $(DEFINES) $(INCLUDES)
13-
LDFLAGS = -g -Os $(EXTRAS) -Wl,--gc-sections,--no-undefined -T../../system/STM32WBxx/LdScripts/STM32WB55xx_FLASH.ld --specs=nano.specs --specs=nosys.specs -Wl,--defsym=__RTC_EPOCH__=$(shell date +"%s")
14-
#LDFLAGS = -g -Os $(EXTRAS) -Wl,--gc-sections,--no-undefined -T../../system/STM32WBxx/LinkScripts/STM32WB55xx_FLASH.ld --specs=nano.specs --specs=nosys.specs
13+
#LDFLAGS = -g -Os $(EXTRAS) -Wl,--gc-sections,--no-undefined -T../../system/STM32WBxx/LdScripts/STM32WB55xx_FLASH.ld --specs=nano.specs --specs=nosys.specs -Wl,--defsym=__RTC_EPOCH__=$(shell date +"%s")
14+
LDFLAGS = -g -Os $(EXTRAS) -Wl,--gc-sections,--no-undefined -T../../system/STM32WBxx/LdScripts/STM32WB55xx_COMPOSITE.ld --specs=nano.specs -Wl,--defsym=__RTC_EPOCH__=$(shell date +"%s")
1515
WARNINGS = -Wall -Wextra
16-
EXTRAS = -mcpu=cortex-m4 -march=armv7e-m+fp -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard
17-
DEFINES = -DSTM32WB55xx -D__SYSTEM_CORE_CLOCK__=64000000 -DDOSFS_SDCARD=0 -DDOSFS_SFLASH=0 -DARDUINO_MAKEFILE
16+
EXTRAS = -mcpu=cortex-m4 -march=armv7e-m+fp -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -falign-functions=6
17+
#DEFINES = -DSTM32WB55xx -D__SYSTEM_CORE_CLOCK__=64000000 -DSTORAGE_TYPE=2 -DARDUINO_MAKEFILE
18+
DEFINES = -DSTM32WB55xx -D__SYSTEM_CORE_CLOCK__=64000000 -DSTORAGE_TYPE=0 -DARDUINO_MAKEFILE -DUSB_VID=0x1209 -DUSB_PID=0x6677 -DUSB_MANUFACTURER="\"Sparkfun\"" -DUSB_PRODUCT="\"MicroMod-WB5MMG\"" -DUSB_TYPE=1
1819
EPOCH = $(shell date +"%s")
1920

2021
INCLUDES = \
2122
-I../../system/CMSIS/Core/Include \
2223
-I../../system/CMSIS/Device/ST/STM32WBxx/Include \
2324
-I../../system/CMSIS/RTOS2/Include \
2425
-I../../system/STM32WBxx/Include \
25-
-I../../variants/Firefly-WB55CG \
26+
-I../../variants/MicroMod-WB5MMG \
2627
-I../../libraries/BLE/src \
2728
-I../../libraries/DOSFS/src \
2829
-I../../libraries/EEPROM/src \
@@ -36,6 +37,7 @@ INCLUDES = \
3637
-I../../libraries/SPI/src \
3738
-I../../libraries/STM32WB/src \
3839
-I../../libraries/TimerMillis/src \
40+
-I../../libraries/USBStorage/src \
3941
-I../../libraries/Wire/src \
4042
-I.
4143
SRCS = \
@@ -52,8 +54,9 @@ SRCS = \
5254
../../libraries/SPI/src/SPI.cpp \
5355
../../libraries/STM32WB/src/STM32WB.cpp \
5456
../../libraries/TimerMillis/src/TimerMillis.cpp \
57+
../../libraries/USBStorage/src/USBStorage.cpp \
5558
../../libraries/Wire/src/Wire.cpp \
56-
../../variants/Firefly-WB55CG/variant.cpp \
59+
../../variants/MicroMod-WB5MMG/variant.cpp \
5760
avr/dtostrf.c \
5861
avr/eeprom.c \
5962
Callback.cpp \
@@ -75,11 +78,10 @@ SRCS = \
7578
delay.c \
7679
hooks.c \
7780
itoa.c \
78-
main.cpp \
7981
new.cpp \
8082
syscalls_stm32wb.c \
8183
wiring.c \
82-
wiring_analog.c \
84+
wiring_analog.cpp \
8385
wiring_digital.c \
8486
wiring_pulse.c \
8587
wiring_shift.c
@@ -98,8 +100,9 @@ OBJS = \
98100
../../libraries/SPI/src/SPI.o \
99101
../../libraries/STM32WB/src/STM32WB.o \
100102
../../libraries/TimerMillis/src/TimerMillis.o \
103+
../../libraries/USBStorage/src/USBStorage.o \
101104
../../libraries/Wire/src/Wire.o \
102-
../../variants/Firefly-WB55CG/variant.o \
105+
../../variants/MicroMod-WB5MMG/variant.o \
103106
avr/dtostrf.o \
104107
avr/eeprom.o \
105108
Callback.o \
@@ -121,7 +124,6 @@ OBJS = \
121124
delay.o \
122125
hooks.o \
123126
itoa.o \
124-
main.o \
125127
new.o \
126128
syscalls_stm32wb.o \
127129
wiring.o \
@@ -141,12 +143,18 @@ all:: flash.elf flash.bin
141143
%.o: %.S
142144
$(CC) $(ASFLAGS) -c $< -o $@
143145

144-
flash.elf: $(OBJS) ../../system/STM32WBxx/Lib/libstm32wb55xx.a
145-
$(CC) $(LDFLAGS) $(OBJS) -L../../system/STM32WBxx/Lib -lstm32wb55xx -lm -lc -lgcc -lstm32wb55xx -o flash.elf
146+
libarduino.a:: $(OBJS)
147+
$(AR) rcs $@ $^
148+
149+
flash.elf: main.o libarduino.a ../../system/STM32WBxx/Source/_out/stm32wb55xx/stm32wb_boot.o ../../system/STM32WBxx/Lib/libstm32wb55xx.a
150+
$(CC) $(LDFLAGS) main.o ../../system/STM32WBxx/Source/_out/stm32wb55xx/stm32wb_boot.o -Wl,--gc-sections,--no-undefined,-Map=flash.map -Wl,--start-group -L. -larduino -L../../system/STM32WBxx/Lib -lstm32wb55xx -lm -lc -Wl,--end-group -o flash.elf
151+
# $(CC) $(LDFLAGS) main.o ../../system/STM32WBxx/Source/_out/stm32wb55xx/stm32wb_boot.o -Wl,--gc-sections,--no-undefined,-Map=flash.map -Wl,--start-group -L. -larduino -L../../system/STM32WBxx/Lib -lstm32wb55xx_debug -lm -lc -Wl,--end-group -o flash.elf
152+
# $(CC) $(LDFLAGS) main.o -Wl,--gc-sections,--no-undefined,-Map=flash.map -Wl,--start-group -L. -larduino -L../../system/STM32WBxx/Lib -lstm32wb55xx_debug -lm -lc -Wl,--end-group -o flash.elf
153+
# ../../tools/linux/elfsign -u eafee6d0-b575-4412-aeb4-c30ecb0d3c6e -v 1209 -p 6675 -e ../../libraries/STM32WB/keys/aes128_key.bin -s ../../libraries/STM32WB/keys/ecc256_key.pem -b flash.bin -d flash.dfu -o flash.ota -x flash.hex flash.elf flash.elf
154+
../../tools/linux/elfsign -u eafee6d0-b575-4412-aeb4-c30ecb0d3c6e -v 1209 -p 6675 -b flash.bin -d flash.dfu -o flash.ota -x flash.hex flash.elf flash.elf
155+
# ../../tools/linux/elfsign -u 07fcdd24-aa7d-4bd5-93b1-9923e90c457c -v 1209 -p 6675 -b flash.bin -d flash.dfu -o flash.ota -x flash.hex flash.elf flash.elf
146156

147-
flash.bin: flash.elf
148-
$(OBJCOPY) -O binary flash.elf flash.bin
149157
clean::
150-
rm -f flash.elf flash.bin *~ *.o *.d $(OBJS)
158+
rm -f flash.elf flash.bin flash.dfu flash.ota flash.hex flash.map libarduino.a *~ *.o *.d main.o $(OBJS)
151159

152160
-include $(OBJS:.o=.d)

cores/arduino/USBAPI.h

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,42 @@ class USBDeviceClass
3636
USBDeviceClass();
3737

3838
// USB Device API
39-
bool begin();
40-
void end();
41-
void start();
42-
void stop();
43-
void wakeup();
44-
45-
bool attached();
46-
bool connected();
47-
bool suspended();
48-
49-
void onAttach(void(*callback)(void));
50-
void onAttach(Callback callback);
51-
void onDetach(void(*callback)(void));
52-
void onDetach(Callback callback);
53-
void onConnect(void(*callback)(void));
54-
void onConnect(Callback callback);
55-
void onSuspend(void(*callback)(void));
56-
void onSuspend(Callback callback);
57-
void onResume(void(*callback)(void));
58-
void onResume(Callback callback);
39+
static bool begin();
40+
static void end();
41+
static void start();
42+
static void stop();
43+
static void wakeup();
44+
45+
static bool attached();
46+
static bool connected();
47+
static bool suspended();
48+
49+
static void onAttach(void(*callback)(void));
50+
static void onAttach(Callback callback);
51+
static void onDetach(void(*callback)(void));
52+
static void onDetach(Callback callback);
53+
static void onConnect(void(*callback)(void));
54+
static void onConnect(Callback callback);
55+
static void onSuspend(void(*callback)(void));
56+
static void onSuspend(Callback callback);
57+
static void onResume(void(*callback)(void));
58+
static void onResume(Callback callback);
5959

6060
private:
61-
volatile uint32_t m_events;
61+
static struct USBDeviceCallbacks {
62+
volatile uint32_t events;
6263

63-
Callback m_attach_callback;
64-
Callback m_detach_callback;
65-
Callback m_connect_callback;
66-
Callback m_suspend_callback;
67-
Callback m_resume_callback;
68-
69-
k_work_t m_work;
64+
Callback attach_callback;
65+
Callback detach_callback;
66+
Callback connect_callback;
67+
Callback suspend_callback;
68+
Callback resume_callback;
69+
70+
k_work_t work;
71+
} m_callbacks;
7072

71-
static void eventCallback(class USBDeviceClass *self, uint32_t events);
72-
static void notifyRoutine(class USBDeviceClass *self);
73+
static void eventCallback(void *context, uint32_t events);
74+
static void notifyRoutine(void *context);
7375
};
7476

7577
extern USBDeviceClass USBDevice;

0 commit comments

Comments
 (0)