Skip to content

Commit 2131f01

Browse files
htiboschActoryOu
andauthored
STM32H7xx driver check result of HAL_ETH_Init v3 (#1035)
* STM32H7xx driver check result of HAL_ETH_Init v3 * One more change to networkInterface.c * Updating FreeRTOS kernel submodule * Once again commit kernel --------- Co-authored-by: ActoryOu <[email protected]>
1 parent eac0d0c commit 2131f01

File tree

1 file changed

+132
-127
lines changed

1 file changed

+132
-127
lines changed

source/portable/NetworkInterface/STM32Hxx/NetworkInterface.c

Lines changed: 132 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
#endif
6666

6767
/* Interrupt events to process: reception, transmission and error handling. */
68-
#define EMAC_IF_RX_EVENT 1UL
69-
#define EMAC_IF_TX_EVENT 2UL
70-
#define EMAC_IF_ERR_EVENT 4UL
68+
#define EMAC_IF_RX_EVENT 1U
69+
#define EMAC_IF_TX_EVENT 2U
70+
#define EMAC_IF_ERR_EVENT 4U
7171

7272
/*
7373
* Enable either Hash or Perfect Filter, Multicast filter - None,
@@ -323,7 +323,7 @@ static uint8_t * pucGetRXBuffer( size_t uxSize )
323323

324324
static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface )
325325
{
326-
BaseType_t xResult;
326+
BaseType_t xResult = pdFAIL;
327327
NetworkEndPoint_t * pxEndPoint;
328328
HAL_StatusTypeDef xHalEthInitStatus;
329329
size_t uxIndex = 0;
@@ -353,156 +353,156 @@ static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInt
353353

354354
xHalEthInitStatus = HAL_ETH_Init( &( xEthHandle ) );
355355

356-
/* Only for inspection by debugger. */
357-
( void ) xHalEthInitStatus;
358-
359-
/* Update MAC filter settings */
360-
xEthHandle.Instance->MACPFR |= ENABLE_HASH_FILTER_SETTINGS;
361-
362-
/* Configuration for HAL_ETH_Transmit(_IT). */
363-
memset( &( xTxConfig ), 0, sizeof( ETH_TxPacketConfig ) );
364-
xTxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CRCPAD;
365-
366-
#if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != 0 )
356+
if( xHalEthInitStatus == HAL_OK )
367357
{
368-
/*xTxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC; */
369-
xTxConfig.Attributes |= ETH_TX_PACKETS_FEATURES_CSUM;
370-
xTxConfig.ChecksumCtrl = ETH_DMATXNDESCRF_CIC_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
371-
}
372-
#else
373-
{
374-
xTxConfig.ChecksumCtrl = ETH_CHECKSUM_DISABLE;
375-
}
376-
#endif
377-
xTxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
358+
/* Update MAC filter settings */
359+
xEthHandle.Instance->MACPFR |= ENABLE_HASH_FILTER_SETTINGS;
378360

379-
/* This counting semaphore will count the number of free TX DMA descriptors. */
380-
xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ETH_TX_DESC_CNT, ( UBaseType_t ) ETH_TX_DESC_CNT );
381-
configASSERT( xTXDescriptorSemaphore );
361+
/* Configuration for HAL_ETH_Transmit(_IT). */
362+
memset( &( xTxConfig ), 0, sizeof( ETH_TxPacketConfig ) );
363+
xTxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CRCPAD;
382364

383-
xTransmissionMutex = xSemaphoreCreateMutex();
384-
configASSERT( xTransmissionMutex );
385-
386-
/* Assign Rx memory buffers to a DMA Rx descriptor */
387-
for( uxIndex = 0; uxIndex < ETH_RX_DESC_CNT; uxIndex++ )
388-
{
389-
uint8_t * pucBuffer;
390-
391-
#if ( ipconfigZERO_COPY_RX_DRIVER != 0 )
365+
#if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != 0 )
392366
{
393-
pucBuffer = pucGetRXBuffer( ETH_RX_BUF_SIZE );
394-
configASSERT( pucBuffer != NULL );
367+
/*xTxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC; */
368+
xTxConfig.Attributes |= ETH_TX_PACKETS_FEATURES_CSUM;
369+
xTxConfig.ChecksumCtrl = ETH_DMATXNDESCRF_CIC_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
395370
}
396371
#else
397372
{
398-
pucBuffer = Rx_Buff[ uxIndex ];
373+
xTxConfig.ChecksumCtrl = ETH_CHECKSUM_DISABLE;
399374
}
400375
#endif
376+
xTxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
401377

402-
HAL_ETH_DescAssignMemory( &( xEthHandle ), uxIndex, pucBuffer, NULL );
403-
}
378+
/* This counting semaphore will count the number of free TX DMA descriptors. */
379+
xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ETH_TX_DESC_CNT, ( UBaseType_t ) ETH_TX_DESC_CNT );
380+
configASSERT( xTXDescriptorSemaphore );
404381

405-
#if ( ipconfigUSE_MDNS == 1 )
406-
{
407-
/* Program the MDNS address. */
408-
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xMDNS_MacAddress.ucBytes );
409-
}
410-
#endif
411-
#if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) )
412-
{
413-
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xMDNS_MacAddressIPv6.ucBytes );
414-
}
415-
#endif
416-
#if ( ipconfigUSE_LLMNR == 1 )
417-
{
418-
/* Program the LLMNR address. */
419-
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xLLMNR_MacAddress.ucBytes );
420-
}
421-
#endif
422-
#if ( ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_IPv6 != 0 ) )
423-
{
424-
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xLLMNR_MacAddressIPv6.ucBytes );
425-
}
426-
#endif
382+
xTransmissionMutex = xSemaphoreCreateMutex();
383+
configASSERT( xTransmissionMutex );
427384

428-
{
429-
/* The EMAC address of the first end-point has been registered in HAL_ETH_Init(). */
430-
for( ;
431-
pxEndPoint != NULL;
432-
pxEndPoint = FreeRTOS_NextEndPoint( pxMyInterface, pxEndPoint ) )
385+
/* Assign Rx memory buffers to a DMA Rx descriptor */
386+
for( uxIndex = 0; uxIndex < ETH_RX_DESC_CNT; uxIndex++ )
433387
{
434-
switch( pxEndPoint->bits.bIPv6 )
388+
uint8_t * pucBuffer;
389+
390+
#if ( ipconfigZERO_COPY_RX_DRIVER != 0 )
391+
{
392+
pucBuffer = pucGetRXBuffer( ETH_RX_BUF_SIZE );
393+
configASSERT( pucBuffer != NULL );
394+
}
395+
#else
435396
{
436-
#if ( ipconfigUSE_IPv4 != 0 )
437-
case pdFALSE_UNSIGNED:
397+
pucBuffer = Rx_Buff[ uxIndex ];
398+
}
399+
#endif
400+
401+
HAL_ETH_DescAssignMemory( &( xEthHandle ), uxIndex, pucBuffer, NULL );
402+
}
438403

439-
if( xEthHandle.Init.MACAddr != ( uint8_t * ) pxEndPoint->xMACAddress.ucBytes )
440-
{
441-
prvSetMAC_HashFilter( &xEthHandle, pxEndPoint->xMACAddress.ucBytes );
442-
}
404+
#if ( ipconfigUSE_MDNS == 1 )
405+
{
406+
/* Program the MDNS address. */
407+
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xMDNS_MacAddress.ucBytes );
408+
}
409+
#endif
410+
#if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) )
411+
{
412+
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xMDNS_MacAddressIPv6.ucBytes );
413+
}
414+
#endif
415+
#if ( ipconfigUSE_LLMNR == 1 )
416+
{
417+
/* Program the LLMNR address. */
418+
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xLLMNR_MacAddress.ucBytes );
419+
}
420+
#endif
421+
#if ( ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_IPv6 != 0 ) )
422+
{
423+
prvSetMAC_HashFilter( &xEthHandle, ( uint8_t * ) xLLMNR_MacAddressIPv6.ucBytes );
424+
}
425+
#endif
426+
427+
{
428+
/* The EMAC address of the first end-point has been registered in HAL_ETH_Init(). */
429+
for( ;
430+
pxEndPoint != NULL;
431+
pxEndPoint = FreeRTOS_NextEndPoint( pxMyInterface, pxEndPoint ) )
432+
{
433+
switch( pxEndPoint->bits.bIPv6 )
434+
{
435+
#if ( ipconfigUSE_IPv4 != 0 )
436+
case pdFALSE_UNSIGNED:
437+
438+
if( xEthHandle.Init.MACAddr != ( uint8_t * ) pxEndPoint->xMACAddress.ucBytes )
439+
{
440+
prvSetMAC_HashFilter( &xEthHandle, pxEndPoint->xMACAddress.ucBytes );
441+
}
442+
break;
443+
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
444+
445+
#if ( ipconfigUSE_IPv6 != 0 )
446+
case pdTRUE_UNSIGNED:
447+
{
448+
uint8_t ucMACAddress[ 6 ] = { 0x33, 0x33, 0xff, 0, 0, 0 };
449+
450+
ucMACAddress[ 3 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 13 ];
451+
ucMACAddress[ 4 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 14 ];
452+
ucMACAddress[ 5 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 15 ];
453+
454+
/* Allow traffic destined to Solicited-Node multicast address of this endpoint
455+
* for Duplicate Address Detection (DAD) */
456+
prvSetMAC_HashFilter( &xEthHandle, ucMACAddress );
457+
}
458+
break;
459+
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
460+
461+
default:
462+
/* MISRA 16.4 Compliance */
443463
break;
444-
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
445-
446-
#if ( ipconfigUSE_IPv6 != 0 )
447-
case pdTRUE_UNSIGNED:
448-
{
449-
uint8_t ucMACAddress[ 6 ] = { 0x33, 0x33, 0xff, 0, 0, 0 };
450-
451-
ucMACAddress[ 3 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 13 ];
452-
ucMACAddress[ 4 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 14 ];
453-
ucMACAddress[ 5 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 15 ];
454-
455-
/* Allow traffic destined to Solicited-Node multicast address of this endpoint
456-
* for Duplicate Address Detection (DAD) */
457-
prvSetMAC_HashFilter( &xEthHandle, ucMACAddress );
458-
}
459-
break;
460-
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
461-
462-
default:
463-
/* MISRA 16.4 Compliance */
464-
break;
464+
}
465465
}
466466
}
467-
}
468467

469-
#if ( ipconfigUSE_IPv6 != 0 )
470-
{
471-
/* Allow traffic destined to IPv6 all nodes multicast MAC 33:33:00:00:00:01 */
472-
const uint8_t ucMACAddress[ 6 ] = { 0x33, 0x33, 0, 0, 0, 0x01 };
473-
prvSetMAC_HashFilter( &xEthHandle, ucMACAddress );
474-
}
475-
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
468+
#if ( ipconfigUSE_IPv6 != 0 )
469+
{
470+
/* Allow traffic destined to IPv6 all nodes multicast MAC 33:33:00:00:00:01 */
471+
const uint8_t ucMACAddress[ 6 ] = { 0x33, 0x33, 0, 0, 0, 0x01 };
472+
prvSetMAC_HashFilter( &xEthHandle, ucMACAddress );
473+
}
474+
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
476475

477-
/* Initialize the MACB and set all PHY properties */
478-
prvMACBProbePhy();
476+
/* Initialize the MACB and set all PHY properties */
477+
prvMACBProbePhy();
479478

480-
/* Force a negotiation with the Switch or Router and wait for LS. */
481-
prvEthernetUpdateConfig( pdTRUE );
479+
/* Force a negotiation with the Switch or Router and wait for LS. */
480+
prvEthernetUpdateConfig( pdTRUE );
482481

483-
/* The deferred interrupt handler task is created at the highest
484-
* possible priority to ensure the interrupt handler can return directly
485-
* to it. The task's handle is stored in xEMACTaskHandle so interrupts can
486-
* notify the task when there is something to process. */
487-
if( xTaskCreate( prvEMACHandlerTask, niEMAC_HANDLER_TASK_NAME, niEMAC_HANDLER_TASK_STACK_SIZE, NULL, niEMAC_HANDLER_TASK_PRIORITY, &( xEMACTaskHandle ) ) == pdPASS )
488-
{
489-
/* The task was created successfully. */
490-
xMacInitStatus = eMACPass;
482+
/* The deferred interrupt handler task is created at the highest
483+
* possible priority to ensure the interrupt handler can return directly
484+
* to it. The task's handle is stored in xEMACTaskHandle so interrupts can
485+
* notify the task when there is something to process. */
486+
if( xTaskCreate( prvEMACHandlerTask, niEMAC_HANDLER_TASK_NAME, niEMAC_HANDLER_TASK_STACK_SIZE, NULL, niEMAC_HANDLER_TASK_PRIORITY, &( xEMACTaskHandle ) ) == pdPASS )
487+
{
488+
/* The task was created successfully. */
489+
xMacInitStatus = eMACPass;
490+
}
491+
else
492+
{
493+
xMacInitStatus = eMACFailed;
494+
}
491495
}
492496
else
493497
{
498+
/* HAL_ETH_Init() returned an error, the driver gets into a fatal error sate. */
494499
xMacInitStatus = eMACFailed;
495500
}
496501
} /* ( xMacInitStatus == eMACInit ) */
497502

498-
if( xMacInitStatus != eMACPass )
499-
{
500-
/* EMAC initialisation failed, return pdFAIL. */
501-
xResult = pdFAIL;
502-
}
503-
else
503+
if( xMacInitStatus == eMACPass )
504504
{
505-
if( xPhyObject.ulLinkStatusMask != 0uL )
505+
if( xPhyObject.ulLinkStatusMask != 0U )
506506
{
507507
xResult = pdPASS;
508508
FreeRTOS_printf( ( "Link Status is high\n" ) );
@@ -511,7 +511,6 @@ static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInt
511511
{
512512
/* For now pdFAIL will be returned. But prvEMACHandlerTask() is running
513513
* and it will keep on checking the PHY and set 'ulLinkStatusMask' when necessary. */
514-
xResult = pdFAIL;
515514
}
516515
}
517516

@@ -642,6 +641,12 @@ static BaseType_t xSTM32H_NetworkInterfaceOutput( NetworkInterface_t * pxInterfa
642641
{
643642
xResult = pdPASS;
644643
}
644+
else
645+
{
646+
/* As the transmission packet was not queued,
647+
* the counting semaphore should be given. */
648+
xSemaphoreGive( xTXDescriptorSemaphore );
649+
}
645650

646651
/* And release the mutex. */
647652
xSemaphoreGive( xTransmissionMutex );
@@ -1078,7 +1083,7 @@ static void prvEMACHandlerTask( void * pvParameters )
10781083
/* When sending a packet, all descriptors in the transmission channel may
10791084
* be occupied. In stat case, the program will wait (block) for the counting
10801085
* semaphore. */
1081-
const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( 100UL );
1086+
const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( 100U );
10821087

10831088
#if ( ipconfigHAS_PRINTF != 0 )
10841089
size_t uxTXDescriptorsUsed = 0U;
@@ -1161,7 +1166,7 @@ static void prvEMACHandlerTask( void * pvParameters )
11611166
xResult += prvNetworkInterfaceInput();
11621167
}
11631168

1164-
if( xPhyCheckLinkStatus( &xPhyObject, xResult ) != 0 )
1169+
if( xPhyCheckLinkStatus( &xPhyObject, xResult ) != pdFALSE )
11651170
{
11661171
/*
11671172
* The function xPhyCheckLinkStatus() returns pdTRUE if the

0 commit comments

Comments
 (0)