Skip to content

Commit c1b33d2

Browse files
authored
Merge pull request #12 from danielinux/stm32h565_port
STM32H563 port + test application
2 parents 0879fc2 + 3be384c commit c1b33d2

File tree

14 files changed

+1812
-7
lines changed

14 files changed

+1812
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ build/*
1313
test/unit/unit
1414
tags
1515
cppcheck_results.xml
16+
src/port/stm32h563/app.elf

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ CPPCHECK_FLAGS=--enable=warning,performance,portability,missingInclude \
8888
--suppress=constParameterCallback \
8989
--suppress=toomanyconfigs \
9090
--suppress=unmatchedSuppression --inconclusive \
91+
--suppress=comparePointers:src/port/stm32h563/startup.c \
92+
--suppress=comparePointers:src/port/stm32h563/syscalls.c \
9193
--disable=style \
9294
--std=c99 --language=c \
9395
--platform=unix64 \

src/port/stm32h563/Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
CC=arm-none-eabi-gcc
2+
OBJCOPY ?= arm-none-eabi-objcopy
3+
4+
ROOT := ../../..
5+
6+
# TrustZone support: set TZEN=1 for TrustZone enabled builds
7+
# Default is TZEN=0 (TrustZone disabled)
8+
TZEN ?= 0
9+
10+
CFLAGS := -mcpu=cortex-m33 -mthumb -mcmse -Os -ffreestanding -fdata-sections -ffunction-sections
11+
CFLAGS += -g -ggdb -Wall -Wextra -Werror -Wdeclaration-after-statement
12+
CFLAGS += -I. -I$(ROOT) -I$(ROOT)/src
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
24+
25+
SRCS := startup.c ivt.c syscalls.c main.c stm32h5_eth.c $(ROOT)/src/wolfip.c
26+
OBJS := $(patsubst %.c,%.o,$(SRCS))
27+
28+
all: app.bin
29+
@echo "Built with TZEN=$(TZEN) using $(LDSCRIPT)"
30+
31+
app.elf: $(OBJS) $(LDSCRIPT)
32+
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -Wl,--start-group -lc -lm -lgcc -lnosys -Wl,--end-group -o $@
33+
34+
app.bin: app.elf
35+
$(OBJCOPY) -O binary $< $@
36+
37+
%.o: %.c
38+
$(CC) $(CFLAGS) -c $< -o $@
39+
40+
clean:
41+
rm -f $(OBJS) app.elf app.bin
42+
43+
.PHONY: all clean

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.

src/port/stm32h563/config.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* config.h
2+
*
3+
* Copyright (C) 2026 wolfSSL Inc.
4+
*
5+
* This file is part of wolfIP TCP/IP stack.
6+
*
7+
* wolfIP is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfIP is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
#ifndef WOLF_CONFIG_H
22+
#define WOLF_CONFIG_H
23+
24+
#ifndef CONFIG_IPFILTER
25+
#define CONFIG_IPFILTER 0
26+
#endif
27+
28+
#define ETHERNET
29+
#define LINK_MTU 1536
30+
31+
#define MAX_TCPSOCKETS 4
32+
#define MAX_UDPSOCKETS 2
33+
#define MAX_ICMPSOCKETS 2
34+
#define RXBUF_SIZE (LINK_MTU * 16)
35+
#define TXBUF_SIZE (LINK_MTU * 16)
36+
37+
#define MAX_NEIGHBORS 16
38+
39+
#ifndef WOLFIP_MAX_INTERFACES
40+
#define WOLFIP_MAX_INTERFACES 1
41+
#endif
42+
43+
#ifndef WOLFIP_ENABLE_FORWARDING
44+
#define WOLFIP_ENABLE_FORWARDING 0
45+
#endif
46+
47+
#ifndef WOLFIP_ENABLE_LOOPBACK
48+
#define WOLFIP_ENABLE_LOOPBACK 0
49+
#endif
50+
51+
#define WOLFIP_IP "192.168.12.11"
52+
#define WOLFIP_NETMASK "255.255.255.0"
53+
#define WOLFIP_GW "192.168.12.1"
54+
#define WOLFIP_STATIC_DNS_IP "9.9.9.9"
55+
56+
#endif

src/port/stm32h563/ivt.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* ivt.c
2+
*
3+
* Copyright (C) 2026 wolfSSL Inc.
4+
*
5+
* This file is part of wolfIP TCP/IP stack.
6+
*
7+
* wolfIP is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfIP is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
#include <stdint.h>
22+
23+
extern void Reset_Handler(void);
24+
extern unsigned long _estack;
25+
26+
static void default_handler(void)
27+
{
28+
while (1) { }
29+
}
30+
31+
void NMI_Handler(void) __attribute__((weak, alias("default_handler")));
32+
void HardFault_Handler(void) __attribute__((weak, alias("default_handler")));
33+
void MemManage_Handler(void) __attribute__((weak, alias("default_handler")));
34+
void BusFault_Handler(void) __attribute__((weak, alias("default_handler")));
35+
void UsageFault_Handler(void)__attribute__((weak, alias("default_handler")));
36+
void SVC_Handler(void) __attribute__((weak, alias("default_handler")));
37+
void DebugMon_Handler(void) __attribute__((weak, alias("default_handler")));
38+
void PendSV_Handler(void) __attribute__((weak, alias("default_handler")));
39+
void SysTick_Handler(void) __attribute__((weak, alias("default_handler")));
40+
41+
__attribute__((section(".isr_vector")))
42+
const uint32_t vector_table[16 + 96] = {
43+
[0] = (uint32_t)&_estack,
44+
[1] = (uint32_t)&Reset_Handler,
45+
[2] = (uint32_t)&NMI_Handler,
46+
[3] = (uint32_t)&HardFault_Handler,
47+
[4] = (uint32_t)&MemManage_Handler,
48+
[5] = (uint32_t)&BusFault_Handler,
49+
[6] = (uint32_t)&UsageFault_Handler,
50+
[7] = 0, [8] = 0, [9] = 0, [10] = 0,
51+
[11] = (uint32_t)&SVC_Handler,
52+
[12] = (uint32_t)&DebugMon_Handler,
53+
[13] = 0,
54+
[14] = (uint32_t)&PendSV_Handler,
55+
[15] = (uint32_t)&SysTick_Handler,
56+
[16 ... 111] = (uint32_t)&default_handler
57+
};

0 commit comments

Comments
 (0)