lwIP basic configuration in Keil MDK
RTOS integration
Beyond stack space, there are no special considerations for the CMSIS-RTOS v2 API
- When using FreeRTOS native interface:
- in
RTOS/FreeRTOSConfig.h- add
#define configUSE_POSIX_ERRNO 1and#define configPRINTF printf - configure a minimum stack size (
configMINIMAL_STACK_SIZE) of 256 words. The default of 128 may work in many situations but in others lwIP may not start.
- add
- in the project configuration (
Project -> Options for Target 'Target 1'), in theC/C++ (AC6)tab we've addedMisc Controls: -Wno-format-securityto silence a warning due to the way lwIP handles its logging macro, that we've just set to use printf
- in
lwIP integration
Add the proper libraries to the Run-Time Environment configuration; in the Run-Time Environment management window:
- for CMSIS Driver, used as Ethernet driver: select
CMSIS Driver -> Ethernet MAC (API) -> Ethernet MACandCMSIS Driver -> Ethernet PHY (API) -> LAN8742A(check the correct PHY for your hardware, this one is the one used on the Nucleo boards)
- for lwIP itself:
- set
NetworkVariant aslwIP - set
Network -> API - select
Network -> Coreand its Variant asIPv4(or another variant with IPv6 support if you wish) - select
Network -> RTOSand its Variant as your OS choice:CMSIS-RTOS2for any RTOS with the CMSIS-RTOS v2 API (including FreeRTOS), orFreeRTOSfor FreeRTOS native API - select
Network -> Driver-> Ethernetand its Variant asCMSIS Driver - select
Network -> Interface -> Ethernet
- set
- for CMSIS Driver, used as Ethernet driver: select
Then there are two config files we need to change according to our application:
- In
Network/ethif_config.h, using the Configuration Wizard, we can configure our MAC Address - In
Network/lwipopts.hlook for these macros and change them, or add those that do not exist, if any_#define MEMP_NUM_NETCONN10- we'll be using several connections simultaneously; even though we are using the socket interface, internally lwIP uses a decoupling API called netconn, so we need to set the number of allowed connections high enough#define LWIP_SOCKET1#define TCPIP_THREAD_STACKSIZE1024#define TCPIP_THREAD_PRIO- set toosPriorityNormalfor CMSIS-RTOS API and to(configMAX_PRIORITIES - 1)for FreeRTOS native API#define TCPIP_MBOX_SIZE6#define DEFAULT_THREAD_STACKSIZE1024#define DEFAULT_THREAD_PRIO- set toosPriorityNormalfor CMSIS-RTOS API and to(configMAX_PRIORITIES - 1)for FreeRTOS native API#define DEFAULT_RAW_RECVMBOX_SIZE6#define DEFAULT_UDP_RECVMBOX_SIZE6#define DEFAULT_TCP_RECVMBOX_SIZE6#define DEFAULT_ACCEPTMBOX_SIZE6#define LWIP_SOCKET1
- In
Finally, in the project configuration (
Project -> Options for Target 'Target 1'):- in the
C/C++ (AC6)tab we've addedMisc Controls: -Wno-implicit-int-conversionto silence a warning due to ethernetif.c having an uncasted conversion (this belongs to CMSIS-Driver) - for F7-based boards, in the
Linkertab we've addedMisc Controls: --diag_suppress 6918to silence a warning due to padding on a RAM region (this also belongs to CMSIS-Driver)
- in the
We didn't change any other default parameters, this is just an approach; for serious work and performance, a tuning operation might be needed.
Initialization
- Create an app_main task
- Initialize the network
- Create a task to poll for link changes and to serve the ethernetif (or two tasks if you prefer)
- Poll the IP address until it has a valid value
- Create the server task to run Mongoose, and terminate.
CMSIS-RTOS v2:
If using FreeRTOS, do not loop but exit on task termination:
FreeRTOS native API: