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
144 changes: 144 additions & 0 deletions IDE/STM32Cube/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# wolfIP for STM32 CubeIDE

This guide explains how to use wolfIP on any STM32 microcontroller with Ethernet using STM32CubeMX and the wolfIP CMSIS pack.

## Supported STM32 Families

| Family | Interface Config | Auto-Detected | Example Boards |
|----------|------------------|---------------|----------------|
| STM32F4 | SYSCFG->PMC | Yes | NUCLEO-F429ZI, STM32F4-Discovery |
| STM32F7 | SYSCFG->PMC | Yes | NUCLEO-F746ZG, NUCLEO-F767ZI |
| STM32H5 | SBS->PMCR | Yes | NUCLEO-H563ZI, NUCLEO-H573ZI |
| STM32H7 | SYSCFG->PMCR | Yes | NUCLEO-H743ZI, NUCLEO-H753ZI |
| Others | Manual | Fallback | See family reference manual |

## Quick Start

### Step 1: Install the wolfIP Pack

1. Download the pack from [wolfSSL](https://www.wolfssl.com/files/ide/I-CUBE-wolfIP.pack)
2. In STM32CubeMX: **Help → Manage Embedded Software Packages → From Local**
3. Select `I-CUBE-wolfIP.pack` and accept the license

### Step 2: Create CubeMX Project

1. Create new project for your board
2. Configure **Connectivity → ETH**:
- Mode: **RMII** (or MII depending on board)
- Verify GPIO pin assignments match your board's PHY (CubeMX auto-configures for NUCLEO boards)
3. Configure **System Core → NVIC**:
- **ETH global interrupt: ENABLED** (CRITICAL - required for RX)
4. Configure **Software Packs → Select Components**:
- Expand wolfIP → Check **Core** and **Eth**
5. Configure **Software Packs → wolfIP**:
- Enable the library checkbox
6. Generate code (Makefile recommended for command-line builds)

**Note:** For NUCLEO boards, CubeMX auto-configures the correct ETH GPIO pins. For custom boards, verify pins match your PHY datasheet.

**That's it for CubeMX!** No MspInit changes needed - the driver auto-configures RMII/MII.

### Step 3: Add wolfIP Code to main.c

Add this code to your CubeMX-generated main.c in the corresponding USER CODE sections:

**In USER CODE BEGIN Includes:**
```c
#include "wolfip.h"
#include "stm32_hal_eth.h"
```

**In USER CODE BEGIN PV:**
```c
static struct wolfIP *ipstack = NULL;
```

**In USER CODE BEGIN 2 (after MX_ETH_Init):**
```c
wolfIP_init_static(&ipstack);
if (stm32_hal_eth_init(wolfIP_getdev(ipstack)) != 0) {
Error_Handler();
}
wolfIP_ipconfig_set(ipstack,
atoip4("192.168.0.200"),
atoip4("255.255.255.0"),
atoip4("192.168.0.1"));
```

**In USER CODE BEGIN 3 (inside while loop):**
```c
wolfIP_poll(ipstack, HAL_GetTick());
```

**In USER CODE BEGIN 4:**
```c
uint32_t wolfIP_getrandom(void)
{
static uint32_t seed = 12345;
seed = seed * 1103515245 + 12345;
return (seed >> 16) ^ HAL_GetTick();
}
```

**Alternative: Use DHCP** instead of static IP by enabling DHCP in Software Packs -> wolfIP settings.

### Step 4: Build and Test

1. Build the project
2. Flash to your board
3. Connect Ethernet cable
4. Ping from your PC: `ping 192.168.0.200`

## Troubleshooting

### No ping response

1. **Check NVIC**: ETH global interrupt must be ENABLED in CubeMX
2. **Check cable**: Ensure Ethernet cable is connected and link LED is on
3. **Check IP**: Ensure IP address is on same subnet as your PC
4. **Check return value**: Verify `stm32_hal_eth_init()` returns 0

### stm32_hal_eth_init() returns -3

This means the ETH reinitialization failed. Check:
- ETH peripheral is properly configured in CubeMX
- GPIO pins are correctly assigned for your board's PHY

### Unsupported STM32 family

For families not auto-detected (F4, F7, H5, H7), add RMII/MII config in MspInit:

```c
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
{
if(heth->Instance==ETH)
{
/* USER CODE BEGIN ETH_MspInit 0 */
/* Manual RMII config - see your STM32 family reference manual */
__HAL_RCC_SYSCFG_CLK_ENABLE();
SYSCFG->PMC |= SYSCFG_PMC_MII_RMII_SEL; /* Example for F4/F7 */
/* USER CODE END ETH_MspInit 0 */
...
}
}
```

## Using TLS with wolfIP

To use TLS (HTTPS, secure sockets):

1. First install wolfSSL pack: [wolfSSL CubeIDE Guide](https://github.com/wolfSSL/wolfssl/blob/master/IDE/STM32Cube/README.md)
2. In Software Packs, also check **wolfSSL-IO** component
3. See wolfSSL examples for TLS socket usage

## Additional Resources

- [wolfIP GitHub](https://github.com/wolfSSL/wolfip)
- [STM32H563 Bare-metal Example](../../src/port/stm32h563/)
- [wolfSSL Support](mailto:support@wolfssl.com)

## Notes

- wolfIP uses zero dynamic memory allocation - all buffers are pre-allocated
- Default configuration supports 4 TCP sockets, 4 UDP sockets
- Adjust `config.h` for different socket pool sizes or buffer sizes
172 changes: 172 additions & 0 deletions IDE/STM32Cube/default_conf.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
[#ftl]
/**
******************************************************************************
* File Name : ${name}
* Description : This file provides code for the configuration
* of the ${name} instances.
******************************************************************************
[@common.optinclude name=mxTmpFolder+"/license.tmp"/][#--include License text --]
******************************************************************************
*/
[#assign s = name]
[#assign toto = s?replace(".","_")]
[#assign toto = toto?replace("/","")]
[#assign toto = toto?replace("-","_")]
[#assign inclusion_protection = toto?upper_case]
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __${inclusion_protection}__
#define __${inclusion_protection}__

#ifdef __cplusplus
extern "C" {
#endif


/* Includes ------------------------------------------------------------------*/
[#if includes??]
[#list includes as include]
#include "${include}"
[/#list]
[/#if]

[#-- SWIPdatas is a list of SWIPconfigModel --]
[#list SWIPdatas as SWIP]
[#-- Global variables --]
[#if SWIP.variables??]
[#list SWIP.variables as variable]
extern ${variable.value} ${variable.name};
[/#list]
[/#if]

[#-- Global variables --]

[#assign instName = SWIP.ipName]
[#assign fileName = SWIP.fileName]
[#assign version = SWIP.version]

/**
MiddleWare name : ${instName}
MiddleWare fileName : ${fileName}
MiddleWare version : ${version}
*/
[#if SWIP.defines??]
[#list SWIP.defines as definition]
/*---------- [#if definition.comments??]${definition.comments}[/#if] -----------*/
#define ${definition.name} #t#t ${definition.value}
[#if definition.description??]${definition.description} [/#if]
[/#list]
[/#if]



[/#list]

/* ------------------------------------------------------------------------- */
/* Platform */
/* ------------------------------------------------------------------------- */
#define WOLFIP_STM32_CUBEMX
#define NO_FILESYSTEM

/* ------------------------------------------------------------------------- */
/* Socket Pool Configuration */
/* ------------------------------------------------------------------------- */
#if defined(WOLFIP_CONF_MAX_TCP) && WOLFIP_CONF_MAX_TCP > 0
#define MAX_TCPSOCKETS WOLFIP_CONF_MAX_TCP
#else
#define MAX_TCPSOCKETS 4
#endif

#if defined(WOLFIP_CONF_MAX_UDP) && WOLFIP_CONF_MAX_UDP > 0
#define MAX_UDPSOCKETS WOLFIP_CONF_MAX_UDP
#else
#define MAX_UDPSOCKETS 2
#endif

#if defined(WOLFIP_CONF_MAX_ICMP) && WOLFIP_CONF_MAX_ICMP > 0
#define MAX_ICMPSOCKETS WOLFIP_CONF_MAX_ICMP
#else
#define MAX_ICMPSOCKETS 2
#endif

/* ------------------------------------------------------------------------- */
/* Buffer Configuration */
/* ------------------------------------------------------------------------- */
#if defined(WOLFIP_CONF_MTU) && WOLFIP_CONF_MTU > 0
#define LINK_MTU WOLFIP_CONF_MTU
#else
#define LINK_MTU 1536
#endif

#define RXBUF_SIZE (LINK_MTU * 16)
#define TXBUF_SIZE (LINK_MTU * 16)

/* ------------------------------------------------------------------------- */
/* Network Configuration */
/* ------------------------------------------------------------------------- */
#define ETHERNET
#define MAX_NEIGHBORS 16

/* ------------------------------------------------------------------------- */
/* Enable/Disable Features */
/* ------------------------------------------------------------------------- */

/* DHCP Client */
#if defined(WOLFIP_CONF_DHCP) && WOLFIP_CONF_DHCP == 1
#define WOLFIP_ENABLE_DHCP
#endif

/* HTTP Server */
#if defined(WOLFIP_CONF_HTTP) && WOLFIP_CONF_HTTP == 1
#define WOLFIP_ENABLE_HTTP
#endif

/* Loopback Interface */
#undef WOLFIP_ENABLE_LOOPBACK
#if defined(WOLFIP_CONF_LOOPBACK) && WOLFIP_CONF_LOOPBACK == 1
#define WOLFIP_ENABLE_LOOPBACK 1
#ifndef WOLFIP_MAX_INTERFACES
#define WOLFIP_MAX_INTERFACES 2
#endif
#else
#define WOLFIP_ENABLE_LOOPBACK 0
#endif

/* IP Forwarding */
#undef WOLFIP_ENABLE_FORWARDING
#if defined(WOLFIP_CONF_FORWARDING) && WOLFIP_CONF_FORWARDING == 1
#define WOLFIP_ENABLE_FORWARDING 1
#else
#define WOLFIP_ENABLE_FORWARDING 0
#endif

#ifndef WOLFIP_MAX_INTERFACES
#define WOLFIP_MAX_INTERFACES 1
#endif

/* ------------------------------------------------------------------------- */
/* Debugging */
/* ------------------------------------------------------------------------- */
#if defined(WOLFIP_CONF_DEBUG) && WOLFIP_CONF_DEBUG == 1
#define DEBUG
#else
#undef DEBUG
#endif

/* ------------------------------------------------------------------------- */
/* wolfSSL Integration */
/* ------------------------------------------------------------------------- */
/* Define WOLFSSL_WOLFIP to enable wolfSSL IO callbacks for TLS support.
* Requires wolfSSL Cube Pack to be installed and configured.
*/
/* #define WOLFSSL_WOLFIP */

#ifdef __cplusplus
}
#endif
#endif /* __${inclusion_protection}__ */

/**
* @}
*/

/*****END OF FILE****/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ build/tcp_netcat_select: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_net

build/test-wolfssl:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP
build/test-httpd:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP -Isrc/http
build/test/test_httpd.o:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP -DWOLFIP_ENABLE_HTTP -Isrc/http
build/http/httpd.o:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP -DWOLFIP_ENABLE_HTTP -Isrc/http
build/test-wolfssl-forwarding:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP -DWOLFIP_MAX_INTERFACES=2 -DWOLFIP_ENABLE_FORWARDING=1

build/test-wolfssl: $(OBJ) build/test/test_native_wolfssl.o build/port/wolfssl_io.o build/certs/server_key.o build/certs/ca_cert.o build/certs/server_cert.o
Expand Down
5 changes: 5 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
#define WOLFIP_ENABLE_LOOPBACK 0
#endif

/* Enable HTTP server for POSIX builds */
#ifndef WOLFIP_ENABLE_HTTP
#define WOLFIP_ENABLE_HTTP
#endif

#if WOLFIP_ENABLE_LOOPBACK && WOLFIP_MAX_INTERFACES < 2
#error "WOLFIP_ENABLE_LOOPBACK requires WOLFIP_MAX_INTERFACES > 1"
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/http/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
*
*
*/

#ifdef WOLFIP_ENABLE_HTTP

#include "wolfip.h"
#include "httpd.h"
#include <ctype.h>
Expand Down Expand Up @@ -525,3 +528,5 @@ int httpd_init(struct httpd *httpd, struct wolfIP *s, uint16_t port, void *ssl_c
wolfIP_register_callback(s, httpd->listen_sd, http_accept_cb, httpd);
return 0;
}

#endif /* WOLFIP_ENABLE_HTTP */
7 changes: 6 additions & 1 deletion src/http/httpd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef WOLF_HTTPD_H
#define WOLF_HTTPD_H

#ifdef WOLFIP_ENABLE_HTTP

#ifdef WOLFSSL_USER_SETTINGS
#include <user_settings.h>
#else
Expand All @@ -8,6 +11,7 @@
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <stdint.h>
#include <stddef.h>

#define HTTP_METHOD_LEN 8
#define HTTP_PATH_LEN 128
Expand Down Expand Up @@ -86,5 +90,6 @@ void http_send_418_teapot(struct http_client *hc);
int http_url_decode(char *buf, size_t len);
int http_url_encode(char *buf, size_t len, size_t max_len);

#endif /* WOLFIP_ENABLE_HTTP */

#endif
#endif /* WOLF_HTTPD_H */
Loading