Quantcast
Viewing all articles
Browse latest Browse all 4899

SDK • Re: Lockup in lwIP

I changed the code to not call low_level_input() of ENC29J60 driver from an ISR anymore. I now check the GPIO to see if there is an interrupt and call low_level_input() from the main loop. I assume pbuf_alloc() is (not configured to be) interrupt safe.

Before that change logs ended the following way:

Code:

pbuf_alloc(length=60)pbuf_alloc(length=60) == 20009400*** PANIC ***pbuf_free: p->ref > 0
This does not happen anymore but I still get a lockup. Now the log ends the following way:

Code:

pbuf_alloc(length=74)pbuf_alloc(length=74) == 200099ECpbuf_remove_header: old 200099FC new 20009A0A (14)pbuf_remove_header: old 20009A0A new 20009A1E (20)pbuf_remove_header: old 20009A1E new 20009A46 (40)pbuf_alloc(length=4)pbuf_alloc(length=4) == 20003824pbuf_add_header: old 2000386C new 20003858 (20)pbuf_add_header: old 20003858 new 20003844 (20)pbuf_add_header: old 20003844 new 20003836 (14)

PS:
I created a little script to analyze pbuf alloc/free in a logfile, just run ./pbuf-log-analyze.py file.log and it will create file.log.pbuf with additional info at the beginning of each line (OK, FF=first free, DF=double free, UF=unallocated free, NF=not freed at end of log):
https://martin.borg.ch/dev/pico/pbuf-log-analyze.py

And the code to process ENC interrupts in the main loop looks like this:

Code:

static void handle_enc29j60_irq(){uint8_t flags = enc28j60_interrupt_flags( &R.enc28j60 );if( flags & ENC28J60_PKTIF ){struct pbuf* packet = low_level_input( &R.netif );if( packet != NULL ){if( !queue_try_add( &R.rx_queue, &packet ) ){printf( "%d: call pbuf_free( %p )\r\n", __LINE__, packet );pbuf_free( packet );}}}if( flags & ENC28J60_TXERIF ){LWIP_DEBUGF( NETIF_DEBUG, ("eth_irq: transmit error\n") );}if( flags & ENC28J60_RXERIF ){LWIP_DEBUGF( NETIF_DEBUG, ("eth_irq: receive error\n") );}enc28j60_interrupt_clear( &R.enc28j60, flags );}static void mainloop(){while(true){if( !gpio_get( ETH_INT_PIN ) ){handle_enc29j60_irq();}// do other things here}}

Statistics: Posted by bw-a4ku — Mon Dec 30, 2024 3:42 am



Viewing all articles
Browse latest Browse all 4899

Trending Articles