Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/port/stm32h563/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CC=arm-none-eabi-gcc
OBJCOPY ?= arm-none-eabi-objcopy

ROOT := ../../..

CFLAGS := -mcpu=cortex-m33 -mthumb -mcmse -Os -ffreestanding -fdata-sections -ffunction-sections
CFLAGS += -g -ggdb -Wall -Wextra -Werror -Wdeclaration-after-statement
CFLAGS += -I. -I$(ROOT) -I$(ROOT)/src
LDFLAGS := -nostdlib -T target.ld -Wl,-gc-sections

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

all: app.bin

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

app.bin: app.elf
$(OBJCOPY) -O binary $< $@

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -f $(OBJS) app.elf app.bin

.PHONY: all clean
56 changes: 56 additions & 0 deletions src/port/stm32h563/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* config.h
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfIP TCP/IP stack.
*
* wolfIP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfIP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef WOLF_CONFIG_H
#define WOLF_CONFIG_H

#ifndef CONFIG_IPFILTER
#define CONFIG_IPFILTER 0
#endif

#define ETHERNET
#define LINK_MTU 1536

#define MAX_TCPSOCKETS 4
#define MAX_UDPSOCKETS 2
#define MAX_ICMPSOCKETS 2
#define RXBUF_SIZE (LINK_MTU * 16)
#define TXBUF_SIZE (LINK_MTU * 16)

#define MAX_NEIGHBORS 16

#ifndef WOLFIP_MAX_INTERFACES
#define WOLFIP_MAX_INTERFACES 1
#endif

#ifndef WOLFIP_ENABLE_FORWARDING
#define WOLFIP_ENABLE_FORWARDING 0
#endif

#ifndef WOLFIP_ENABLE_LOOPBACK
#define WOLFIP_ENABLE_LOOPBACK 0
#endif

#define WOLFIP_IP "192.168.12.11"
#define WOLFIP_NETMASK "255.255.255.0"
#define WOLFIP_GW "192.168.12.1"
#define WOLFIP_STATIC_DNS_IP "9.9.9.9"

#endif
57 changes: 57 additions & 0 deletions src/port/stm32h563/ivt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* ivt.c
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfIP TCP/IP stack.
*
* wolfIP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfIP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdint.h>

extern void Reset_Handler(void);
extern unsigned long _estack;

static void default_handler(void)
{
while (1) { }
}

void NMI_Handler(void) __attribute__((weak, alias("default_handler")));
void HardFault_Handler(void) __attribute__((weak, alias("default_handler")));
void MemManage_Handler(void) __attribute__((weak, alias("default_handler")));
void BusFault_Handler(void) __attribute__((weak, alias("default_handler")));
void UsageFault_Handler(void)__attribute__((weak, alias("default_handler")));
void SVC_Handler(void) __attribute__((weak, alias("default_handler")));
void DebugMon_Handler(void) __attribute__((weak, alias("default_handler")));
void PendSV_Handler(void) __attribute__((weak, alias("default_handler")));
void SysTick_Handler(void) __attribute__((weak, alias("default_handler")));

__attribute__((section(".isr_vector")))
const uint32_t vector_table[16 + 96] = {
[0] = (uint32_t)&_estack,
[1] = (uint32_t)&Reset_Handler,
[2] = (uint32_t)&NMI_Handler,
[3] = (uint32_t)&HardFault_Handler,
[4] = (uint32_t)&MemManage_Handler,
[5] = (uint32_t)&BusFault_Handler,
[6] = (uint32_t)&UsageFault_Handler,
[7] = 0, [8] = 0, [9] = 0, [10] = 0,
[11] = (uint32_t)&SVC_Handler,
[12] = (uint32_t)&DebugMon_Handler,
[13] = 0,
[14] = (uint32_t)&PendSV_Handler,
[15] = (uint32_t)&SysTick_Handler,
[16 ... 111] = (uint32_t)&default_handler
};
106 changes: 106 additions & 0 deletions src/port/stm32h563/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* main.c
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfIP TCP/IP stack.
*
* wolfIP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfIP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdint.h>
#include <string.h>
#include "config.h"
#include "wolfip.h"
#include "stm32h5_eth.h"

#define ECHO_PORT 7
#define RX_BUF_SIZE 1024

#define RCC_BASE 0x44020C00u
#define RCC_AHB1ENR (*(volatile uint32_t *)(RCC_BASE + 0x88u))

static struct wolfIP *IPStack;
static int listen_fd = -1;
static int client_fd = -1;
static uint8_t rx_buf[RX_BUF_SIZE];

uint32_t wolfIP_getrandom(void)
{
static uint32_t lfsr = 0x1A2B3C4DU;
lfsr ^= lfsr << 13;
lfsr ^= lfsr >> 17;
lfsr ^= lfsr << 5;
return lfsr;
}

static void echo_cb(int fd, uint16_t event, void *arg)
{
struct wolfIP *s = (struct wolfIP *)arg;
int ret;

if ((fd == listen_fd) && (event & CB_EVENT_READABLE) && (client_fd == -1)) {
client_fd = wolfIP_sock_accept(s, listen_fd, NULL, NULL);
if (client_fd > 0) {
wolfIP_register_callback(s, client_fd, echo_cb, s);
}
return;
}

if ((fd == client_fd) && (event & CB_EVENT_READABLE)) {
ret = wolfIP_sock_recvfrom(s, client_fd, rx_buf, sizeof(rx_buf), 0, NULL, NULL);
if (ret > 0) {
(void)wolfIP_sock_sendto(s, client_fd, rx_buf, (uint32_t)ret, 0, NULL, 0);
} else if (ret == 0) {
wolfIP_sock_close(s, client_fd);
client_fd = -1;
}
}

if ((fd == client_fd) && (event & CB_EVENT_CLOSED)) {
wolfIP_sock_close(s, client_fd);
client_fd = -1;
}
}

int main(void)
{
struct wolfIP_ll_dev *ll;
struct wolfIP_sockaddr_in addr;
uint64_t tick = 0;

wolfIP_init_static(&IPStack);
RCC_AHB1ENR |= (1u << 19) | (1u << 20) | (1u << 21);
ll = wolfIP_getdev(IPStack);
(void)stm32h5_eth_init(ll, NULL);

wolfIP_ipconfig_set(IPStack,
atoip4(WOLFIP_IP),
atoip4(WOLFIP_NETMASK),
atoip4(WOLFIP_GW));

listen_fd = wolfIP_sock_socket(IPStack, AF_INET, IPSTACK_SOCK_STREAM, 0);
wolfIP_register_callback(IPStack, listen_fd, echo_cb, IPStack);

memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = ee16(ECHO_PORT);
addr.sin_addr.s_addr = 0;
(void)wolfIP_sock_bind(IPStack, listen_fd, (struct wolfIP_sockaddr *)&addr, sizeof(addr));
(void)wolfIP_sock_listen(IPStack, listen_fd, 1);

for (;;) {
(void)wolfIP_poll(IPStack, tick++);
}
return 0;
}
47 changes: 47 additions & 0 deletions src/port/stm32h563/startup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* startup.c
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfIP TCP/IP stack.
*
* wolfIP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfIP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdint.h>

extern uint32_t _sidata;
extern uint32_t _sdata;
extern uint32_t _edata;
extern uint32_t _sbss;
extern uint32_t _ebss;
extern void __libc_init_array(void);

int main(void);

void Reset_Handler(void)
{
uint32_t *src;
uint32_t *dst;

src = &_sidata;
for (dst = &_sdata; dst < &_edata; ) {
*dst++ = *src++;
}
for (dst = &_sbss; dst < &_ebss; ) {
*dst++ = 0u;
}
__libc_init_array();
(void)main();
while (1) { }
}
Loading
Loading