cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault occurs when initializing IwIP in NUCLEO-F429ZI.

Bhong.11
Associate

HardFault occurs when initializing IwIP in NUCLEO-F429ZI.

LwIP is being tested using STM Nucleo-F429ZI Board.

I am using STM32CudeIDE Version 1.6.1 and an error occurs in FreeRTOS environment.

IPv4 DCHP is not used and IP Address Setting has been made.

/**

 * LwIP initialization function

 */

void MX_LWIP_Init(void)

{

 /* IP addresses initialization */

 IP_ADDRESS[0] = 192;

 IP_ADDRESS[1] = 168;

 IP_ADDRESS[2] = 1;

 IP_ADDRESS[3] = 10;

 NETMASK_ADDRESS[0] = 255;

 NETMASK_ADDRESS[1] = 255;

 NETMASK_ADDRESS[2] = 255;

 NETMASK_ADDRESS[3] = 0;

 GATEWAY_ADDRESS[0] = 192;

 GATEWAY_ADDRESS[1] = 168;

 GATEWAY_ADDRESS[2] = 1;

 GATEWAY_ADDRESS[3] = 1;

 /* Initilialize the LwIP stack with RTOS */

 tcpip_init( NULL, NULL );

 /* 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) with RTOS */

 netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

 /* Registers the default network interface */

 netif_set_default(&gnetif);

 if (netif_is_link_up(&gnetif))

 {

  /* When the netif is fully configured this function must be called */

  netif_set_up(&gnetif);

 }

 else

 {

  /* When the netif link is down this function must be called */

  netif_set_down(&gnetif);

 }

/* USER CODE BEGIN 3 */

/* USER CODE END 3 */

}

Error Modules is

void udp_init(void)

{

#ifdef LWIP_RAND

 udp_port = UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());

#endif /* LWIP_RAND */

}

�?� 함수를 실행하면 HardFault_Handler()가 호출�?�니다.

void HardFault_Handler(void)

{

 /* USER CODE BEGIN HardFault_IRQn 0 */

 /* USER CODE END HardFault_IRQn 0 */

 while (1)

 {

  /* USER CODE BEGIN W1_HardFault_IRQn 0 */

  /* USER CODE END W1_HardFault_IRQn 0 */

 }

}

It doesn't go any further here. If it is a bug, please tell me how to fix it.

Thank you.

6 REPLIES 6

Have you tried debugging? Where does the hard fault occures?

Hello @Bhong.1​ ,

Could you please share your example zip for further check ?

Thanks in advance.

Walid.

bhong.1
Associate II

Error Line Debug

mX_LWIP_Init(void)

{

void MX_LWIP_Init(void)

{

 /* IP addresses initialization */

 IP_ADDRESS[0] = 192;

 IP_ADDRESS[1] = 168;

 IP_ADDRESS[2] = 0;

 IP_ADDRESS[3] = 81;

 NETMASK_ADDRESS[0] = 255;

 NETMASK_ADDRESS[1] = 255;

 NETMASK_ADDRESS[2] = 255;

 NETMASK_ADDRESS[3] = 0;

 GATEWAY_ADDRESS[0] = 192;

 GATEWAY_ADDRESS[1] = 168;

 GATEWAY_ADDRESS[2] = 0;

 GATEWAY_ADDRESS[3] = 254;

 /* Initilialize the LwIP stack with RTOS */

 tcpip_init( NULL, NULL ); -> Error This Line

tcpio.c file

tcpip_init(tcpip_init_done_fn initfunc, void *arg)

{

 lwip_init(); ---> Error This Line

 tcpip_init_done = initfunc;

 tcpip_init_done_arg = arg;

 if (sys_mbox_new(&tcpip_mbox, TCPIP_MBOX_SIZE) != ERR_OK) {

  LWIP_ASSERT("failed to create tcpip_thread mbox", 0);

 }

#if LWIP_TCPIP_CORE_LOCKING

 if (sys_mutex_new(&lock_tcpip_core) != ERR_OK) {

  LWIP_ASSERT("failed to create lock_tcpip_core", 0);

 }

#endif /* LWIP_TCPIP_CORE_LOCKING */

 sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);

}

lwip/src/core/init.c

void

lwip_init(void)

{

#ifndef LWIP_SKIP_CONST_CHECK

 int a = 0;

 LWIP_UNUSED_ARG(a);

 LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void *, &a) == &a);

#endif

#ifndef LWIP_SKIP_PACKING_CHECK

 LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE);

#endif

 /* Modules initialization */

 stats_init();

#if !NO_SYS

 sys_init();

#endif /* !NO_SYS */

 mem_init();

 memp_init();

 pbuf_init();

 netif_init();

#if LWIP_IPV4

 ip_init();

#if LWIP_ARP

 etharp_init();

#endif /* LWIP_ARP */

#endif /* LWIP_IPV4 */

#if LWIP_RAW

 raw_init();

#endif /* LWIP_RAW */

#if LWIP_UDP

 udp_init();

#endif /* LWIP_UDP */

#if LWIP_TCP

 tcp_init(); -> Error this point to

stm32f4xx_it.c file

void HardFault_Handler(void)

{

 /* USER CODE BEGIN HardFault_IRQn 0 */

 /* USER CODE END HardFault_IRQn 0 */

 while (1)

 {

  /* USER CODE BEGIN W1_HardFault_IRQn 0 */

  /* USER CODE END W1_HardFault_IRQn 0 */

 }

}

Have an effective Hard Fault Handler that can output actionable data so you can see the faulting instructions and registers

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bhong.1
Associate II

tcp_init(void)

{

#ifdef LWIP_RAND

 tcp_port = TCP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND()); -> Error This Line

#endif /* LWIP_RAND */

}

0693W00000DloWwQAJ.png Hardfault Like This..

Help me.

Leoq
Associate II

I am debugging an example from STM32H7-LwIP-Examples/STM32H745_Nucleo_M4_ETH at main · stm32-hotspot/STM32H7-LwIP-Examples · GitHub, However, it runs into HardFault_Handler at the following line in function udp_init: 

UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());

It crashes on the invocation of the "rand" function from stdlib !!!!!