-
Notifications
You must be signed in to change notification settings - Fork 18
Add wolfIP STM32 CubeMX Support #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aidangarske
wants to merge
5
commits into
wolfSSL:master
Choose a base branch
from
aidangarske:add-stm32-cube-ide
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ea9a8e0
Add wolfIP stm32CubeMX IDE support
aidangarske 306d947
Fix comments/concerns
aidangarske 6632242
Add STM32 HAL Ethernet driver for CubeMX integration
aidangarske 83c99d7
Fix Makefile to use WOLFIP_ENABLE_HTTP for native builds
aidangarske 4aae7f5
Update STM32Cube README and HAL driver
aidangarske File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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****/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.