Skip to content

Commit b9fd381

Browse files
authored
Merge pull request tock#4695 from jlab-sensing/upstream_staging/stm32wle5xx
Add STM32WLE5xx Support
2 parents d8cbb84 + 9244d6b commit b9fd381

47 files changed

Lines changed: 9500 additions & 1 deletion

Some content is hidden

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

Cargo.lock

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,20 @@ dependencies = [
619619
"rv32i",
620620
]
621621

622+
[[package]]
623+
name = "lora_e5_mini"
624+
version = "0.2.3-dev"
625+
dependencies = [
626+
"capsules-core",
627+
"capsules-extra",
628+
"capsules-system",
629+
"components",
630+
"cortexm4",
631+
"kernel",
632+
"stm32wle5jc",
633+
"tock_build_scripts",
634+
]
635+
622636
[[package]]
623637
name = "lora_things_plus"
624638
version = "0.2.3-dev"
@@ -1568,6 +1582,25 @@ dependencies = [
15681582
"kernel",
15691583
]
15701584

1585+
[[package]]
1586+
name = "stm32wle5jc"
1587+
version = "0.2.3-dev"
1588+
dependencies = [
1589+
"cortexm4",
1590+
"enum_primitive",
1591+
"kernel",
1592+
"stm32wle5xx",
1593+
]
1594+
1595+
[[package]]
1596+
name = "stm32wle5xx"
1597+
version = "0.2.3-dev"
1598+
dependencies = [
1599+
"cortexm4",
1600+
"enum_primitive",
1601+
"kernel",
1602+
]
1603+
15711604
[[package]]
15721605
name = "subtle"
15731606
version = "2.4.1"

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ members = [
6969
"boards/tutorials/nrf52840dk-dynamic-apps-and-policies",
7070
"boards/tutorials/nrf52840dk-hotp-tutorial",
7171
"boards/tutorials/nrf52840dk-thread-tutorial",
72+
"boards/lora_e5_mini",
7273
"boards/tutorials/qemu_rv32_virt-tutorial",
7374
"capsules/aes_gcm",
7475
"capsules/ecdsa_sw",
@@ -110,6 +111,8 @@ members = [
110111
"chips/stm32f412g",
111112
"chips/stm32f4xx",
112113
"chips/veer_el2",
114+
"chips/stm32wle5xx",
115+
"chips/stm32wle5jc",
113116
"chips/virtio",
114117
"kernel",
115118
"libraries/enum_primitive",

boards/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Virtual hardware platforms that are regularly tested as part of the CI.
119119
| [Verilated LiteX Simulation](litex/sim/README.md) | RISC-V RV32IMC | LiteX+VexRiscv | custom | tockloader (flash-file)[^1] | No |
120120
| [VeeR EL2 simulation](veer_el2_sim/README.md) | RISC-V RV32IMC | VeeR EL2 | custom | custom | No |
121121
| [QEMU i486 Q53](qemu_i486_q35/README.md) | i468 | Q35 | custom | custom | Yes |
122-
122+
| [Seeed Studio LoRa E5 Mini](lora_e5_mini/README.md) | ARM Cortex-M4 | STM32WLE5JC | openocd | tockloader | No |
123123
[^1]: Tockloader is not able to interact with this board directly, but
124124
can be used to work on a flash-image of the board, which can in
125125
turn be flashed onto / read from the board. For more specific

boards/components/src/i2c.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ macro_rules! i2c_master_slave_component_static {
6666
};};
6767
}
6868

69+
#[macro_export]
70+
macro_rules! i2c_master_driver_component_static {
71+
($I:ty $(,)?) => {{
72+
let i2c_master_buffer = kernel::static_buf!([u8; 32]);
73+
74+
let driver = kernel::static_buf!(capsules_core::i2c_master::I2CMasterDriver<'static, $I>);
75+
76+
(driver, i2c_master_buffer)
77+
};};
78+
}
79+
6980
pub struct I2CMuxComponent<
7081
I: 'static + i2c::I2CMaster<'static>,
7182
S: 'static + i2c::SMBusMaster<'static> = NoSMBus,
@@ -173,3 +184,45 @@ impl<I: 'static + i2c::I2CMasterSlave<'static>> Component for I2CMasterSlaveDriv
173184
i2c_master_slave_driver
174185
}
175186
}
187+
188+
pub struct I2CMasterDriverComponent<I: 'static + i2c::I2CMaster<'static>> {
189+
board_kernel: &'static kernel::Kernel,
190+
driver_num: usize,
191+
i2c: &'static I,
192+
}
193+
194+
impl<I: 'static + i2c::I2CMaster<'static>> I2CMasterDriverComponent<I> {
195+
pub fn new(board_kernel: &'static kernel::Kernel, driver_num: usize, i2c: &'static I) -> Self {
196+
I2CMasterDriverComponent {
197+
board_kernel,
198+
driver_num,
199+
i2c,
200+
}
201+
}
202+
}
203+
impl<I: 'static + i2c::I2CMaster<'static>> Component for I2CMasterDriverComponent<I> {
204+
type StaticInput = (
205+
&'static mut MaybeUninit<capsules_core::i2c_master::I2CMasterDriver<'static, I>>,
206+
&'static mut MaybeUninit<[u8; 32]>,
207+
);
208+
type Output = &'static capsules_core::i2c_master::I2CMasterDriver<'static, I>;
209+
210+
fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
211+
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
212+
213+
let i2c_master_buffer = static_buffer.1.write([0; 32]);
214+
215+
let i2c_master_driver =
216+
static_buffer
217+
.0
218+
.write(capsules_core::i2c_master::I2CMasterDriver::new(
219+
self.i2c,
220+
i2c_master_buffer,
221+
self.board_kernel.create_grant(self.driver_num, &grant_cap),
222+
));
223+
224+
self.i2c.set_master_client(i2c_master_driver);
225+
226+
i2c_master_driver
227+
}
228+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2025.
4+
5+
include = [
6+
"../../cargo/tock_flags.toml",
7+
"../../cargo/unstable_flags.toml",
8+
]
9+
10+
[build]
11+
target = "thumbv7em-none-eabi"
12+
13+
[unstable]
14+
config-include = true

boards/lora_e5_mini/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2025.
4+
5+
[package]
6+
name = "lora_e5_mini"
7+
version.workspace = true
8+
authors.workspace = true
9+
edition.workspace = true
10+
build = "../build.rs"
11+
12+
[dependencies]
13+
components = { path = "../components" }
14+
cortexm4 = { path = "../../arch/cortex-m4" }
15+
kernel = { path = "../../kernel" }
16+
stm32wle5jc = { path = "../../chips/stm32wle5jc" }
17+
18+
capsules-core = { path = "../../capsules/core" }
19+
capsules-extra = { path = "../../capsules/extra" }
20+
capsules-system = { path = "../../capsules/system" }
21+
22+
[build-dependencies]
23+
tock_build_scripts = { path = "../build_scripts" }
24+
25+
[lints]
26+
workspace = true
27+

boards/lora_e5_mini/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2025.
4+
5+
# Makefile for building the tock kernel for the Seeed Studio LoRa E5 Mini board
6+
7+
include ../Makefile.common
8+
9+
OPENOCD=openocd
10+
11+
# Default target for installing the kernel.
12+
.PHONY: install
13+
install: flash
14+
15+
.PHONY: flash-debug
16+
flash-debug: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).bin
17+
$(OPENOCD) -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32wlx.cfg -c "init; reset halt; program $< verify 0x08000000; reset; shutdown"
18+
19+
.PHONY: flash
20+
flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
21+
$(OPENOCD) -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32wlx.cfg \
22+
-c "init; reset halt; program $< verify 0x08000000; reset; shutdown"
23+
24+
.PHONY: erase-all
25+
erase-all:
26+
$(OPENOCD) -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32wlx.cfg -c "init; reset halt; flash erase_sector 0 0 last; reset; shutdown"

boards/lora_e5_mini/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Platform-Specific Instructions: Seeed Studio LoRa E5 Mini
2+
=======================================================
3+
4+
The [Seeed Studio LoRa E5 Mini](https://wiki.seeedstudio.com/LoRa_E5_mini/) is a
5+
development board based around the [STM32WLE5JC](https://www.st.com/en/microcontrollers-microprocessors/stm32wle5jc.html), an SoC with an ARM Cortex-M4
6+
and LoRa SubGhz radio. This kit contains a UART to USB-C adaptor.
7+
8+
## Getting Started
9+
10+
First, follow the [Tock Getting Started guide](../../../doc/Getting_Started.md)
11+
12+
OpenOCD is the preferred method to program the board. The development kit does
13+
not have an integrated debugger. An external ST-Link is recommended. This can be
14+
connected to the board's SWD pins for programming.
15+
16+
## Programming the kernel
17+
Once you have all software installed, you should be able to simply run
18+
`make flash` in this directory to install a fresh kernel.
19+
20+
## Programming user-level applications
21+
You can program an application over USB using `tockloader`:
22+
23+
```bash
24+
$ cd libtock-c/examples/<app>
25+
$ make
26+
$ tockloader install
27+
```
28+
29+
## Console output
30+
To view the console output on the Seeed Studio LoRa E5 HF Mini:
31+
32+
```bash
33+
$ tockloader listen
34+
```
35+

boards/lora_e5_mini/chip_layout.ld

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Licensed under the Apache License, Version 2.0 or the MIT License. */
2+
/* SPDX-License-Identifier: Apache-2.0 OR MIT */
3+
/* Copyright Tock Contributors 2025. */
4+
5+
/* Memory layout for the STM32WLE5JC
6+
* rom = 252KB
7+
* kernel = 128KB
8+
* user = 128KB
9+
* ram = 64KB */
10+
11+
MEMORY
12+
{
13+
rom (rx) : ORIGIN = 0x08000000, LENGTH = 0x00020000
14+
prog (rx) : ORIGIN = 0x08020000, LENGTH = 0x00020000
15+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000
16+
}
17+
18+
PAGE_SIZE = 2K;

boards/lora_e5_mini/gdbinit.stlink

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2025.
4+
#
5+
# connect.gdb - GDB startup script for STM32 (Cortex-M4)
6+
7+
# Load ELF file with symbols
8+
file ../../target/thumbv7em-none-eabi/debug/lora_e5_mini.elf
9+
10+
# Connect to OpenOCD (or other gdbserver)
11+
target remote localhost:3333
12+
13+
# Optional: halt the CPU
14+
monitor reset halt
15+
16+
# Optional: print confirmation
17+
echo "Connected to target at localhost:3333\n"

0 commit comments

Comments
 (0)