diff --git a/source/portable/NetworkInterface/STM32Hxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32Hxx/NetworkInterface.c index 7105ca26a4..6e319a0210 100644 --- a/source/portable/NetworkInterface/STM32Hxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32Hxx/NetworkInterface.c @@ -203,6 +203,36 @@ const PhyProperties_t xPHYProperties = }; /*-----------------------------------------------------------*/ +static void prvMACAddressConfig( ETH_HandleTypeDef * heth, + uint32_t ulIndex, + const uint8_t * Addr ) +{ + uint32_t ulTempReg; + uint32_t ulETH_MAC_ADDR_HBASE = ( uint32_t ) &( heth->Instance->MACA0HR ); + uint32_t ulETH_MAC_ADDR_LBASE = ( uint32_t ) &( heth->Instance->MACA0LR ); + + /* ETH_MAC_ADDRESS0 reserved for the primary MAC-address. */ + configASSERT( ulIndex >= ETH_MAC_ADDRESS1 ); + + /* STM32Hxx devices support 4 MAC address registers + * (ETH_MAC_ADDRESS0 - ETH_MAC_ADDRESS3), make sure ulIndex is not + * more than that. */ + configASSERT( ulIndex <= ETH_MAC_ADDRESS3 ); + + /* Calculate the selected MAC address high register. */ + ulTempReg = 0xBF000000ul | ( ( uint32_t ) Addr[ 5 ] << 8 ) | ( uint32_t ) Addr[ 4 ]; + + /* Load the selected MAC address high register. */ + ( *( __IO uint32_t * ) ( ( uint32_t ) ( ulETH_MAC_ADDR_HBASE + ulIndex ) ) ) = ulTempReg; + + /* Calculate the selected MAC address low register. */ + ulTempReg = ( ( uint32_t ) Addr[ 3 ] << 24 ) | ( ( uint32_t ) Addr[ 2 ] << 16 ) | ( ( uint32_t ) Addr[ 1 ] << 8 ) | Addr[ 0 ]; + + /* Load the selected MAC address low register */ + ( *( __IO uint32_t * ) ( ( uint32_t ) ( ulETH_MAC_ADDR_LBASE + ulIndex ) ) ) = ulTempReg; +} + +/*-----------------------------------------------------------*/ /******************************************************************************* @@ -232,6 +262,7 @@ static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInt NetworkEndPoint_t * pxEndPoint; HAL_StatusTypeDef xHalEthInitStatus; size_t uxIndex = 0; + BaseType_t xMACEntry = ETH_MAC_ADDRESS1; /* ETH_MAC_ADDRESS0 reserved for the primary MAC-address. */ if( xMacInitStatus == eMACInit ) { @@ -304,6 +335,95 @@ static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInt HAL_ETH_DescAssignMemory( &( xEthHandle ), uxIndex, pucBuffer, NULL ); } + #if ( ipconfigUSE_MDNS == 1 ) + { + /* Program the MDNS address. */ + prvMACAddressConfig( &xEthHandle, xMACEntry, ( uint8_t * ) xMDNS_MacAdress.ucBytes ); + xMACEntry += 8; + } + #endif + #if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) ) + { + prvMACAddressConfig( &xEthHandle, xMACEntry, ( uint8_t * ) xMDNS_MACAdressIPv6.ucBytes ); + xMACEntry += 8; + } + #endif + #if ( ipconfigUSE_LLMNR == 1 ) + { + /* Program the LLMNR address. */ + prvMACAddressConfig( &xEthHandle, xMACEntry, ( uint8_t * ) xLLMNR_MacAdress.ucBytes ); + xMACEntry += 8; + } + #endif + #if ( ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_IPv6 != 0 ) ) + { + prvMACAddressConfig( &xEthHandle, xMACEntry, ( uint8_t * ) xLLMNR_MacAdressIPv6.ucBytes ); + xMACEntry += 8; + } + #endif + + { + /* The EMAC address of the first end-point has been registered in HAL_ETH_Init(). */ + for( ; + pxEndPoint != NULL; + pxEndPoint = FreeRTOS_NextEndPoint( pxMyInterface, pxEndPoint ) ) + { + switch( pxEndPoint->bits.bIPv6 ) + { + #if ( ipconfigUSE_IPv4 != 0 ) + case pdFALSE_UNSIGNED: + + if( xEthHandle.Init.MACAddr != ( uint8_t * ) pxEndPoint->xMACAddress.ucBytes ) + { + prvMACAddressConfig( &xEthHandle, xMACEntry, pxEndPoint->xMACAddress.ucBytes ); + xMACEntry += 8; + } + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + + #if ( ipconfigUSE_IPv6 != 0 ) + case pdTRUE_UNSIGNED: + { + uint8_t ucMACAddress[ 6 ] = { 0x33, 0x33, 0xff, 0, 0, 0 }; + + ucMACAddress[ 3 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 13 ]; + ucMACAddress[ 4 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 14 ]; + ucMACAddress[ 5 ] = pxEndPoint->ipv6_settings.xIPAddress.ucBytes[ 15 ]; + + /* Allow traffic destined to Solicited-Node multicast address of this endpoint + * for Duplicate Address Detection (DAD) */ + prvMACAddressConfig( &xEthHandle, xMACEntry, ucMACAddress ); + xMACEntry += 8; + } + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: + /* MISRA 16.4 Compliance */ + break; + } + + if( xMACEntry > ( BaseType_t ) ETH_MAC_ADDRESS3 ) + { + /* No more locations available. */ + break; + } + } + } + + #if ( ipconfigUSE_IPv6 != 0 ) + { + if( xMACEntry <= ( BaseType_t ) ETH_MAC_ADDRESS3 ) + { + /* Allow traffic destined to IPv6 all nodes multicast MAC 33:33:00:00:00:01 */ + uint8_t ucMACAddress[ 6 ] = { 0x33, 0x33, 0, 0, 0, 0x01 }; + + prvMACAddressConfig( &xEthHandle, xMACEntry, ucMACAddress ); + xMACEntry += 8; + } + } + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + /* Initialize the MACB and set all PHY properties */ prvMACBProbePhy(); @@ -412,7 +532,7 @@ static BaseType_t xSTM32H_NetworkInterfaceOutput( NetworkInterface_t * pxInterfa TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 100U ); uint8_t * pucTXBuffer; - if( xGetPhyLinkStatus( pxInterface ) == = pdPASS ) + if( xSTM32H_GetPhyLinkStatus( pxInterface ) == pdPASS ) { #if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) /* Zero-copy method, pass the buffer. */ @@ -870,8 +990,6 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB } /*-----------------------------------------------------------*/ -#define __NOP() __ASM volatile ( "nop" ) - static void vClearOptionBit( volatile uint32_t * pulValue, uint32_t ulValue ) { @@ -994,7 +1112,7 @@ static void prvEMACHandlerTask( void * pvParameters ) * The function xPhyCheckLinkStatus() returns pdTRUE if the * Link Status has changes since it was called the last time. */ - if( xGetPhyLinkStatus( pxMyInterface ) == pdFALSE ) + if( xSTM32H_GetPhyLinkStatus( pxMyInterface ) == pdFALSE ) { /* Stop the DMA transfer. */ HAL_ETH_Stop_IT( &( xEthHandle ) );