lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] LwIP doesn't receive messages after a while


From: Noam Weissman
Subject: Re: [lwip-users] LwIP doesn't receive messages after a while
Date: Sun, 27 Mar 2016 13:43:09 +0000

Hi Andrea,

Can you send me your code to see, or at the minimum send me your  
FreeRTOSConfig.h + lwipopts.h

I have never worked with the auto created cube code. I work with my own 
settings, the old school :-)

It can either be problems with driver code, config file settings or wrong usage 
of LwIP.

If you work with LwIP in RAW mode you have to be very careful to use the code 
only from within 
The TCP context or add protection.

*******************
One important lesson I learned, the hard way... FreeRTOS has functions to be 
used from within interrupts.
For example xQueueSendToBackFromISR compared with xQueueSendToBack !!

All the NONE ISR functions have critical sections in them. That means when the 
OS needs to do something that
Is dangerous or needs synchronization with data changed inside ISR function it 
will block interrupts.

The Cortex-M has a priority level that is somewhat complicated to understand 
from first look.
If you set your ISR level to be higher than the 
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
You can get unpredictable results.

I had stability problems and found that the hard way !!!!!.


Her is the average FreeRTOSConfig I normally use. This is the compilation 
result of numerus sources I found
and my own changes. This  config file is used for STM32F4xx  :

---------------------------------------------------------------------------------------------------------

#define configUSE_PREEMPTION              1
#define configUSE_IDLE_HOOK           0
#define configUSE_TICK_HOOK           0
#define configCPU_CLOCK_HZ        ( ( unsigned long ) 168000000 )       
#define configTICK_RATE_HZ            ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES              ( ( unsigned portBASE_TYPE ) 20 )
#define configMINIMAL_STACK_SIZE        ( ( unsigned short ) 200 )
#define configTOTAL_HEAP_SIZE             ( ( size_t ) (60 * 1024 ) )
#define configMAX_TASK_NAME_LEN         ( 20 )
#define configUSE_TRACE_FACILITY        0
#define configUSE_16_BIT_TICKS          0
#define configIDLE_SHOULD_YIELD         1
#define configUSE_MUTEXES               1
#define configUSE_COUNTING_SEMAPHORES   1
#define configUSE_MALLOC_FAILED_HOOK    0

#define configUSE_RECURSIVE_MUTEXES 0


#define configUSE_TIMERS                  1
#define configTIMER_QUEUE_LENGTH      20
#define configTIMER_TASK_STACK_DEPTH  configMINIMAL_STACK_SIZE
#define configTIMER_TASK_PRIORITY     ( tskIDLE_PRIORITY + 4 )

// for plugin
//#define configQUEUE_REGISTRY_SIZE 6

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES           0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet                  1
#define INCLUDE_uxTaskPriorityGet                 1
#define INCLUDE_vTaskDelete                           1
#define INCLUDE_vTaskCleanUpResources   0
#define INCLUDE_vTaskSuspend                        1
#define INCLUDE_vTaskDelayUntil                   0
#define INCLUDE_vTaskDelay                      1
#define INCLUDE_xTaskGetCurrentTaskHandle 1




/*The table below gives the allowed values of the pre-emption priority and 
subpriority according
  *  to the Priority Grouping configuration performed by 
NVIC_PriorityGroupConfig function
  *    
==========================================================================================================================
  *      NVIC_PriorityGroup   | NVIC_IRQChannelPreemptionPriority | 
NVIC_IRQChannelSubPriority  |       Description
  *    
==========================================================================================================================
  *     NVIC_PriorityGroup_0  |                0                  |            
0-15             | 0 bits for pre-emption priority
  *                           |                                   |             
                | 4 bits for subpriority
  *    
--------------------------------------------------------------------------------------------------------------------------
  *     NVIC_PriorityGroup_1  |                0-1                |            
0-7              | 1 bits for pre-emption priority
  *                           |                                   |             
                | 3 bits for subpriority
  *    
--------------------------------------------------------------------------------------------------------------------------
    
  *     NVIC_PriorityGroup_2  |                0-3                |            
0-3              | 2 bits for pre-emption priority
  *                           |                                   |             
                | 2 bits for subpriority
  *    
--------------------------------------------------------------------------------------------------------------------------
    
  *     NVIC_PriorityGroup_3  |                0-7                |            
0-1              | 3 bits for pre-emption priority
  *                           |                                   |             
                | 1 bits for subpriority
  *    
--------------------------------------------------------------------------------------------------------------------------
    
  *     NVIC_PriorityGroup_4  |                0-15               |            
0                | 4 bits for pre-emption priority
  *                           |                                   |             
                | 0 bits for subpriority                       
  *    
==========================================================================================================================
 
*/

#define IRQ_SYS_PRIORITY_MODEL  NVIC_PriorityGroup_4

/* 8 bit of MSB is priority, 8 bit of LSB is SUBpriority */
//                         priority | sub-priority
#define AUDIO_DSP_ER_IT_PRIORITY    0x0000//i2c
#define AUDIO_DSP_EV_IT_PRIORITY   0x0000 //i2c
#define SII_UART_IT_PRIORITY   0x0100 //uart
#define FP_UART_IT_PRIORITY   0x0100 //uart
#define IR_FPGA_SPI_PRIORITY  0x0300 //spi
#define IRQ_FPGA_EVENT_PRIOR  0x0B00
#define IR_IRQ_PRIORITY       0x0300

/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
        /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
        #define configPRIO_BITS                 __NVIC_PRIO_BITS
#else
        #define configPRIO_BITS                 4        /* 15 priority levels 
*/
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY                 0xF

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY    5

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY                 ( 
configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    ( 
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )


#define ADC3_DMA_ISR_PRIO      (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 
6)
#define ETH_ISR_PRIO           (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 
5)
#define IR_TIMERS_ISR_PRIO     (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 
2)
#define SERIAL_ISR_PRIO        (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 
1)

-----------------------------------------------------------------------------------------------------------

If you use I2C and it should not be interrupted by the OS use the highest 
interrupt priority for it.
as for TCP, RS232 etc... interrupted priorities MUST be lower than 
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY

Lower means a higher number. That is the reason for +1 or other

Hope that helped :-)


BR,
Noam.


-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Andrea Toscan
Sent: Friday, March 25, 2016 7:41 PM
To: address@hidden
Subject: [lwip-users] LwIP doesn't receive messages after a while

Hallo,
I'm developing on a board based on STM32F407 and FreeRTOS, FatFS, and LwIP. The 
code is generated by Cube 4.13.

The problem is that during a test with a continuous ping (-f) the board doesn't 
receive messages after a while. Some times it is possible to have a default 
header interrupt due to a illegal access memory done by alloc or free mempool 
functions.

In my opinion it is a matter of LwIP configuration, but I don't understand 
exactly what.
Have you got some suggestions?

Thanks.

--
Ing. Andrea Toscan, Project Leader
Bluewind Embedded System Design

mobile: +39 338 5324872
telephone (Bluewind): +39 0423 723431
telephone (direct): +39 0423 744742
e-mail: address@hidden
skype: andrea.toscan.bluewind
it.linkedin.com/in/andreatoscan


Address:
via Della Borsa, 16/A int.5
31033 Castelfranco Veneto
Treviso - Italy

www.bluewind.it



_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users



reply via email to

[Prev in Thread] Current Thread [Next in Thread]