Skip to content

Commit 3abb04c

Browse files
committed
Progress with TZEN=1 mode.
1 parent 2f5df91 commit 3abb04c

5 files changed

Lines changed: 401 additions & 115 deletions

File tree

src/port/stm32h563/Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ OBJCOPY ?= arm-none-eabi-objcopy
33

44
ROOT := ../../..
55

6+
# TrustZone support: set TZEN=1 for TrustZone enabled builds
7+
# Default is TZEN=0 (TrustZone disabled)
8+
TZEN ?= 0
9+
610
CFLAGS := -mcpu=cortex-m33 -mthumb -mcmse -Os -ffreestanding -fdata-sections -ffunction-sections
711
CFLAGS += -g -ggdb -Wall -Wextra -Werror -Wdeclaration-after-statement
812
CFLAGS += -I. -I$(ROOT) -I$(ROOT)/src
9-
LDFLAGS := -nostdlib -T target.ld -Wl,-gc-sections
13+
14+
# Select linker script based on TZEN setting
15+
ifeq ($(TZEN),1)
16+
LDSCRIPT := target_tzen.ld
17+
CFLAGS += -DTZEN_ENABLED=1
18+
else
19+
LDSCRIPT := target.ld
20+
CFLAGS += -DTZEN_ENABLED=0
21+
endif
22+
23+
LDFLAGS := -nostdlib -T $(LDSCRIPT) -Wl,-gc-sections
1024

1125
SRCS := startup.c ivt.c syscalls.c main.c stm32h5_eth.c $(ROOT)/src/wolfip.c
1226
OBJS := $(patsubst %.c,%.o,$(SRCS))
1327

1428
all: app.bin
29+
@echo "Built with TZEN=$(TZEN) using $(LDSCRIPT)"
1530

16-
app.elf: $(OBJS) target.ld
31+
app.elf: $(OBJS) $(LDSCRIPT)
1732
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -Wl,--start-group -lc -lm -lgcc -lnosys -Wl,--end-group -o $@
1833

1934
app.bin: app.elf

src/port/stm32h563/README.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# wolfIP STM32H563 Port
2+
3+
This directory contains a bare-metal port of wolfIP for the STM32H563 microcontroller, featuring an Ethernet driver and TCP/IP echo server example.
4+
5+
## Hardware Requirements
6+
7+
- STM32H563 development board (e.g., NUCLEO-H563ZI)
8+
- Ethernet connection (RMII interface)
9+
- ST-LINK debugger (built-in on NUCLEO boards)
10+
- USB cable for serial output
11+
12+
## Software Requirements
13+
14+
- ARM GCC toolchain (`arm-none-eabi-gcc`)
15+
- OpenOCD (STMicroelectronics fork recommended)
16+
- Serial terminal (e.g., minicom, screen, or picocom)
17+
18+
### Installing Dependencies (Ubuntu/Debian)
19+
20+
```bash
21+
sudo apt install gcc-arm-none-eabi openocd
22+
```
23+
24+
## Building
25+
26+
### Default Build (TrustZone Disabled - Recommended)
27+
28+
```bash
29+
cd src/port/stm32h563
30+
make TZEN=0
31+
```
32+
33+
This produces `app.elf` and `app.bin` for use with TZEN=0 (TrustZone disabled).
34+
35+
### TrustZone Enabled Build (Experimental)
36+
37+
```bash
38+
make TZEN=1
39+
```
40+
41+
> **Note:** TZEN=1 support is experimental. The Ethernet driver currently has issues receiving packets when TrustZone is enabled.
42+
43+
## Disabling TrustZone (Option Bytes)
44+
45+
If your board has TrustZone enabled, you must disable it via option bytes before using the TZEN=0 build. Use STM32CubeProgrammer or OpenOCD:
46+
47+
### Using STM32CubeProgrammer (Recommended)
48+
49+
1. Open STM32CubeProgrammer
50+
2. Connect to the target
51+
3. Go to **Option Bytes** tab
52+
4. Find **TZEN** under "User Configuration"
53+
5. Set TZEN to **0xC3** (disabled)
54+
6. Click **Apply**
55+
56+
### Using OpenOCD
57+
58+
```bash
59+
openocd -f interface/stlink-dap.cfg -f target/stm32h5x.cfg -c "init" -c "halt" -c "stm32h5x option_write 0 0x5200201C 0xC3B6" -c "reset" -c "exit"
60+
```
61+
62+
> **Warning:** Modifying option bytes can lock the device. Ensure you understand the process before proceeding.
63+
64+
### Verifying TrustZone Status
65+
66+
When flashing, OpenOCD will report TrustZone status:
67+
68+
```
69+
Info : TZEN = 0xC3 : TrustZone disabled by option bytes # Good for TZEN=0
70+
Info : TZEN = 0xB4 : TrustZone enabled by option bytes # Requires TZEN=1 build
71+
```
72+
73+
## Flashing
74+
75+
```bash
76+
openocd -f interface/stlink-dap.cfg -f target/stm32h5x.cfg \
77+
-c "program app.elf verify reset exit"
78+
```
79+
80+
## Serial Console
81+
82+
Connect to the USB serial port (typically `/dev/ttyACM0`) at 115200 baud:
83+
84+
```bash
85+
# Using screen
86+
screen /dev/ttyACM0 115200
87+
88+
# Using minicom
89+
minicom -D /dev/ttyACM0 -b 115200
90+
91+
# Using picocom
92+
picocom -b 115200 /dev/ttyACM0
93+
```
94+
95+
## Example Output
96+
97+
When the firmware boots successfully, you should see output similar to:
98+
99+
```
100+
=== wolfIP STM32H563 Echo Server ===
101+
Initializing wolfIP stack...
102+
Configuring GPIO for RMII...
103+
Enabling Ethernet clocks...
104+
Resetting Ethernet MAC...
105+
Initializing Ethernet MAC...
106+
PHY link: UP, PHY addr: 0x00000000
107+
Setting IP configuration:
108+
IP: 192.168.12.11
109+
Mask: 255.255.255.0
110+
GW: 192.168.12.1
111+
Creating TCP socket on port 7...
112+
Entering main loop. Ready for connections!
113+
Loop starting...
114+
```
115+
116+
The "PHY link: UP" message indicates the Ethernet PHY has established a link with the network.
117+
118+
## Network Configuration
119+
120+
The example configures the following static IP:
121+
122+
| Setting | Value |
123+
|---------|-------|
124+
| IP Address | 192.168.12.11 |
125+
| Subnet Mask | 255.255.255.0 |
126+
| Gateway | 192.168.12.1 |
127+
128+
Configure your host PC's Ethernet interface to be on the same subnet:
129+
130+
```bash
131+
sudo ip addr add 192.168.12.1/24 dev <interface>
132+
sudo ip link set <interface> up
133+
```
134+
135+
Replace `<interface>` with your Ethernet interface name (e.g., `eth0`, `enp5s0`).
136+
137+
## Testing
138+
139+
Once running, the echo server listens on TCP port 7:
140+
141+
```bash
142+
# Test with netcat
143+
echo "Hello wolfIP!" | nc 192.168.12.11 7
144+
145+
# Test with ping
146+
ping 192.168.12.11
147+
```
148+
149+
## Files
150+
151+
| File | Description |
152+
|------|-------------|
153+
| `main.c` | Application entry point, wolfIP initialization, echo server |
154+
| `stm32h5_eth.c` | Ethernet MAC/DMA driver for STM32H5 |
155+
| `stm32h5_eth.h` | Ethernet driver header |
156+
| `startup.c` | Startup code and data initialization |
157+
| `ivt.c` | Interrupt vector table |
158+
| `syscalls.c` | Newlib syscall stubs |
159+
| `target.ld` | Linker script for TZEN=0 |
160+
| `target_tzen.ld` | Linker script for TZEN=1 |
161+
| `config.h` | Build configuration |
162+
| `Makefile` | Build system |
163+
164+
## TrustZone Support (TZEN=1) - Experimental
165+
166+
The TZEN=1 build adds TrustZone support:
167+
168+
- **SAU Configuration:** Marks memory regions for non-secure DMA access
169+
- **GTZC/MPCBB:** Configures SRAM3 blocks for Ethernet DMA
170+
- **Secure Aliases:** Uses secure peripheral addresses (0x5xxxxxxx)
171+
- **Separate ETHMEM:** Places Ethernet buffers in dedicated non-secure SRAM
172+
173+
### Current Limitations
174+
175+
The TZEN=1 build compiles and runs, but the Ethernet driver experiences RBU (Receive Buffer Unavailable) errors. This appears to be a DMA access issue that requires further investigation.
176+
177+
## Troubleshooting
178+
179+
### No Serial Output
180+
181+
- Check USB connection and correct serial port
182+
- Verify baud rate is 115200
183+
- Try resetting the board
184+
185+
### OpenOCD Connection Fails
186+
187+
- Ensure ST-LINK drivers are installed
188+
- Try `sudo` if permission denied
189+
- Check that no other debugger is connected
190+
191+
### Ethernet Not Responding
192+
193+
- Verify physical Ethernet connection
194+
- Check that host PC is on same subnet (192.168.12.x)
195+
- Confirm PHY link is up (check serial output for "link" status)
196+
197+
### TrustZone Errors
198+
199+
If you see `stm32h5x.cpu in Secure state` but built with TZEN=0:
200+
- The board has TrustZone enabled
201+
- Either rebuild with `make TZEN=1` or disable TrustZone via option bytes
202+
203+
## License
204+
205+
This code is part of wolfIP and is licensed under GPLv3. See the LICENSE file in the repository root for details.
206+
207+
Copyright (C) 2026 wolfSSL Inc.

0 commit comments

Comments
 (0)