Перейти к содержанию
    

FreeRTOS7.6.0+lwIP1.4.1+stm32f417

Добрый день.

Помогите пожалуйста разобраться с проблемой. Есть код:

 

uint8_t PTPService_Start(void)
{
 if(isRunning) {
   return PTP_ERR;
 }

 serviceMode = ePTP_NoInit;
 PTPService_Init();

 isTimeSet = 0;
 isRunning = 1;

 xTaskCreate(vPTPService_GnThread, (signed char *) "ptp", 2048, NULL, (tskIDLE_PRIORITY + 1UL), (xTaskHandle *) NULL);

 return PTP_OK;
}

static portTASK_FUNCTION(vPTPService_GnThread, pvParameters)
{
 struct netconn *pxPTPEventConn;
 struct netconn *pxPTPGeneralConn;
 struct netbuf *generalBuf;
 struct netbuf *eventBuf;  

 pxPTPGeneralConn = netconn_new(NETCONN_UDP);
 if(pxPTPGeneralConn == NULL) {
   while(1);
 }
 pxPTPEventConn = netconn_new(NETCONN_UDP);
 if(pxPTPEventConn == NULL) {
   while(1);
 }
 netconn_set_recvtimeout(pxPTPGeneralConn, 50);
 netconn_set_recvtimeout(pxPTPEventConn, 50);

 if(ERR_OK != netconn_join_leave_group(pxPTPGeneralConn, &ptpGroup, IP_ADDR_ANY, NETCONN_JOIN)) {
   while(1);
 }
 if(ERR_OK != netconn_join_leave_group(pxPTPEventConn, &ptpGroup, IP_ADDR_ANY, NETCONN_JOIN)) {
   while(1);
 }

 if(ERR_OK != netconn_bind(pxPTPEventConn, IP_ADDR_ANY, PTP_EVENT_PORT)) {
   while(1);
 }
 if(ERR_OK != netconn_bind(pxPTPGeneralConn, IP_ADDR_ANY, PTP_GENERAL_PORT)) {
   while(1);
 }

 while(isRunning) {

   if(netconn_recv(pxPTPGeneralConn, &generalBuf) == ERR_OK)
   {
     vLedCtl_Toggle(LED3);
     netbuf_delete(generalBuf);
   }

   if (netconn_recv(pxPTPEventConn, &eventBuf) == ERR_OK)
   {     
     vLedCtl_Toggle(LED2);
     netbuf_delete(eventBuf);
   }
 }

 netconn_join_leave_group(pxPTPGeneralConn, &ptpGroup, IP_ADDR_ANY, NETCONN_LEAVE);
 netconn_join_leave_group(pxPTPEventConn, &ptpGroup, IP_ADDR_ANY, NETCONN_LEAVE);
 netconn_delete(pxPTPGeneralConn);
 netconn_delete(pxPTPEventConn);
 /*  */
 vLedCtl_On(LED3);
 vLedCtl_On(LED4);
 vTaskDelete(NULL);
}

На ПК запущен ptpd, который отправляет multicast запросы. На 319 и 320 порты(PTP_EVENT_PORT и PTP_GENERAL_PORT соответственно).

В wireshark'e вижу, что на 319 порт идут Sync пакеты с периодичностью примерно раз в секунду. На 320 приходят Follow_up - раз в секунду, и Announce - раз в две секунды.

Проблема в том, что на stm32 стабильно доходят только Sync, то есть на 319 порт. На 320 порт пакеты приходят случайно, то есть их нет, а потом чудесным образом прилетает какой-то шальной пакет и снова тишина.

Если 319 порт не открывать, а оставить только 320, то ситуация меняется. Пакеты начинают приходить, но периодичность Follow_up не 1 секунда, а 2.

Изначально написал для каждого соединения свой Task, но ситуация такая же.

 

lwipopts.h

/**
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
* critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#define SYS_LIGHTWEIGHT_PROT    0

#define ETHARP_TRUST_IP_MAC     0
#define IP_REASSEMBLY           0
#define IP_FRAG                 0
#define ARP_QUEUEING            0
#define TCP_LISTEN_BACKLOG      1

/**
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
* use lwIP facilities.
*/
#define NO_SYS                  0

/* ---------- Memory options ---------- */
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
  lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
  byte alignment -> define MEM_ALIGNMENT to 2. */
#define MEM_ALIGNMENT           4

/* MEM_SIZE: the size of the heap memory. If the application will send
a lot of data that needs to be copied, this should be set high. */
#define MEM_SIZE                (20*1024)

/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
  sends a lot of data out of ROM (or other static memory), this
  should be set high. */
#define MEMP_NUM_PBUF           100
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
  per active UDP "connection". */
#define MEMP_NUM_UDP_PCB        10
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
  connections. */
#define MEMP_NUM_TCP_PCB        10
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
  connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 5
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
  segments. */
#define MEMP_NUM_TCP_SEG        20
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
  timeouts. */
#define MEMP_NUM_SYS_TIMEOUT    10


/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE          20

/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
#define PBUF_POOL_BUFSIZE       500


/* ---------- TCP options ---------- */
#define LWIP_TCP                1
#define TCP_TTL                 255

/* Controls if TCP should queue segments that arrive out of
  order. Define to 0 if your device is low on memory. */
#define TCP_QUEUE_OOSEQ         0

/* TCP Maximum segment size. */
#define TCP_MSS                 (1500 - 40)	  /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */

/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF             (2*TCP_MSS)

/*  TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
 as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */

#define TCP_SND_QUEUELEN        (4* TCP_SND_BUF/TCP_MSS)

/* TCP receive window. */
#define TCP_WND                 (2*TCP_MSS)


/*
  ----------------------------------
  ---------- IGMP options ----------
  ----------------------------------
*/
/**
* LWIP_IGMP==1: Turn on IGMP module.
*/
#define LWIP_IGMP                       1
#define LWIP_RAND()                    vRndGen_GetValue()

/* ---------- ICMP options ---------- */
#define LWIP_ICMP                       1


/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
  interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
  turning this on does currently not work. */
#define LWIP_DHCP               1

/* ---------- PTP options ---------- */
#define LWIP_PTP                1

/* ---------- UDP options ---------- */
#define LWIP_UDP                1
#define UDP_TTL                 255

/* ---------- Statistics options ---------- */
#define LWIP_STATS 0
#define LWIP_PROVIDE_ERRNO 1

/* ---------- link callback options ---------- */
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
* whenever the link changes (i.e., link down)
*/
#define LWIP_NETIF_LINK_CALLBACK        1

/*
  --------------------------------------
  ---------- Checksum options ----------
  --------------------------------------
*/

/*
The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
- To use this feature let the following define uncommented.
- To disable it and process by CPU comment the  the checksum.
*/
#define CHECKSUM_BY_HARDWARE


#ifdef CHECKSUM_BY_HARDWARE
 /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
 #define CHECKSUM_GEN_IP                 0
 /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
 #define CHECKSUM_GEN_UDP                0
 /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
 #define CHECKSUM_GEN_TCP                0
 /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
 #define CHECKSUM_CHECK_IP               0
 /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
 #define CHECKSUM_CHECK_UDP              0
 /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
 #define CHECKSUM_CHECK_TCP              0
 /* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
 #define CHECKSUM_GEN_ICMP               0
#else
 /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
 #define CHECKSUM_GEN_IP                 1
 /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
 #define CHECKSUM_GEN_UDP                1
 /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
 #define CHECKSUM_GEN_TCP                1
 /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
 #define CHECKSUM_CHECK_IP               1
 /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
 #define CHECKSUM_CHECK_UDP              1
 /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
 #define CHECKSUM_CHECK_TCP              1
 /* CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
 #define CHECKSUM_GEN_ICMP               1
#endif


/*
  ----------------------------------------------
  ---------- Sequential layer options ----------
  ----------------------------------------------
*/
/**
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
*/
#define LWIP_NETCONN                    1

/*
  ------------------------------------
  ---------- Socket options ----------
  ------------------------------------
*/
/**
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
*/
#define LWIP_SOCKET                     0

/*
  -----------------------------------
  ---------- DEBUG options ----------
  -----------------------------------
*/

#define LWIP_DEBUG                      0


/*
  ------------------------------------
  ---------- Socket options ----------
  ------------------------------------
*/

/**
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
* SO_RCVTIMEO processing.
*/
#ifndef LWIP_SO_RCVTIMEO
#define LWIP_SO_RCVTIMEO                1
#endif

/*
  ---------------------------------
  ---------- OS options ----------
  ---------------------------------
*/

#define TCPIP_THREAD_NAME              "TCP/IP"
#define TCPIP_THREAD_STACKSIZE          1000
#define TCPIP_MBOX_SIZE                 5
#define DEFAULT_UDP_RECVMBOX_SIZE       2000
#define DEFAULT_TCP_RECVMBOX_SIZE       2000
#define DEFAULT_ACCEPTMBOX_SIZE         2000
#define DEFAULT_THREAD_STACKSIZE        500
#define TCPIP_THREAD_PRIO               (configMAX_PRIORITIES - 3UL)
#define LWIP_COMPAT_MUTEX               1

FreeRTOSConfig.h

#define configUSE_PREEMPTION			1
#define configUSE_IDLE_HOOK			    0
#define configUSE_TICK_HOOK			    0
#define configCPU_CLOCK_HZ			    ( SystemCoreClock )
#define configTICK_RATE_HZ			    ( ( portTickType ) 250 )
#define configMAX_PRIORITIES			( ( unsigned portBASE_TYPE ) 8 )
#define configMINIMAL_STACK_SIZE		( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 40 * 1024 ) )
#define configMAX_TASK_NAME_LEN			( 10 )
#define configUSE_TRACE_FACILITY		1
#define configUSE_16_BIT_TICKS			0
#define configIDLE_SHOULD_YIELD			1
#define configUSE_MUTEXES			    1
#define configQUEUE_REGISTRY_SIZE		8
#define configCHECK_FOR_STACK_OVERFLOW	0
#define configUSE_RECURSIVE_MUTEXES		1
#define configUSE_MALLOC_FAILED_HOOK	0
#define configUSE_APPLICATION_TASK_TAG	0
#define configUSE_COUNTING_SEMAPHORES	1
#define configGENERATE_RUN_TIME_STATS	0

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

/* Software timer definitions. */
#define configUSE_TIMERS			    0
#define configTIMER_TASK_PRIORITY		( 2 )
#define configTIMER_QUEUE_LENGTH		10
#define configTIMER_TASK_STACK_DEPTH	( configMINIMAL_STACK_SIZE * 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			0
#define INCLUDE_vTaskDelayUntil			0
#define INCLUDE_vTaskDelay			    1

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

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }	

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler

Драйвер ethernet с сайта stm - stm32f4x7_eth.

Также заметил, что через некоторое время пакеты перестают доходить и на 319 порт, хотя на пинги устройство отвечает.

До этого работал с этим же железом и lwIp, но без FreeRTOS. Использовал raw/native API и никаких проблем не заметил.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

×
×
  • Создать...