Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

AT91SAM7x IAR LWIP problem

Posted by pbeamtn on October 28, 2008
I'v been working on porting LWIP to FreeRTOS for the AT91SAM7x with IAR EWARM 5.1. I now have it compiling fine, but LWIP seems to "run away" whenever it receives a packet. For example, if I send it an ARP request, it continues to send ARP responses. It seems to not clear the old receive buffer, so it interprets the buffer over and over as a new packet.

The offending code seems to be in ethernetif.c:

for( ;; )
{
do
{
ethernetif = xNetIf->state;

/* move received packet into a new pbuf */
p = low_level_input( xNetIf );

if( p == NULL )
{
/* No packet could be read. Wait a for an interrupt to tell us
there is more data available. */
vEMACWaitForInput();
}

} while( p == NULL );

vEMACWaitForInput() is only run if low_level_input() returns null. I don't fully understand what low_level_input() does, but it calls ulEMACInputLength() which always returns a length even if a new packet has not been received.

I don't understand the initial do loop, since it seems to me you would want to do vEMACWaitForInput() and then process what was received instead of trying to receive and only calling vEMACWaitForInput() if that "fails" -- which it never does for me after I receive the first packet.

I am hesitant to start changing this code since it seems to work for someone. This is the stock Rowley AT91SAM7x logic in the demo distribution. If someone can explain how this is supposed to work and how it determines whether the data is the buffer is new or not, I would certainly appreciate it.




RE: AT91SAM7x IAR LWIP problem

Posted by Richard on October 29, 2008
I would have to read the data sheet again to remember exactly, but from memory....

Each descriptor has an 'ownership' bit that says whether the buffer is owned by the software or hardware. When it is owned by the hardware the MAC peripheral can write data into the buffer pointed to by the descriptor, when it is owned by the software the buffer already contains data that has not yet been processed.

The software maintains an index that indicates which descriptor it is going to read next. When it reads data from a descriptor it has to first set (or maybe clear) the ownership bit to pass the buffer back to the hardware, and increment the index so it knows which buffer to read next.

It sounds like your setup if failing to do one or other of these.

Regards.

RE: AT91SAM7x IAR LWIP problem

Posted by pbeamtn on October 29, 2008
I think I know more about what is going on, but I'm not yet sure how to fix it.

I had to set ETH_PAD_SIZE to 2 to get data aligned properly -- otherwise, I get data aborts on address checks. This increases the len returned by ulEMACInputLength() by 2. This adversely affects vEMACRead() such that the ownership bit is never reset -- ulSectionLength is 60 but ulTotalFrameLength is 62 in my case. It would seem that the length I need to read should be reduced by ETH_PAD_SIZE.

RE: AT91SAM7x IAR LWIP problem

Posted by pbeamtn on October 29, 2008
This is what I had to do to get the demo project to at least respond to pings:

In ethernetif.c, I modified low_level_input() to look like this:

if( xSemaphoreTake( xRxSemaphore, netifGUARD_BLOCK_TIME ) )
{
/* Obtain the size of the packet. */
len = ulEMACInputLength();

if( len )
{
//#if ETH_PAD_SIZE
//len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
//#endif

/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc( PBUF_RAW, len + ETH_PAD_SIZE, PBUF_POOL );


Instead of modifying len by adding the size of ETH_PAD_SIZE, I leave it alone and just allocate len + ETH_PAD_SIZE.

I don't have Rowley CrossStudio to see how the stock demo works, but it worries me to make this kind of change just to convert to IAR.

If someone wants the IAR/lwip AT91SAM7 project I'm working on, then let me know -- pbeam at windrock dot com. I would love to have another set of eyes look at what I did to get this to work.


RE: AT91SAM7x IAR LWIP problem

Posted by Jon Newcomb on March 1, 2010
Bringing up this thread again, has anyone out there successfully ported lwIP to FreeRTOS using the IAR Embedded Workbench?
I guess I’m looking for a kind of BSP for the AT91SAM7X-EK that I can use as a starting point..
(Already looked at IAR uIP and lwIP GCC demos.. Also worth noting that the Atmel software pack includes ‘basic-emac-lwip-project’ – but it is again, only for GCC)
Thanks;
arm at jnewcomb d_o_t com


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists