Skip to main content
taraben
Associate III
Jul 18, 2020 11:53 AM UTC
Question

STM32CubeMX lwip should generate USER section to allow customization of IP Address per device

STM32CubeMX lwip should generate USER section to allow customization of IP Address per device

currently I use CubeMX 5.6 and STM32F4 1.25

The IP address is specified in the ioc file. But when I have many boards it is not suitable to generate 1 project per board ...

For the MAC address there is such proposed solution in the file ethernetif.c implemented.

currently in the autogenerated lwip.c file the code lookes like this:

void MX_LWIP_Init(void)
{
/* IP addresses initialization */
IP_ADDRESS[0] = 192;
IP_ADDRESS[1] = 168;
IP_ADDRESS[2] = 123;
IP_ADDRESS[3] = 3;
NETMASK_ADDRESS[0] = 255;
NETMASK_ADDRESS[1] = 255;
NETMASK_ADDRESS[2] = 255;
NETMASK_ADDRESS[3] = 0;
GATEWAY_ADDRESS[0] = 0;
GATEWAY_ADDRESS[1] = 0;
GATEWAY_ADDRESS[2] = 0;
GATEWAY_ADDRESS[3] = 0;
 
/* Initilialize the LwIP stack without RTOS */
lwip_init();
 
/* IP addresses initialization without DHCP (IPv4) */
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);
 
/* add the network interface (IPv4/IPv6) without RTOS */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
 
/* Registers the default network interface */
netif_set_default(&gnetif);

So for the instance there should be a possible USER SECTION after variable assignment and any function call.

like this:

void MX_LWIP_Init(void)
{
/* IP addresses initialization */
IP_ADDRESS[0] = 192;
IP_ADDRESS[1] = 168;
IP_ADDRESS[2] = 123;
IP_ADDRESS[3] = 3;
NETMASK_ADDRESS[0] = 255;
NETMASK_ADDRESS[1] = 255;
NETMASK_ADDRESS[2] = 255;
NETMASK_ADDRESS[3] = 0;
GATEWAY_ADDRESS[0] = 0;
GATEWAY_ADDRESS[1] = 0;
GATEWAY_ADDRESS[2] = 0;
GATEWAY_ADDRESS[3] = 0;
 
/* USER CODE END IPADDRESS /
/ USER CODE END IPADDRESS */
 
/* Initilialize the LwIP stack without RTOS */
lwip_init();
 
...

Currently I have to patch after every project generation. Again and again.

Thanks ST for providing those changes in next release.

Adib.

--

This topic has been closed for replies.

2 replies

Khouloud ZEMMELI
ST Employee
Jul 20, 2020 7:52 AM UTC

​hello @taraben​ ,

Thanks for your feedback, it will be internally checked.

Best Regards,

Khouloud

Khouloud ZEMMELI
ST Employee
Aug 31, 2020 2:41 PM UTC

Done, your request will be available for the next release.

Best Regards,

Khouloud