@@ -80,6 +80,7 @@ extern "C" {
8080
8181
8282
83+
8384#if MG_ARCH == MG_ARCH_ARMCGT
8485
8586#include < ctype.h>
@@ -122,6 +123,91 @@ extern "C" {
122123#endif
123124
124125
126+ #if MG_ARCH == MG_ARCH_CUBE
127+
128+ #include < ctype.h>
129+ #include < errno.h>
130+ #include < stdarg.h>
131+ #include < stdbool.h>
132+ #include < stdio.h>
133+ #include < stdlib.h>
134+ #include < string.h>
135+ #include < sys/stat.h>
136+ #include < sys/time.h>
137+ #include < sys/types.h>
138+ #include < time.h>
139+ #include < unistd.h>
140+
141+ // Cube-generated header, includes ST Cube HAL
142+ // NOTE: use angle brackets to prevent amalgamator ditching it
143+ #include < main.h>
144+
145+ #ifndef MG_PATH_MAX
146+ #define MG_PATH_MAX 100
147+ #endif
148+
149+ #ifndef MG_ENABLE_DIRLIST
150+ #define MG_ENABLE_DIRLIST 0
151+ #endif
152+
153+ #ifndef MG_ENABLE_SOCKET
154+ #define MG_ENABLE_SOCKET 0
155+ #endif
156+
157+ #ifndef MG_ENABLE_TCPIP
158+ #define MG_ENABLE_TCPIP 1 // Enable built-in TCP/IP stack
159+ #endif
160+
161+ #if MG_ENABLE_TCPIP && !defined(MG_ENABLE_DRIVER_STM32F) && !defined(MG_ENABLE_DRIVER_STM32H)
162+ #if defined(STM32F1) || defined(STM32F2) || defined(STM32F4) || defined(STM32F7)
163+ #define MG_ENABLE_DRIVER_STM32F 1
164+ #elif defined(STM32H5) || defined(STM32H7)
165+ #define MG_ENABLE_DRIVER_STM32H 1
166+ #else
167+ #error Select a driver in mongoose_config.h
168+ #endif
169+ #endif
170+
171+ #ifndef MG_TLS
172+ #define MG_TLS MG_TLS_BUILTIN
173+ #endif
174+
175+ #if !defined(MG_OTA) && defined(STM32F1) || defined(STM32F2) || defined(STM32F4) || defined(STM32F7)
176+ #define MG_OTA MG_OTA_STM32F
177+ #elif !defined(MG_OTA) && defined(STM32H5)
178+ #define MG_OTA MG_OTA_STM32H5
179+ #elif !defined(MG_OTA) && defined(STM32H7)
180+ #define MG_OTA MG_OTA_STM32H7
181+ #endif
182+ // use HAL-defined execute-in-ram section
183+ #define MG_IRAM __attribute__ ((section(" .RamFunc" )))
184+
185+ #ifndef STM32H5
186+ #define HAL_ICACHE_IsEnabled () 0
187+ #define HAL_ICACHE_Enable () (void ) 0
188+ #define HAL_ICACHE_Disable () (void ) 0
189+ #endif
190+
191+ #ifndef MG_SET_MAC_ADDRESS
192+ // Construct MAC address from UUID
193+ #define MGUID ((uint32_t *) UID_BASE ) // Unique 96-bit chip ID
194+ #define MG_SET_MAC_ADDRESS (mac ) \
195+ do { \
196+ int icache_enabled_ = HAL_ICACHE_IsEnabled (); \
197+ if (icache_enabled_) HAL_ICACHE_Disable (); \
198+ mac[0 ] = 42 ; \
199+ mac[1 ] = ((MGUID [0 ] >> 0 ) & 255 ) ^ ((MGUID [2 ] >> 19 ) & 255 ); \
200+ mac[2 ] = ((MGUID [0 ] >> 10 ) & 255 ) ^ ((MGUID [1 ] >> 10 ) & 255 ); \
201+ mac[3 ] = (MGUID [0 ] >> 19 ) & 255 ; \
202+ mac[4 ] = ((MGUID [1 ] >> 0 ) & 255 ) ^ ((MGUID [2 ] >> 10 ) & 255 ); \
203+ mac[5 ] = ((MGUID [2 ] >> 0 ) & 255 ) ^ ((MGUID [1 ] >> 19 ) & 255 ); \
204+ if (icache_enabled_) HAL_ICACHE_Enable (); \
205+ } while (0 )
206+ #endif
207+
208+ #endif
209+
210+
125211#if MG_ARCH == MG_ARCH_ESP32
126212
127213#include < ctype.h>
@@ -3406,6 +3492,12 @@ struct mg_tcpip_driver_stm32f_data {
34063492#define MG_DRIVER_MDC_CR 4
34073493#endif
34083494
3495+ #if MG_ARCH == MG_ARCH_CUBE
3496+ #define MG_NEIRQ NVIC_EnableIRQ (ETH_IRQn)
3497+ #else
3498+ #define MG_NEIRQ
3499+ #endif
3500+
34093501#define MG_TCPIP_DRIVER_INIT (mgr ) \
34103502 do { \
34113503 static struct mg_tcpip_driver_stm32f_data driver_data_; \
@@ -3418,6 +3510,7 @@ struct mg_tcpip_driver_stm32f_data {
34183510 mif_.driver = &mg_tcpip_driver_stm32f; \
34193511 mif_.driver_data = &driver_data_; \
34203512 MG_SET_MAC_ADDRESS (mif_.mac ); \
3513+ MG_NEIRQ ; \
34213514 mg_tcpip_init (mgr, &mif_); \
34223515 MG_INFO ((" Driver: stm32f, MAC: %M" , mg_print_mac, mif_.mac )); \
34233516 } while (0 )
@@ -3465,6 +3558,12 @@ struct mg_tcpip_driver_stm32h_data {
34653558#define MG_DRIVER_MDC_CR 4
34663559#endif
34673560
3561+ #if MG_ENABLE_DRIVER_STM32H && MG_ARCH == MG_ARCH_CUBE
3562+ #define MG_NEIRQ NVIC_EnableIRQ (ETH_IRQn)
3563+ #else
3564+ #define MG_NEIRQ
3565+ #endif
3566+
34683567#define MG_TCPIP_DRIVER_INIT (mgr ) \
34693568 do { \
34703569 static struct mg_tcpip_driver_stm32h_data driver_data_; \
@@ -3479,6 +3578,7 @@ struct mg_tcpip_driver_stm32h_data {
34793578 mif_.driver_data = &driver_data_; \
34803579 MG_SET_MAC_ADDRESS (mif_.mac ); \
34813580 mg_tcpip_init (mgr, &mif_); \
3581+ MG_NEIRQ ; \
34823582 MG_INFO ((" Driver: stm32h, MAC: %M" , mg_print_mac, mif_.mac )); \
34833583 } while (0 )
34843584
0 commit comments