Skip to content

Commit e48dc31

Browse files
aidangarskedanielinux
authored andcommitted
Update STM32Cube README and HAL driver
README: - Add GPIO pin configuration note for custom boards - Clarify ETH interrupt required for RX - Update example IP to 192.168.0.200 stm32_hal_eth.c: - Add wolfip_get_time_ms callback for CubeMX builds Tested on NUCLEO-H563ZI.
1 parent 4689486 commit e48dc31

2 files changed

Lines changed: 45 additions & 50 deletions

File tree

IDE/STM32Cube/README.md

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ This guide explains how to use wolfIP on any STM32 microcontroller with Ethernet
66

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

15-
## Quick Start - Zero Configuration!
15+
## Quick Start
1616

1717
### Step 1: Install the wolfIP Pack
1818

@@ -25,84 +25,69 @@ This guide explains how to use wolfIP on any STM32 microcontroller with Ethernet
2525
1. Create new project for your board
2626
2. Configure **Connectivity → ETH**:
2727
- Mode: **RMII** (or MII depending on board)
28+
- Verify GPIO pin assignments match your board's PHY (CubeMX auto-configures for NUCLEO boards)
2829
3. Configure **System Core → NVIC**:
29-
- **ETH global interrupt: ENABLED** ⚠️ CRITICAL
30+
- **ETH global interrupt: ENABLED** (CRITICAL - required for RX)
3031
4. Configure **Software Packs → Select Components**:
3132
- Expand wolfIP → Check **Core** and **Eth**
3233
5. Configure **Software Packs → wolfIP**:
3334
- Enable the library checkbox
34-
6. Generate code
35+
6. Generate code (Makefile recommended for command-line builds)
36+
37+
**Note:** For NUCLEO boards, CubeMX auto-configures the correct ETH GPIO pins. For custom boards, verify pins match your PHY datasheet.
3538

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

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

43+
Add this code to your CubeMX-generated main.c in the corresponding USER CODE sections:
44+
45+
**In USER CODE BEGIN Includes:**
4046
```c
41-
/* USER CODE BEGIN Includes */
4247
#include "wolfip.h"
4348
#include "stm32_hal_eth.h"
44-
/* USER CODE END Includes */
49+
```
4550

46-
/* USER CODE BEGIN PV */
51+
**In USER CODE BEGIN PV:**
52+
```c
4753
static struct wolfIP *ipstack = NULL;
54+
```
4855

49-
/* IP Configuration - adjust for your network */
50-
#define MY_IP atoip4("192.168.1.100")
51-
#define MY_MASK atoip4("255.255.255.0")
52-
#define MY_GATEWAY atoip4("192.168.1.1")
53-
/* USER CODE END PV */
54-
55-
int main(void)
56-
{
57-
HAL_Init();
58-
SystemClock_Config();
59-
MX_GPIO_Init();
60-
MX_ETH_Init();
61-
62-
/* USER CODE BEGIN 2 */
63-
/* Initialize wolfIP */
64-
wolfIP_init_static(&ipstack);
65-
if (stm32_hal_eth_init(wolfIP_getdev(ipstack)) != 0) {
66-
Error_Handler();
67-
}
68-
wolfIP_ipconfig_set(ipstack, MY_IP, MY_MASK, MY_GATEWAY);
69-
/* USER CODE END 2 */
70-
71-
while (1)
72-
{
73-
/* USER CODE BEGIN 3 */
74-
wolfIP_poll(ipstack, HAL_GetTick());
75-
/* USER CODE END 3 */
76-
}
56+
**In USER CODE BEGIN 2 (after MX_ETH_Init):**
57+
```c
58+
wolfIP_init_static(&ipstack);
59+
if (stm32_hal_eth_init(wolfIP_getdev(ipstack)) != 0) {
60+
Error_Handler();
7761
}
62+
wolfIP_ipconfig_set(ipstack,
63+
atoip4("192.168.0.200"),
64+
atoip4("255.255.255.0"),
65+
atoip4("192.168.0.1"));
7866
```
7967
80-
### Step 4: Add Required Callbacks
81-
82-
Add these functions to your main.c (wolfIP requires them):
83-
68+
**In USER CODE BEGIN 3 (inside while loop):**
8469
```c
85-
/* USER CODE BEGIN 4 */
86-
uint64_t wolfip_get_time_ms(void)
87-
{
88-
return (uint64_t)HAL_GetTick();
89-
}
70+
wolfIP_poll(ipstack, HAL_GetTick());
71+
```
9072

73+
**In USER CODE BEGIN 4:**
74+
```c
9175
uint32_t wolfIP_getrandom(void)
9276
{
9377
static uint32_t seed = 12345;
9478
seed = seed * 1103515245 + 12345;
9579
return (seed >> 16) ^ HAL_GetTick();
9680
}
97-
/* USER CODE END 4 */
9881
```
9982
100-
### Step 5: Build and Test
83+
**Alternative: Use DHCP** instead of static IP by enabling DHCP in Software Packs -> wolfIP settings.
84+
85+
### Step 4: Build and Test
10186
10287
1. Build the project
10388
2. Flash to your board
10489
3. Connect Ethernet cable
105-
4. Ping from your PC: `ping 192.168.1.100`
90+
4. Ping from your PC: `ping 192.168.0.200`
10691
10792
## Troubleshooting
10893

src/port/stm32_hal/stm32_hal_eth.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,13 @@ int stm32_hal_eth_init(struct wolfIP_ll_dev *ll)
288288

289289
return 0;
290290
}
291+
292+
/* wolfIP callbacks for CubeMX builds */
293+
#ifdef WOLFIP_STM32_CUBEMX
294+
295+
uint64_t wolfip_get_time_ms(void)
296+
{
297+
return (uint64_t)HAL_GetTick();
298+
}
299+
300+
#endif /* WOLFIP_STM32_CUBEMX */

0 commit comments

Comments
 (0)