Skip to content

Commit 8852f8e

Browse files
committed
STM32H563 port + test application
1 parent 0879fc2 commit 8852f8e

9 files changed

Lines changed: 970 additions & 0 deletions

File tree

src/port/stm32h563/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CC=arm-none-eabi-gcc
2+
OBJCOPY ?= arm-none-eabi-objcopy
3+
4+
ROOT := ../../..
5+
6+
CFLAGS := -mcpu=cortex-m33 -mthumb -mcmse -Os -ffreestanding -fdata-sections -ffunction-sections
7+
CFLAGS += -g -ggdb -Wall -Wextra -Werror -Wdeclaration-after-statement
8+
CFLAGS += -I. -I$(ROOT) -I$(ROOT)/src
9+
LDFLAGS := -nostdlib -T target.ld -Wl,-gc-sections
10+
11+
SRCS := startup.c ivt.c syscalls.c main.c stm32h5_eth.c $(ROOT)/src/wolfip.c
12+
OBJS := $(patsubst %.c,%.o,$(SRCS))
13+
14+
all: app.bin
15+
16+
app.elf: $(OBJS) target.ld
17+
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -Wl,--start-group -lc -lm -lgcc -lnosys -Wl,--end-group -o $@
18+
19+
app.bin: app.elf
20+
$(OBJCOPY) -O binary $< $@
21+
22+
%.o: %.c
23+
$(CC) $(CFLAGS) -c $< -o $@
24+
25+
clean:
26+
rm -f $(OBJS) app.elf app.bin
27+
28+
.PHONY: all clean

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+
};

src/port/stm32h563/main.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* main.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+
#include <string.h>
23+
#include "config.h"
24+
#include "wolfip.h"
25+
#include "stm32h5_eth.h"
26+
27+
#define ECHO_PORT 7
28+
#define RX_BUF_SIZE 1024
29+
30+
#define RCC_BASE 0x44020C00u
31+
#define RCC_AHB1ENR (*(volatile uint32_t *)(RCC_BASE + 0x88u))
32+
33+
static struct wolfIP *IPStack;
34+
static int listen_fd = -1;
35+
static int client_fd = -1;
36+
static uint8_t rx_buf[RX_BUF_SIZE];
37+
38+
uint32_t wolfIP_getrandom(void)
39+
{
40+
static uint32_t lfsr = 0x1A2B3C4DU;
41+
lfsr ^= lfsr << 13;
42+
lfsr ^= lfsr >> 17;
43+
lfsr ^= lfsr << 5;
44+
return lfsr;
45+
}
46+
47+
static void echo_cb(int fd, uint16_t event, void *arg)
48+
{
49+
struct wolfIP *s = (struct wolfIP *)arg;
50+
int ret;
51+
52+
if ((fd == listen_fd) && (event & CB_EVENT_READABLE) && (client_fd == -1)) {
53+
client_fd = wolfIP_sock_accept(s, listen_fd, NULL, NULL);
54+
if (client_fd > 0) {
55+
wolfIP_register_callback(s, client_fd, echo_cb, s);
56+
}
57+
return;
58+
}
59+
60+
if ((fd == client_fd) && (event & CB_EVENT_READABLE)) {
61+
ret = wolfIP_sock_recvfrom(s, client_fd, rx_buf, sizeof(rx_buf), 0, NULL, NULL);
62+
if (ret > 0) {
63+
(void)wolfIP_sock_sendto(s, client_fd, rx_buf, (uint32_t)ret, 0, NULL, 0);
64+
} else if (ret == 0) {
65+
wolfIP_sock_close(s, client_fd);
66+
client_fd = -1;
67+
}
68+
}
69+
70+
if ((fd == client_fd) && (event & CB_EVENT_CLOSED)) {
71+
wolfIP_sock_close(s, client_fd);
72+
client_fd = -1;
73+
}
74+
}
75+
76+
int main(void)
77+
{
78+
struct wolfIP_ll_dev *ll;
79+
struct wolfIP_sockaddr_in addr;
80+
uint64_t tick = 0;
81+
82+
wolfIP_init_static(&IPStack);
83+
RCC_AHB1ENR |= (1u << 19) | (1u << 20) | (1u << 21);
84+
ll = wolfIP_getdev(IPStack);
85+
(void)stm32h5_eth_init(ll, NULL);
86+
87+
wolfIP_ipconfig_set(IPStack,
88+
atoip4(WOLFIP_IP),
89+
atoip4(WOLFIP_NETMASK),
90+
atoip4(WOLFIP_GW));
91+
92+
listen_fd = wolfIP_sock_socket(IPStack, AF_INET, IPSTACK_SOCK_STREAM, 0);
93+
wolfIP_register_callback(IPStack, listen_fd, echo_cb, IPStack);
94+
95+
memset(&addr, 0, sizeof(addr));
96+
addr.sin_family = AF_INET;
97+
addr.sin_port = ee16(ECHO_PORT);
98+
addr.sin_addr.s_addr = 0;
99+
(void)wolfIP_sock_bind(IPStack, listen_fd, (struct wolfIP_sockaddr *)&addr, sizeof(addr));
100+
(void)wolfIP_sock_listen(IPStack, listen_fd, 1);
101+
102+
for (;;) {
103+
(void)wolfIP_poll(IPStack, tick++);
104+
}
105+
return 0;
106+
}

src/port/stm32h563/startup.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* startup.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 uint32_t _sidata;
24+
extern uint32_t _sdata;
25+
extern uint32_t _edata;
26+
extern uint32_t _sbss;
27+
extern uint32_t _ebss;
28+
extern void __libc_init_array(void);
29+
30+
int main(void);
31+
32+
void Reset_Handler(void)
33+
{
34+
uint32_t *src;
35+
uint32_t *dst;
36+
37+
src = &_sidata;
38+
for (dst = &_sdata; dst < &_edata; ) {
39+
*dst++ = *src++;
40+
}
41+
for (dst = &_sbss; dst < &_ebss; ) {
42+
*dst++ = 0u;
43+
}
44+
__libc_init_array();
45+
(void)main();
46+
while (1) { }
47+
}

0 commit comments

Comments
 (0)