5.10 ETH

This chapter covers how the N32H49x ETH peripheral (with the lwIP 2.2.0 stack) is organized in the development kit, its public API and its examples.

5.10.1 Related files

The table lists the header, the driver implementation, the example root and the layout of one example.

Relative path Purpose
firmware/n32h49x_std_periph_driver/inc/n32h49x_eth.h Register definitions, data types and public function declarations of the ETH peripheral.
firmware/n32h49x_std_periph_driver/src/n32h49x_eth.c ETH driver implementation: initialization, descriptors and DMA transfer, status and interrupt queries.
middlewares/lwip-2.2.0/ The lwIP 2.2.0 stack that provides the IP, TCP and UDP interfaces used by the examples.
middlewares/FreeRTOSv202212.01/ The FreeRTOS kernel used by the examples that run an operating system.
projects/n32h49x_EVAL/examples/ETH/ All 12 examples: HTTP_Client, HTTP_Server, iPerf_Netconn, iPerf_Socket, NetBIOS, PING, TCP_Client, TCP_Client_RAW, TCP_Server, TCP_Server_RAW, UDP, UDP_RAW.
projects/n32h49x_EVAL/examples/ETH/PING/ Directory layout of the OS-free examples: src/ sources, inc/ headers, bsp/ lwIP adaptation layer, and the MDK-ARM/ and EWARM/ projects.

5.10.2 API reference

Search API126 functions

The 126 public functions are grouped into 12 blocks in the declaration order of n32h49x_eth.h; each entry gives a summary and the original source comment.

Initialization and reset

ETH_DeInit, ETH_StructInit, ETH_ExternalPHYInit, ETH_Init, ETH_SoftwareReset, ETH_CSRRegisterWrite1ClearCmd

PHY and MDC clock

ETH_ConfigMDCNormalClock, ETH_ConfigMDCFastClock, ETH_ReadPHYRegister, ETH_WritePHYRegister

MAC enable, address and filter

ETH_TxMACCmd, ETH_RxMACCmd, ETH_SetMACAddress, ETH_GetMACAddress, ETH_SetHashTable, ETH_MACAddressPerfectFilterCmd, ETH_SetMACAddressFilter, ETH_SetMACAddressFilterMaskBytes

VLAN tag

ETH_RxVLANTagStructInit, ETH_RxVLANTagInit, ETH_SetVLANHashTable, ETH_SetRxVLANIdentifier

Flow control and low-power wake-up

ETH_InitiatePauseControlPacket, ETH_ActivateBackpressure, ETH_PowerDownCmd, ETH_MagicPacketDetectionCmd, ETH_WakeUpPacketDetectionCmd, ETH_GlobalUnicastWakeUpCmd, ETH_ResetWakeUpPacketFilterRegPointer, ETH_SetWakeUpPacketFilterRegister, ETH_GetFlowControlBusyStatus, ETH_GetPMTFlagStatus

MMC statistics

ETH_MMCCountersReset, ETH_MMCCounterStopRolloverCmd, ETH_MMCResetOnReadCmd, ETH_MMCCounterFreezeCmd, ETH_MMCCounterHalfPreset, ETH_MMCCounterFullPreset, ETH_MMCCounterUpdateForDropBCPacketCmd, ETH_GetMMCCounterValue

Time stamp and PPS

ETH_MACTimeStampCmd, ETH_SetTimeStampUpdateMethod, ETH_MACTimeStampInit, ETH_MACTimeStampUpdate, ETH_EnableTimeStampIntTrigger, ETH_MACTimeStampAddendRegUpdate, ETH_MACTimeStampAllPacketsCmd, ETH_MACTimeStampDigBinRolloverCmd, ETH_PTPTypePacketProcesCmd, ETH_MACAddrPTPPacketFilterCmd, ETH_MACTxTimeStampStatusModeCmd, ETH_SetSubSecondIncrementValue, ETH_SetTimeStampUpdateValue, ETH_SetTimeStampAddendValue, ETH_GetTimeStampRegValue, ETH_ConfigPPSOutput, ETH_SetPPSTargetTimeValue

MTL queue management

ETH_MTLDropTxStatusCmd, ETH_MTLCounterPreset, ETH_MTLCounterReset, ETH_FlushTransmitQueue, ETH_GetMTLUnderflowPacketCounter, ETH_GetMTLOverflowPacketCounter, ETH_GetMTLMissedPacketCounter

DMA descriptors and transfer

ETH_DMATxDescListInit, ETH_DMARxDescListInit, ETH_RxDescAssignMemory, ETH_BuildRxDescriptors, ETH_PrepareTxDescriptors, ETH_Transmit, ETH_TransmitIT, ETH_IsRxDataAvailable, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_GetRxPacketInfo, ETH_TxDMACmd, ETH_RxDMACmd, ETH_ResumeDMATransmission, ETH_ResumeDMAReception, ETH_Start, ETH_StartIT, ETH_Stop, ETH_StopIT, ETH_SetRxInterruptWatchdogTimer, ETH_GetTxDescFlagStatus

DMA status and queries

ETH_GetCurrentTxDescriptorAddress, ETH_GetCurrentRxDescriptorAddress, ETH_GetCurrentTxBufferAddress, ETH_GetCurrentRxBufferAddress, ETH_GetTxDMAErrorType, ETH_GetRxDMAErrorType, ETH_GetDMACh0DroppedPacketCounter, ETH_GetDMACh0ERICounter, ETH_GetDMACh0TxProcessStatus, ETH_GetDMACh0RxProcessStatus, ETH_GetDMACh0FlagStatus, ETH_GetDMAInterruptStatus, ETH_GetFlushTransmitQueueStatus

Status and interrupt flag queries

ETH_GetRxDescExtendedFlagStatus, ETH_GetRxDescFilterFlagStatus, ETH_GetRxDescFlagStatus, ETH_GetMACInterruptStatus, ETH_GetMACTxRxFlagStatus, ETH_GetMMCRxInterruptStatus, ETH_GetMMCTxInterruptStatus, ETH_GetMACTimeStampFlagStatus, ETH_GetMTLInterruptStatus, ETH_GetMTLQueueInterruptStatus, ETH_GetMTLCounterFlagStatus, ETH_GetSoftwareResetStatus, ETH_GetDMACh0InterruptStatus

Interrupt flag clear and enable

ETH_ClearMACPHYInterruptFlag, ETH_ClearPMTFlag, ETH_ClearMMCRxInterruptFlag, ETH_ClearMMCTxInterruptFlag, ETH_ClearMACTimeStampFlag, ETH_ClearMACTxRxFlag, ETH_ClearMACMDIOInterruptFlag, ETH_ClearMTLQueueInterruptFlag, ETH_ClearDMACh0Flag, ETH_ClearDMACh0InterruptFlag, ETH_ConfigMACInterrupt, ETH_ConfigMMCRxInterrupt, ETH_ConfigMMCTxInterrupt, ETH_ConfigMTLQueueInterrupt, ETH_ConfigDMACh0Interrupt

void ETH_DeInit(ETH_Module* ETHx)DeInitializes the ETH peripheral.
Source comment
name    ETH_DeInit.
fun     DeInitializes the ETH peripheral.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_StructInit(ETH_InitType* ETH_InitParam)Initializes the structure parameter of type ETH_InitType used to initialize ETH. This function is usually called before initializing a parameter of type ETH_InitType.
Source comment
name    ETH_StructInit.
fun     Initializes the structure parameter of type ETH_InitType used to
        initialize ETH. This function is usually called before initializing
        a parameter of type ETH_InitType.
param   ETH_InitParam :
          - Pointer to the ETH_InitType structure which will be initialized.
return  none
void ETH_DMATxDescListInit(ETH_Module* ETHx, ETH_InfoType* pInfo)Initialize the ETH DMA transmit descriptor.
Source comment
name    ETH_DMATxDescListInit.
fun     Initialize the ETH DMA transmit descriptor.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  none
void ETH_DMARxDescListInit(ETH_Module* ETHx, ETH_InfoType* pInfo)Initialize the ETH DMA Receive descriptor.
Source comment
name    ETH_DMARxDescListInit.
fun     Initialize the ETH DMA Receive descriptor.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  none
void ETH_ConfigMDCNormalClock(ETH_Module* ETHx)Configure the normal clock frequency (1.0MHz ≤ MDC clock ≤ 2.5MHz) of the MDC based on the CSR clock frequency(HclkFreq),
Source comment
name    ETH_ConfigMDCNormalClock.
fun     Configure the normal clock frequency (1.0MHz ≤ MDC clock ≤ 2.5MHz) of the
        MDC based on the CSR clock frequency(HclkFreq),
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_ConfigMDCFastClock(ETH_Module* ETHx, uint32_t DivValue)Configure the fast clock frequency (MDC clock > 2.5MHz) of the MDC based on the CSR clock frequency(HclkFreq),
Source comment
name    ETH_ConfigMDCFastClock.
fun     Configure the fast clock frequency (MDC clock > 2.5MHz) of the MDC based
        on the CSR clock frequency(HclkFreq),
param   ETHx (The input parameters must be the following values):
          - ETH
param   DivValue (The input parameters must be the following values):
          - ETH_MDCFCLK_CRSCLK_DIV4
          - ETH_MDCFCLK_CRSCLK_DIV6
          - ETH_MDCFCLK_CRSCLK_DIV8
          - ETH_MDCFCLK_CRSCLK_DIV10
          - ETH_MDCFCLK_CRSCLK_DIV12
          - ETH_MDCFCLK_CRSCLK_DIV14
          - ETH_MDCFCLK_CRSCLK_DIV16
          - ETH_MDCFCLK_CRSCLK_DIV18
return  none
note    Configure for fast clocks is only supported if the interface chip supports
        faster MDC clocks.
uint32_t ETH_ReadPHYRegister(ETH_Module* ETHx, uint32_t PHYAddr, uint32_t PHYReg, uint32_t* pRegValue)Read a PHY register.
Source comment
name    ETH_ReadPHYRegister.
fun     Read a PHY register.
param   ETHx (The input parameters must be the following values):
          - ETH
param   PHYAddr :
          - PHY port address, must be a value from 0 to 31.
param   PHYReg :
          - PHY register address, must be a value from 0 to 31.
param   pRegValue :
          - Points to the address where the read PHY register value is stored.
return  0 or 1.
uint32_t ETH_WritePHYRegister(ETH_Module* ETHx, uint32_t PHYAddr, uint32_t PHYReg, uint32_t PHYRegValue)Read a PHY register.
Source comment
name    ETH_WritePHYRegister.
fun     Read a PHY register.
param   ETHx (The input parameters must be the following values):
          - ETH
param   PHYAddr :
          - PHY port address, must be a value from 0 to 31.
param   PHYReg :
          - PHY register address, must be a value from 0 to 31.
param   PHYRegValue :
          - The value to write.
return  0 or 1.
EthFuncStatusType ETH_ExternalPHYInit(ETH_Module* ETHx, ETH_InfoType* pInfo, ETH_InitType* ETH_InitParam)Initialize the external PHY, including settings related to whether or not to enable the PHY auto-negotiation function.
Source comment
name    ETH_ExternalPHYInit.
fun     Initialize the external PHY, including settings related to whether or
        not to enable the PHY auto-negotiation function.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   ETH_InitParam :
          - Pointer to the ETH_InitType structure which will be initialized.
return  One of EthFuncStatusType.
EthFuncStatusType ETH_Init(ETH_Module* ETHx, ETH_InfoType* pInfo, ETH_InitType* ETH_InitParam)Initialize the ETH module with ETH_InitParam of type ETH_InitType, including ETH MAC initialization, MTL initialization, ETH DMA initialization, etc.
Source comment
name    ETH_Init.
fun     Initialize the ETH module with ETH_InitParam of type ETH_InitType, including
        ETH MAC initialization, MTL initialization, ETH DMA initialization, etc.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   ETH_InitParam :
          - Pointer to the ETH_InitType structure which will be initialized.
return  One of EthFuncStatusType.
void ETH_TxMACCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC transmission.
Source comment
name    ETH_TxMACCmd.
fun     Enables or disables the MAC transmission.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_RxMACCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC reception.
Source comment
name    ETH_RxMACCmd.
fun     Enables or disables the MAC reception.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_SetHashTable(ETH_Module* ETHx, uint32_t *pHashTable)Set the ETH Hash Table Value.
Source comment
name    ETH_SetHashTable.
fun     Set the ETH Hash Table Value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pHashTable :
          - Pointer to a table of two 32 bit values, that contains the 64
            bits of the hash table.
return  none
void ETH_RxVLANTagStructInit(ETH_RxVLANTagInitType* ETH_RxVTInitParam)Initializes the structure parameter of type ETH_RxVLANTagInitType used to initialize VLAN tag. This function is usually called before initializing a parameter of type ETH_RxVLANTagInitType.
Source comment
name    ETH_RxVLANTagStructInit.
fun     Initializes the structure parameter of type ETH_RxVLANTagInitType used to
        initialize VLAN tag. This function is usually called before initializing
        a parameter of type ETH_RxVLANTagInitType.
param   ETH_InitParam :
          - Pointer to the ETH_RxVLANTagInitType structure which will be initialized.
return  none
void ETH_RxVLANTagInit(ETH_Module* ETHx, ETH_RxVLANTagInitType* ETH_RxVTInitParam)Initialize VLAN tag processing on the receive path.
Source comment
name    ETH_RxVLANTagInit.
fun     Initialize VLAN tag processing on the receive path.
param   ETHx (The input parameters must be the following values):
          - ETH
param   ETH_RxVTInitParam :
          - Pointer to the ETH_RxVLANTagInitType structure which will be initialized.
return  none
void ETH_SetVLANHashTable(ETH_Module* ETHx, uint16_t HashTable)Set the ETH VLAN Hash Table Value.
Source comment
name    ETH_SetVLANHashTable.
fun     Set the ETH VLAN Hash Table Value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   HashTable :
          - VLAN hash table 16 bit value.
return  none
void ETH_SetRxVLANIdentifier(ETH_Module* ETHx, uint32_t VLANIdentifier)Set the VLAN Identifier for Rx packets.
Source comment
name    ETH_SetRxVLANIdentifier.
fun     Set the VLAN Identifier for Rx packets.
param   ETHx (The input parameters must be the following values):
          - ETH
param   VLANIdentifier :
          - VLAN Identifier value.
return  none
void ETH_InitiatePauseControlPacket(ETH_Module* ETHx)Initiates a pause control packet transmission during TX flow control operation.
Source comment
name    ETH_InitiatePauseControlPacket.
fun     Initiates a pause control packet transmission during TX flow control
        operation.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    The pause packet function is only valid when the MAC is configured
        in full-duplex mode.
note    During control packet transmission, this bit remains set to 1 to
        indicate that packet transmission is in progress. When pause packet
        transmission is complete, the MAC resets this bit to 0. No write
        operations should be performed to this register until this bit is
        cleared.
void ETH_ActivateBackpressure(ETH_Module* ETHx)Activate backpressure function during TX flow control operation.
Source comment
name    ETH_ActivateBackpressure.
fun     Activate backpressure function during TX flow control operation.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    Activate backpressure function is only valid when the MAC is configured
        in half-duplex mode.
note    during backpressure, when the MAC receives a new frame, the transmitter
        starts sending a JAM pattern resulting in a collision.
note    BPA is automatically disabled when the MAC is configured in full-duplex
        mode.
void ETH_PowerDownCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the ETH Power Down mode.
Source comment
name    ETH_PowerDownCmd.
fun     Enables or disables the ETH Power Down mode.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MagicPacketDetectionCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC Magic Packet Detection.
Source comment
name    ETH_MagicPacketDetectionCmd.
fun     Enables or disables the MAC Magic Packet Detection.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_WakeUpPacketDetectionCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC Remote Wake-Up Packet Detection.
Source comment
name    ETH_WakeUpPacketDetectionCmd.
fun     Enables or disables the MAC Remote Wake-Up Packet Detection.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_GlobalUnicastWakeUpCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables any unicast packet filtered by the MAC address recognition to be a wake-up packet.
Source comment
name    ETH_GlobalUnicastWakeUpCmd.
fun     Enables or disables any unicast packet filtered by the MAC
        address recognition to be a wake-up packet.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_ResetWakeUpPacketFilterRegPointer(ETH_Module* ETHx)Reset Wakeup packet filter register pointer.
Source comment
name    ETH_ResetWakeUpPacketFilterRegPointer.
fun     Reset Wakeup packet filter register pointer.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_SetWakeUpPacketFilterRegister(ETH_Module* ETHx, uint32_t *pBuffer)Populates the remote wakeup packet registers.
Source comment
name    ETH_SetWakeUpPacketFilterRegister.
fun     Populates the remote wakeup packet registers.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pBuffer :
          - Pointer on remote WakeUp Packet Filter Register buffer data (8 words).
return  none
note    When MAC RWK Packet Filter register is written, the content is transferred
        from CSR clock domain to PHY receive clock domain after the write operation,
        there should not be any further write to the MAC RWK Packet Filter register
        until the first write is updated in PHY receive clock domain. Otherwise, the
        second write operation does not get updated to the PHY receive clock domain.
        Therefore, the delay between two writes to the MAC RWK Packet Filter register
        should be at least 4 cycles of the PHY receive clock.
void ETH_CSRRegisterWrite1ClearCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables Write 1 clear mode for some CSR registers.
Source comment
name    ETH_CSRRegisterWrite1ClearCmd.
fun     Enables or disables Write 1 clear mode for some CSR registers.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_SetMACAddress(ETH_Module* ETHx, EthMacAddr0123Type Offset, uint8_t* pAddr)Set MAC address by application layer setting. Support configuring MAC address registers 0~3.
Source comment
name    ETH_SetMACAddress.
fun     Set MAC address by application layer setting. Support configuring
        MAC address registers 0~3.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MAC_ADDR0_OFFSET
          - ETH_MAC_ADDR1_OFFSET
          - ETH_MAC_ADDR2_OFFSET
          - ETH_MAC_ADDR3_OFFSET
param   pAddr:
          - Pointer on MAC address buffer
return  none
void ETH_GetMACAddress(ETH_Module* ETHx, EthMacAddr0123Type Offset, uint8_t* pAddr)Get MAC address by application layer setting. Support get MAC address registers 0~3.
Source comment
name    ETH_GetMACAddress.
fun     Get MAC address by application layer setting. Support get MAC address
        registers 0~3.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MAC_ADDR0_OFFSET
          - ETH_MAC_ADDR1_OFFSET
          - ETH_MAC_ADDR2_OFFSET
          - ETH_MAC_ADDR3_OFFSET
param   pAddr:
          - Pointer on MAC address buffer
return  none
void ETH_MACAddressPerfectFilterCmd(ETH_Module* ETHx, EthMacAddr123Type Offset, FunctionalStatus Cmd)Enables or disables the Address filter module uses the specified ETH MAC address (MAC address 1 ~ MAC address 3) for perfect filtering.
Source comment
name    ETH_MACAddressPerfectFilterCmd.
fun     Enables or disables the Address filter module uses the specified ETH
        MAC address (MAC address 1 ~ MAC address 3) for perfect filtering.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MACADDR1_OFFSET
          - ETH_MACADDR2_OFFSET
          - ETH_MACADDR3_OFFSET
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_SetMACAddressFilter(ETH_Module* ETHx, EthMacAddr123Type Offset, EthMacAddrFilterType Filter)Set the filter type for the specified ETH MAC address (MAC address 1 ~ MAC address 3).
Source comment
name    ETH_SetMACAddressFilter.
fun     Set the filter type for the specified ETH MAC address (MAC address 1 ~
        MAC address 3).
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MACADDR1_OFFSET
          - ETH_MACADDR2_OFFSET
          - ETH_MACADDR3_OFFSET
param   Filter (The input parameters must be the following values):
          - ETH_MACADDR_FILTER_SA
          - ETH_MACADDR_FILTER_DA
return  none
void ETH_SetMACAddressFilterMaskBytes(ETH_Module* ETHx, EthMacAddr123Type Offset, uint32_t MaskByte)Set the filter mask bytes for the specified ETH MAC address (MAC address 1 ~ MAC address 3).
Source comment
name    ETH_SetMACAddressFilterMaskBytes.
fun     Set the filter mask bytes for the specified ETH MAC address (MAC address 1 ~
        MAC address 3).
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MACADDR1_OFFSET
          - ETH_MACADDR2_OFFSET
          - ETH_MACADDR3_OFFSET
param   MaskByte (The input parameters must be the following values):
          - ETH_MACADDR_MASK_BYTE6
          - ETH_MACADDR_MASK_BYTE5
          - ETH_MACADDR_MASK_BYTE4
          - ETH_MACADDR_MASK_BYTE3
          - ETH_MACADDR_MASK_BYTE2
          - ETH_MACADDR_MASK_BYTE1
return  none
void ETH_MMCCountersReset(ETH_Module* ETHx)Resets the MMC Counters.
Source comment
name    ETH_MMCCountersReset.
fun     Resets the MMC Counters.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MMCCounterStopRolloverCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MMC Counter Stop Rollover.
Source comment
name    ETH_MMCCounterStopRolloverCmd.
fun     Enables or disables the MMC Counter Stop Rollover.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MMCResetOnReadCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MMC Reset On Read.
Source comment
name    ETH_MMCResetOnReadCmd.
fun     Enables or disables the MMC Reset On Read.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MMCCounterFreezeCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MMC Counter Freeze.
Source comment
name    ETH_MMCCounterFreezeCmd.
fun     Enables or disables the MMC Counter Freeze.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MMCCounterHalfPreset(ETH_Module* ETHx)Preset and Initialize the MMC counters to almost-half value: 0x7FFF_FFF0.
Source comment
name    ETH_MMCCounterHalfPreset.
fun     Preset and Initialize the MMC counters to almost-half value:
        0x7FFF_FFF0.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MMCCounterFullPreset(ETH_Module* ETHx)Preset and Initialize the MMC counters to almost-full value: 0xFFFF_FFF0.
Source comment
name    ETH_MMCCounterFullPreset.
fun     Preset and Initialize the MMC counters to almost-full value:
        0xFFFF_FFF0.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MMCCounterUpdateForDropBCPacketCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the Update MMC Counters for Dropped Broadcast Packets.
Source comment
name    ETH_MMCCounterUpdateForDropBCPacketCmd.
fun     Enables or disables the Update MMC Counters for Dropped Broadcast
        Packets.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
uint32_t ETH_GetMMCCounterValue(ETH_Module* ETHx, EthMmcAddrType Offset)Get the specified ETH MMC counter value.
Source comment
name    ETH_GetMMCCounterValue.
fun     Get the specified ETH MMC counter value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MMC_SCGP_OFFSET
          - ETH_MMC_MCGP_OFFSET
          - ETH_MMC_PCG_OFFSET
          - ETH_MMC_BPG_OFFSET
          - ETH_MMC_MPG_OFFSET
          - ETH_MMC_CRCEP_OFFSET
          - ETH_MMC_AEP_OFFSET
          - ETH_MMC_UPG_OFFSET
return  Corresponding counter value.
void ETH_MACTimeStampCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC timestamp.
Source comment
name    ETH_MACTimeStampCmd.
fun     Enables or disables the MAC timestamp.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_SetTimeStampUpdateMethod(ETH_Module* ETHx, uint32_t Method)Selects the MAC timestamp Update method.
Source comment
name    ETH_SetTimeStampUpdateMethod.
fun     Selects the MAC timestamp Update method.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Method (The input parameters must be the following values):
          - ETH_MACTS_FINE_UPDATE
          - ETH_MACTS_COARSE_UPDATE
return  none
void ETH_MACTimeStampInit(ETH_Module* ETHx)Initialize the MAC timestamp. The system time is initialized (overwritten) with the values specified in the MAC System Time Seconds Update Register and the MAC System Time Nanoseconds Update Register.
Source comment
name    ETH_MACTimeStampInit.
fun     Initialize the MAC timestamp. The system time is initialized
        (overwritten) with the values specified in the MAC System Time Seconds
        Update Register and the MAC System Time Nanoseconds Update Register.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MACTimeStampUpdate(ETH_Module* ETHx)Update the MAC timestamp. The system time is updated (added or subtracted) with the values specified in the MAC System Time Seconds Update Register and the MAC System Time Nanoseconds Update Register.
Source comment
name    ETH_MACTimeStampUpdate.
fun     Update the MAC timestamp. The system time is updated (added or
        subtracted) with the values specified in the MAC System Time Seconds
        Update Register and the MAC System Time Nanoseconds Update Register.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_EnableTimeStampIntTrigger(ETH_Module* ETHx)Enable the MAC TimeStamp interrupt trigger. the timestamp interrupt is generated when the System Time becomes greater than the value written in the Target Time register.
Source comment
name    ETH_EnableTimeStampIntTrigger.
fun     Enable the MAC TimeStamp interrupt trigger. the timestamp interrupt is
        generated when the System Time becomes greater than the value written
        in the Target Time register.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MACTimeStampAddendRegUpdate(ETH_Module* ETHx)Update the MAC timestamp addend register. the content of the Timestamp Addend register is updated in the PTP block for fine correction.
Source comment
name    ETH_MACTimeStampAddendRegUpdate.
fun     Update the MAC timestamp addend register. the content of the Timestamp
        Addend register is updated in the PTP block for fine correction.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MACTimeStampAllPacketsCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC timestamp for All Packets.
Source comment
name    ETH_MACTimeStampAllPacketsCmd.
fun     Enables or disables the MAC timestamp for All Packets.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MACTimeStampDigBinRolloverCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC timestamp Rollover for Digital or Binary.
Source comment
name    ETH_MACTimeStampDigBinRolloverCmd.
fun     Enables or disables the MAC timestamp Rollover for Digital or Binary.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_PTPTypePacketProcesCmd(ETH_Module* ETHx, uint32_t PacketType, FunctionalStatus Cmd)Enables or disables the processing for selected PTP packet type.
Source comment
name    ETH_PTPTypePacketProcesCmd.
fun     Enables or disables the processing for selected PTP packet type.
param   ETHx (The input parameters must be the following values):
          - ETH
param   PacketType (The input parameters must be the following values):
          - ETH_MACPTP_TYPE_VERSION2
          - ETH_MACPTP_TYPE_ETHERNET
          - ETH_MACPTP_TYPE_IPV6UDP
          - ETH_MACPTP_TYPE_IPV4UDP (default)
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MACAddrPTPPacketFilterCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC address for PTP packet filtering.
Source comment
name    ETH_MACAddrPTPPacketFilterCmd.
fun     Enables or disables the MAC address for PTP packet filtering.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MACTxTimeStampStatusModeCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the MAC TX timestamp status mode.
Source comment
name    ETH_MACTxTimeStampStatusModeCmd.
fun     Enables or disables the MAC TX timestamp status mode.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_SetSubSecondIncrementValue(ETH_Module* ETHx, uint8_t IncValue)Sets the system time Sub-Second Increment value.
Source comment
name    ETH_SetSubSecondIncrementValue.
fun     Sets the system time Sub-Second Increment value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IncValue :
          - 0~0xFF
return  none
void ETH_SetTimeStampUpdateValue(ETH_Module* ETHx, uint32_t CalMode, uint32_t SecondValue, uint32_t SubSecondValue)Sets the Time Stamp update value.
Source comment
name    ETH_SetTimeStampUpdateValue.
fun     Sets the Time Stamp update value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   CalMode (The input parameters must be the following values):
          - ETH_MACTS_CALMODE_SUB
          - ETH_MACTS_CALMODE_ADD
param   SecondValue :
          - 0~0xFFFFFFFF
param   SubSecondValue :
          - 0~0x7FFFFFFF
return  none
note    When CalMode is set to ETH_MACTS_CALMODE_SUB, the seconds field
        and nanosecond field must be programmed with the complement of
        the corresponding part of the update value.
void ETH_SetTimeStampAddendValue(ETH_Module* ETHx, uint32_t AddValue)Sets the Time Stamp addend value.
Source comment
name    ETH_SetTimeStampAddendValue.
fun     Sets the Time Stamp addend value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   AddValue :
          - 0~0xFFFFFFFF
return  none
uint32_t ETH_GetTimeStampRegValue(ETH_Module* ETHx, EthTsAddrType Offset)Gets the specified ETH MAC TimeStamp register value.
Source comment
name    ETH_GetTimeStampRegValue.
fun     Gets the specified ETH MAC TimeStamp register value.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Offset (The input parameters must be the following values):
          - ETH_MACTS_SSIR_OFFSET
          - ETH_MACTS_STSR_OFFSET
          - ETH_MACTS_STNSR_OFFSET
          - ETH_MACTS_STSUR_OFFSET
          - ETH_MACTS_STNSUR_OFFSET
          - ETH_MACTS_TAR_OFFSET
          - ETH_MACTS_TTSNSR_OFFSET
          - ETH_MACTS_TTSSR_OFFSET
          - ETH_MACTS_TICNSR_OFFSET
          - ETH_MACTS_TECNSR_OFFSET
          - ETH_MACTS_TILR_OFFSET
          - ETH_MACTS_TELR_OFFSET
          - ETH_MACTS_PTTSR_OFFSET
          - ETH_MACTS_PTTNSR_OFFSET
return  Corresponding MAC TimeStamp value.
void ETH_ConfigPPSOutput(ETH_Module* ETHx, uint32_t OutputFreq)Configure the PPS output, e.g. configure the output frequency, which defaults to one pulse per second.
Source comment
name    ETH_ConfigPPSOutput.
fun     Configure the PPS output, e.g. configure the output frequency,
        which defaults to one pulse per second.
param   ETHx (The input parameters must be the following values):
          - ETH
param   OutputFreq (The input parameters must be the following values):
          - ETH_MACPPS_FREQCTRL_B2D1
          - ETH_MACPPS_FREQCTRL_B4D2
          - ETH_MACPPS_FREQCTRL_B8D4
          - ETH_MACPPS_FREQCTRL_B16D8
          - ETH_MACPPS_FREQCTRL_B32D16
          - ETH_MACPPS_FREQCTRL_B64D32
          - ETH_MACPPS_FREQCTRL_B128D64
          - ETH_MACPPS_FREQCTRL_B256D128
          - ETH_MACPPS_FREQCTRL_B512D256
          - ETH_MACPPS_FREQCTRL_B1024D512
          - ETH_MACPPS_FREQCTRL_B2048D1024
          - ETH_MACPPS_FREQCTRL_B4096D2048
          - ETH_MACPPS_FREQCTRL_B8192D4096
          - ETH_MACPPS_FREQCTRL_B16384D8192
          - ETH_MACPPS_FREQCTRL_B32768D16384
return  none
void ETH_SetPPSTargetTimeValue(ETH_Module* ETHx, uint32_t SecondValue, uint32_t SubSecondValue)Sets the PPS target time value with seconds field and nanosecond field.
Source comment
name    ETH_SetPPSTargetTimeValue.
fun     Sets the PPS target time value with seconds field and nanosecond field.
param   ETHx (The input parameters must be the following values):
          - ETH
param   SecondValue :
          - 0~0xFFFFFFFF
param   SubSecondValue :
          - 0~0x7FFFFFFF
return  none
void ETH_MTLDropTxStatusCmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the Drop Transmit Status.
Source comment
name    ETH_MTLDropTxStatusCmd.
fun     Enables or disables the Drop Transmit Status.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_MTLCounterPreset(ETH_Module* ETHx)Preset and Initialize the MTL counters to value: 0x7F0.
Source comment
name    ETH_MTLCounterPreset.
fun     Preset and Initialize the MTL counters to value: 0x7F0.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_MTLCounterReset(ETH_Module* ETHx)Reset all counters of MTL.
Source comment
name    ETH_MTLCounterReset.
fun     Reset all counters of MTL.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    The counter reset control bit is automatically cleared after 1 clock
        cycle.
void ETH_FlushTransmitQueue(ETH_Module* ETHx)Clears the ETH transmit FIFO.
Source comment
name    ETH_FlushTransmitQueue.
fun     Clears the ETH transmit FIFO.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    The MTL Transmit Queue Operation Mode Register (ETH_MTLTXQOPMOD)
        should not be written until the flush operation is complete.
        This function causes all data in the Tx FIFO to be lost or flushed.
        However, data that has been accepted by the MAC transmitter will not
        be flushed. It will be scheduled for transmission and will result in
        underflow and short packets being sent.
uint16_t ETH_GetMTLUnderflowPacketCounter(ETH_Module* ETHx)Get the number of packets aborted by the controller due to Tx queue underflow.
Source comment
name    ETH_GetMTLUnderflowPacketCounter.
fun     Get the number of packets aborted by the controller due to Tx queue
        underflow.
param   ETHx (The input parameters must be the following values):
          - ETH
return  Counter value: 0~0x7FF.
uint16_t ETH_GetMTLOverflowPacketCounter(ETH_Module* ETHx)Gets the number of packets discarded due to Rx queue overflow.
Source comment
name    ETH_GetMTLOverflowPacketCounter.
fun     Gets the number of packets discarded due to Rx queue overflow.
param   ETHx (The input parameters must be the following values):
          - ETH
return  Counter value: 0~0x7FF.
uint16_t ETH_GetMTLMissedPacketCounter(ETH_Module* ETHx)Gets the number of packets lost due to the application performing packet refresh requests against this queue.
Source comment
name    ETH_GetMTLMissedPacketCounter.
fun     Gets the number of packets lost due to the application performing
        packet refresh requests against this queue.
param   ETHx (The input parameters must be the following values):
          - ETH
return  Counter value: 0~0x7FF.
void ETH_SoftwareReset(ETH_Module* ETHx)ETH software reset, the MAC and the DMA controller reset the logic and all internal registers of the DMA, MTL, and MAC.
Source comment
name    ETH_SoftwareReset.
fun     ETH software reset, the MAC and the DMA controller reset the logic
        and all internal registers of the DMA, MTL, and MAC.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    1. The software reset status bit (SWR) is automatically cleared after
        the reset operation is completed.
        2. Before reprogramming any ETH register, a value of zero should be
        read in SWR bit.
        3. The SWR bit must be read at least 4 CSR clock cycles after it is
        written to 1.
void ETH_TxDMACmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the DMA transmission.
Source comment
name    ETH_TxDMACmd.
fun     Enables or disables the DMA transmission.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_RxDMACmd(ETH_Module* ETHx, FunctionalStatus Cmd)Enables or disables the DMA reception.
Source comment
name    ETH_RxDMACmd.
fun     Enables or disables the DMA reception.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_ResumeDMATransmission(ETH_Module* ETHx)Resume TX DMA by writing any value to transmit descriptor tail pointer register when TX DMA enters suspend mode.
Source comment
name    ETH_ResumeDMATransmission.
fun     Resume TX DMA by writing any value to transmit descriptor tail pointer
        register when TX DMA enters suspend mode.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    This function is only applicable when the DMA enters suspend mode.
void ETH_ResumeDMAReception(ETH_Module* ETHx)Resume RX DMA by writing any value to receive descriptor tail pointer register when RX DMA enters suspend mode.
Source comment
name    ETH_ResumeDMAReception.
fun     Resume RX DMA by writing any value to receive descriptor tail pointer
        register when RX DMA enters suspend mode.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
note    This function is only applicable when the DMA enters suspend mode.
void ETH_SetRxInterruptWatchdogTimer(ETH_Module* ETHx, uint32_t CntUnit, uint32_t CntValue)Set the watchdog timer for the DMA receive interrupt.
Source comment
name    ETH_SetRxInterruptWatchdogTimer.
fun     Set the watchdog timer for the DMA receive interrupt.
param   ETHx (The input parameters must be the following values):
          - ETH
param   CntUnit (The input parameters must be the following values):
          - ETH_DMARXINT_WDGTIM_CNTUNIT_256
          - ETH_DMARXINT_WDGTIM_CNTUNIT_512
          - ETH_DMARXINT_WDGTIM_CNTUNIT_1024
          - ETH_DMARXINT_WDGTIM_CNTUNIT_2048
param   CntValue :
          - Count value: 0~0x000000FF.
return  none
note    Timer cycles = count unit * count value (CntUnit * CntValue) system
        clock cycles.
uint32_t ETH_GetCurrentTxDescriptorAddress(ETH_Module* ETHx)Gets the address of the current application transmit descriptor read by the DMA.
Source comment
name    ETH_GetCurrentTxDescriptorAddress.
fun     Gets the address of the current application transmit descriptor read
        by the DMA.
param   ETHx (The input parameters must be the following values):
          - ETH
return  The value of the current Tx descriptor address.
uint32_t ETH_GetCurrentRxDescriptorAddress(ETH_Module* ETHx)Gets the address of the current application receive descriptor read by the DMA.
Source comment
name    ETH_GetCurrentRxDescriptorAddress.
fun     Gets the address of the current application receive descriptor read
        by the DMA.
param   ETHx (The input parameters must be the following values):
          - ETH
return  The value of the current Rx descriptor address.
uint32_t ETH_GetCurrentTxBufferAddress(ETH_Module* ETHx)Gets the address of the current application transmit buffer read by the DMA.
Source comment
name    ETH_GetCurrentTxBufferAddress.
fun     Gets the address of the current application transmit buffer read
        by the DMA.
param   ETHx (The input parameters must be the following values):
          - ETH
return  The value of the current Tx buffer address.
uint32_t ETH_GetCurrentRxBufferAddress(ETH_Module* ETHx)Gets the address of the current application receive buffer read by the DMA.
Source comment
name    ETH_GetCurrentRxBufferAddress.
fun     Gets the address of the current application receive buffer read
        by the DMA.
param   ETHx (The input parameters must be the following values):
          - ETH
return  The value of the current Rx buffer address.
uint8_t ETH_GetTxDMAErrorType(ETH_Module* ETHx)Get the type of TX DMA error that caused the fatal bus error.
Source comment
name    ETH_GetTxDMAErrorType.
fun     Get the type of TX DMA error that caused the fatal bus error.
param   ETHx (The input parameters must be the following values):
          - ETH
return  TX DMA Error Bits[2:0] Value:
          - bit[0]:
            - 1: Error during read transfer
            - 0: Error during write transfer
          - bit[1]:
            - 1: Error during descriptor access
            - 0: Error during data buffer access
          - bit[2]:
            - 1: Error during data transfer by Tx DMA
            - 0: No Error during data transfer by Tx DMA
        Invalid value:
          - 0xFF
note    This function returns a valid value only if a fatal bus error occurs
        (FBE set to 1). And these error types do not generate interrupts.
uint8_t ETH_GetRxDMAErrorType(ETH_Module* ETHx)Get the type of RX DMA error that caused the fatal bus error.
Source comment
name    ETH_GetRxDMAErrorType.
fun     Get the type of RX DMA error that caused the fatal bus error.
param   ETHx (The input parameters must be the following values):
          - ETH
return  RX DMA Error Bits[2:0] Value:
          - bit[0]:
            - 1: Error during read transfer
            - 0: Error during write transfer
          - bit[1]:
            - 1: Error during descriptor access
            - 0: Error during data buffer access
          - bit[2]:
            - 1: Error during data transfer by Rx DMA
            - 0: No Error during data transfer by Rx DMA
        Invalid value:
          - 0xFF
note    This function returns a valid value only if a fatal bus error occurs
        (FBE set to 1). And these error types do not generate interrupts.
uint16_t ETH_GetDMACh0DroppedPacketCounter(ETH_Module* ETHx)Get the number of packet counters dropped by the DMA due to bus errors or programming the RPF field in the DMA Channel 0 Rx Control Register.
Source comment
name    ETH_GetDMACh0DroppedPacketCounter.
fun     Get the number of packet counters dropped by the DMA due to bus errors
        or programming the RPF field in the DMA Channel 0 Rx Control Register.
param   ETHx (The input parameters must be the following values):
          - ETH
return  Counter value: 0~0x7FF.
uint16_t ETH_GetDMACh0ERICounter(ETH_Module* ETHx)Get the number of counts for the number of times an ERI (Early Receive Interrupt) is valid.
Source comment
name    ETH_GetDMACh0ERICounter.
fun     Get the number of counts for the number of times an ERI (Early Receive
        Interrupt) is valid.
param   ETHx (The input parameters must be the following values):
          - ETH
return  Counter value: 0~0xFFF.
EthFuncStatusType ETH_RxDescAssignMemory(ETH_InfoType* pInfo, uint32_t Index, uint8_t* pBuffer1, uint8_t* pBuffer2)Assign memory buffers to a DMA Rx descriptor.
Source comment
name    ETH_RxDescAssignMemory.
fun     Assign memory buffers to a DMA Rx descriptor.
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   Index :
          - Index of the DMA Rx descriptor.
param   pBuffer1 :
          - Points to Buffer1 address.
param   pBuffer2 :
          - Points to Buffer2 address, if available.
return  One of EthFuncStatusType.
EthFuncStatusType ETH_BuildRxDescriptors(ETH_Module* ETHx, ETH_InfoType* pInfo)This function gives back Rx Desc of the last received Packet to the DMA, so ETH DMA will be able to use these descriptors to receive next Packets. It should be called after processing the received Packet.
Source comment
name    ETH_BuildRxDescriptors.
fun     This function gives back Rx Desc of the last received Packet to the DMA,
        so ETH DMA will be able to use these descriptors to receive next Packets.
        It should be called after processing the received Packet.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  One of EthFuncStatusType.
EthFuncStatusType ETH_PrepareTxDescriptors(ETH_Module* ETHx, ETH_InfoType* pInfo, ETH_TxPacketType* pTxPacket, uint32_t ItMode)Prepare Tx DMA descriptor before transmission.
Source comment
name    ETH_PrepareTxDescriptors.
fun     Prepare Tx DMA descriptor before transmission.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   pTxPacket :
          - Points to the TX packet, containing some configuration information
param   ItMode :
          - Mode Selection: 1 indicates to interrupt mode, 0 indicates to polling mode.
return  One of EthFuncStatusType.
EthFuncStatusType ETH_Transmit(ETH_Module* ETHx, ETH_InfoType* pInfo, ETH_TxPacketType* pTxPacket, uint32_t Timeout)Send packets via polling mode.
Source comment
name    ETH_Transmit.
fun     Send packets via polling mode.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   pTxPacket :
          - Points to the TX packet, containing some configuration information
param   Timeout :
          - timeout value
return  One of EthFuncStatusType.
EthFuncStatusType ETH_TransmitIT(ETH_Module* ETHx, ETH_InfoType* pInfo, ETH_TxPacketType* pTxPacket)Send packets via interrupt mode.
Source comment
name    ETH_TransmitIT.
fun     Send packets via interrupt mode.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   pTxPacket :
          - Points to the TX packet, containing some configuration information
return  One of EthFuncStatusType.
uint8_t ETH_IsRxDataAvailable(ETH_InfoType* pInfo)Checks the data of received packets.
Source comment
name    ETH_IsRxDataAvailable.
fun     Checks the data of received packets.
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  1 or 0.
EthFuncStatusType ETH_GetRxDataBuffer(ETH_InfoType* pInfo, ETH_BufferType* pRxBuffer)Used to fetch the data buffer when processing the received Packet.
Source comment
name    ETH_GetRxDataBuffer.
fun     Used to fetch the data buffer when processing the received Packet.
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   pRxBuffer :
          - Points to the RX buffer, ETH_BufferType structure.
return  One of EthFuncStatusType.
uint16_t ETH_GetRxDataLength(ETH_InfoType* pInfo)Used to fetch the data length of last received Packet when processing the received Packet.
Source comment
name    ETH_GetRxDataLength.
fun     Used to fetch the data length of last received Packet when processing the
        received Packet.
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  0 or length of last received Packet.
EthFuncStatusType ETH_GetRxPacketInfo(ETH_InfoType* pInfo, ETH_RxPacketType* pRxPacket)Get the Rx Packet info (Packet type, VLAN tag, Filters status, ...).
Source comment
name    ETH_GetRxPacketInfo.
fun     Get the Rx Packet info (Packet type, VLAN tag, Filters status, ...).
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
param   pRxPacket :
          - Points to the RX packet, containing some packet information.
return  One of EthFuncStatusType.
void ETH_Start(ETH_Module* ETHx)Turn on ETH via polling mode, including turning on TX and RX DMA engines, turning on TX and RX MAC controllers, etc.
Source comment
name    ETH_Start.
fun     Turn on ETH via polling mode, including turning on TX and RX DMA engines,
        turning on TX and RX MAC controllers, etc.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none.
void ETH_StartIT(ETH_Module* ETHx, ETH_InfoType* pInfo)Turn on ETH via interrupt mode, including turning on TX and RX DMA engines, turning on TX and RX MAC controllers, etc.
Source comment
name    ETH_StartIT.
fun     Turn on ETH via interrupt mode, including turning on TX and RX DMA engines,
        turning on TX and RX MAC controllers, etc.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  none.
void ETH_Stop(ETH_Module* ETHx)Turn off ETH in polling mode, including turning off TX and RX DMA engines, turning off TX and RX MAC controllers, etc.
Source comment
name    ETH_Stop.
fun     Turn off ETH in polling mode, including turning off TX and RX DMA engines,
        turning off TX and RX MAC controllers, etc.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none.
void ETH_StopIT(ETH_Module* ETHx, ETH_InfoType* pInfo)Turn off ETH in interrupt mode, including turning off TX and RX DMA engines, turning off TX and RX MAC controllers, etc.
Source comment
name    ETH_StopIT.
fun     Turn off ETH in interrupt mode, including turning off TX and RX DMA engines,
        turning off TX and RX MAC controllers, etc.
param   ETHx (The input parameters must be the following values):
          - ETH
param   pInfo :
          - Pointer to an ETH_InfoType structure parameter containing various
            information about the operation of the ETH module.
return  none.
FlagStatus ETH_GetTxDescFlagStatus(ETH_DMADescType* pTxDescriptor, uint32_t Flag)Checks whether the specified ETH DMA Tx Descriptor status flag bits is set or not.
Source comment
name    ETH_GetTxDescFlagStatus.
fun     Checks whether the specified ETH DMA Tx Descriptor status flag
        bits is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_DMATXDESC_FLAG_IHE
          - ETH_DMATXDESC_FLAG_DB
          - ETH_DMATXDESC_FLAG_UF
          - ETH_DMATXDESC_FLAG_ED
          - ETH_DMATXDESC_FLAG_CC
          - ETH_DMATXDESC_FLAG_EC
          - ETH_DMATXDESC_FLAG_LC
          - ETH_DMATXDESC_FLAG_NC
          - ETH_DMATXDESC_FLAG_LOC
          - ETH_DMATXDESC_FLAG_PCE
          - ETH_DMATXDESC_FLAG_PF
          - ETH_DMATXDESC_FLAG_JT
          - ETH_DMATXDESC_FLAG_ES
          - ETH_DMATXDESC_FLAG_TTSS
          - ETH_DMATXDESC_FLAG_DE
          - ETH_DMATXDESC_FLAG_LD
          - ETH_DMATXDESC_FLAG_FD
return  SET or RESET
FlagStatus ETH_GetRxDescExtendedFlagStatus(ETH_DMADescType* pRxDescriptor, uint32_t Flag)Checks whether the specified ETH DMA Rx Descriptor Extended status flag bits is set or not.
Source comment
name    ETH_GetRxDescExtendedFlagStatus.
fun     Checks whether the specified ETH DMA Rx Descriptor Extended status
        flag bits is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_DMARXDESC_EXTFLAG_PT_NONE
          - ETH_DMARXDESC_EXTFLAG_PT_NUDP
          - ETH_DMARXDESC_EXTFLAG_PT_TCP
          - ETH_DMARXDESC_EXTFLAG_PT_ICNP
          - ETH_DMARXDESC_EXTFLAG_IPHE
          - ETH_DMARXDESC_EXTFLAG_IPV4
          - ETH_DMARXDESC_EXTFLAG_IPV6
          - ETH_DMARXDESC_EXTFLAG_IPCB
          - ETH_DMARXDESC_EXTFLAG_IPCE
          - ETH_DMARXDESC_EXTFLAG_PMT_NONE
          - ETH_DMARXDESC_EXTFLAG_PMT_SYNC
          - ETH_DMARXDESC_EXTFLAG_PMT_FU
          - ETH_DMARXDESC_EXTFLAG_PMT_DREQ
          - ETH_DMARXDESC_EXTFLAG_PMT_DRESP
          - ETH_DMARXDESC_EXTFLAG_PMT_PDREQ
          - ETH_DMARXDESC_EXTFLAG_PMT_PDRESP
          - ETH_DMARXDESC_EXTFLAG_PMT_PRFU
          - ETH_DMARXDESC_EXTFLAG_PMT_ANN
          - ETH_DMARXDESC_EXTFLAG_PMT_MAN
          - ETH_DMARXDESC_EXTFLAG_PMT_SIG
          - ETH_DMARXDESC_EXTFLAG_PMT_PRT
          - ETH_DMARXDESC_EXTFLAG_PFT
          - ETH_DMARXDESC_EXTFLAG_PV
          - ETH_DMARXDESC_EXTFLAG_TSA
          - ETH_DMARXDESC_EXTFLAG_TD
return  SET or RESET
FlagStatus ETH_GetRxDescFilterFlagStatus(ETH_DMADescType* pRxDescriptor, uint32_t Flag)Checks whether the specified ETH DMA Rx Descriptor Filter status flag bits is set or not.
Source comment
name    ETH_GetRxDescFilterFlagStatus.
fun     Checks whether the specified ETH DMA Rx Descriptor Filter status flag
        bits is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_DMARXDESC_FLTFLAG_VFS
          - ETH_DMARXDESC_FLTFLAG_SAF
          - ETH_DMARXDESC_FLTFLAG_DAF
          - ETH_DMARXDESC_FLTFLAG_HF
return  SET or RESET
FlagStatus ETH_GetRxDescFlagStatus(ETH_DMADescType* pRxDescriptor, uint32_t Flag)Checks whether the specified ETH DMA Rx Descriptor status flag bits is set or not.
Source comment
name    ETH_GetRxDescFlagStatus.
fun     Checks whether the specified ETH DMA Rx Descriptor status flag bits
        is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_DMARXDESC_FLAG_ES
          - ETH_DMARXDESC_FLAG_LT_LP
          - ETH_DMARXDESC_FLAG_LT_TP
          - ETH_DMARXDESC_FLAG_LT_ARP
          - ETH_DMARXDESC_FLAG_LT_VLAN
          - ETH_DMARXDESC_FLAG_LT_DVLAN
          - ETH_DMARXDESC_FLAG_LT_MAC
          - ETH_DMARXDESC_FLAG_LT_OAM
          - ETH_DMARXDESC_FLAG_DE
          - ETH_DMARXDESC_FLAG_RE
          - ETH_DMARXDESC_FLAG_OE
          - ETH_DMARXDESC_FLAG_RWT
          - ETH_DMARXDESC_FLAG_GP
          - ETH_DMARXDESC_FLAG_CE
          - ETH_DMARXDESC_FLAG_RS0V
          - ETH_DMARXDESC_FLAG_RS1V
          - ETH_DMARXDESC_FLAG_RS2V
          - ETH_DMARXDESC_FLAG_LD
          - ETH_DMARXDESC_FLAG_FD
return  SET or RESET
FlagStatus ETH_GetFlowControlBusyStatus(ETH_Module* ETHx)Checks whether the ETH flow control busy bit is set or not.
Source comment
name    ETH_GetFlowControlBusyStatus.
fun     Checks whether the ETH flow control busy bit is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
return  SET or RESET
note    The Flow Control register should not be written to until this bit
        is cleared.
INTStatus ETH_GetMACInterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH MAC Interrupt flag is set or not.
Source comment
name    ETH_GetMACInterruptStatus.
fun     Checks whether the specified ETH MAC Interrupt flag is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MAC_INT_FLAG_PHY
          - ETH_MAC_INT_FLAG_PMT
          - ETH_MAC_INT_FLAG_MMCRX
          - ETH_MAC_INT_FLAG_MMCTX
          - ETH_MAC_INT_FLAG_TS
          - ETH_MAC_INT_FLAG_TX
          - ETH_MAC_INT_FLAG_RX
          - ETH_MAC_INT_FLAG_MDIO
return  SET or RESET
FlagStatus ETH_GetMACTxRxFlagStatus(ETH_Module* ETHx, uint32_t Flag)Checks whether the specified ETH MAC transmit-receive status flag bits is set or not.
Source comment
name    ETH_GetMACTxRxFlagStatus.
fun     Checks whether the specified ETH MAC transmit-receive status
        flag bits is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_MACTX_FLAG_TJT
          - ETH_MACTX_FLAG_NCARR
          - ETH_MACTX_FLAG_LCARR
          - ETH_MACTX_FLAG_EXDEF
          - ETH_MACTX_FLAG_LCOL
          - ETH_MACTX_FLAG_EXCOL
          - ETH_MACRX_FLAG_RWT
return  SET or RESET
FlagStatus ETH_GetPMTFlagStatus(ETH_Module* ETHx, uint32_t Flag)Checks whether the specified ETH PMT status flag bits is set or not.
Source comment
name    ETH_GetPMTFlagStatus.
fun     Checks whether the specified ETH PMT status flag bits is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_PMT_FLAG_WUPFRPR
          - ETH_PMT_FLAG_WUPR
          - ETH_PMT_FLAG_MPR
return  SET or RESET
INTStatus ETH_GetMMCRxInterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH MMC RX Interrupt flag is set or not.
Source comment
name    ETH_GetMMCRxInterruptStatus.
fun     Checks whether the specified ETH MMC RX Interrupt flag is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MMCRX_INT_FLAG_BCGPIS
          - ETH_MMCRX_INT_FLAG_MCGPIS
          - ETH_MMCRX_INT_FLAG_CRCERPIS
          - ETH_MMCRX_INT_FLAG_ALGNERPIS
          - ETH_MMCRX_INT_FLAG_UCGPIS
return  SET or RESET
INTStatus ETH_GetMMCTxInterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH MMC TX Interrupt flag is set or not.
Source comment
name    ETH_GetMMCTxInterruptStatus.
fun     Checks whether the specified ETH MMC TX Interrupt flag is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MMCTX_INT_FLAG_SCOLGPIS
          - ETH_MMCTX_INT_FLAG_MCOLGPIS
          - ETH_MMCTX_INT_FLAG_GPKTIS
return  SET or RESET
FlagStatus ETH_GetMACTimeStampFlagStatus(ETH_Module* ETHx, uint32_t Flag)Checks whether the specified ETH MAC Time Stamp flag is set or not.
Source comment
name    ETH_GetMACTimeStampFlagStatus.
fun     Checks whether the specified ETH MAC Time Stamp flag is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_MACTS_FLAG_SOVF
          - ETH_MACTS_FLAG_TARGT0
          - ETH_MACTS_FLAG_TRGTERR0
          - ETH_MACTS_FLAG_TXTSSIS
return  SET or RESET
FlagStatus ETH_GetFlushTransmitQueueStatus(ETH_Module* ETHx)Checks whether the ETH Flush Transmit Queue bit is cleared or not.
Source comment
name    ETH_GetFlushTransmitQueueStatus.
fun     Checks whether the ETH Flush Transmit Queue bit is cleared or not.
param   ETHx (The input parameters must be the following values):
          - ETH
return  SET or RESET
note    The MTL Transmit Queue Operation Mode Register (ETH_MTLTXQOPMOD)
        should not be written until the Flush Transmit Queue bit is reset.
INTStatus ETH_GetMTLInterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH MTL Interrupt flag is set or not.
Source comment
name    ETH_GetMTLInterruptStatus.
fun     Checks whether the specified ETH MTL Interrupt flag is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MTL_INT_FLAG_Q0IS
return  SET or RESET
INTStatus ETH_GetMTLQueueInterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH MTL queue Interrupt flag is set or not.
Source comment
name    ETH_GetMTLQueueInterruptStatus.
fun     Checks whether the specified ETH MTL queue Interrupt flag is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MTLTXQUEUE_INT_FLAG_UNFIS
          - ETH_MTLRXQUEUE_INT_FLAG_OVFIS
return  SET or RESET
FlagStatus ETH_GetMTLCounterFlagStatus(ETH_Module* ETHx, uint32_t Flag)Checks whether the specified ETH MTL Counter flag is set or not.
Source comment
name    ETH_GetMTLCounterFlagStatus.
fun     Checks whether the specified ETH MTL Counter flag is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_MTLCOUNTER_FLAG_UFCNTOVF
          - ETH_MTLCOUNTER_FLAG_OVFCNTOVF
          - ETH_MTLCOUNTER_FLAG_MISCNTOVF
return  SET or RESET
FlagStatus ETH_GetSoftwareResetStatus(ETH_Module* ETHx)Checks whether the ETH software reset bit (SWR) is set or not.
Source comment
name    ETH_GetSoftwareResetStatus.
fun     Checks whether the ETH software reset bit (SWR) is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
return  SET or RESET
note    1. Before reprogramming any ETH register, a value of zero should be
        read in SWR bit.
        2. The SWR bit must be read at least 4 CSR clock cycles after it is
        written to 1.
INTStatus ETH_GetDMAInterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH DMA Interrupt flag is set or not.
Source comment
name    ETH_GetDMAInterruptStatus.
fun     Checks whether the specified ETH DMA Interrupt flag is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_DMA_INT_FLAG_DMACH0
          - ETH_DMA_INT_FLAG_MTL
          - ETH_DMA_INT_FLAG_MAC
return  SET or RESET
uint32_t ETH_GetDMACh0TxProcessStatus(ETH_Module* ETHx)Returns the ETH DMA Transmit Process Status.
Source comment
name    ETH_GetDMACh0TxProcessStatus.
fun     Returns the ETH DMA Transmit Process Status.
param   ETHx (The input parameters must be the following values):
          - ETH
return  One of the following values:
          - ETH_DMACH0_TXPRO_FLAG_STOP
          - ETH_DMACH0_TXPRO_FLAG_RUN_FTTD
          - ETH_DMACH0_TXPRO_FLAG_RUN_WS
          - ETH_DMACH0_TXPRO_FLAG_RUN_RDS
          - ETH_DMACH0_TXPRO_FLAG_TSTMP_WS
          - ETH_DMACH0_TXPRO_FLAG_SUSPND
          - ETH_DMACH0_TXPRO_FLAG_RUN_CTD
uint32_t ETH_GetDMACh0RxProcessStatus(ETH_Module* ETHx)Returns the ETH DMA Receive Process Status.
Source comment
name    ETH_GetDMACh0RxProcessStatus.
fun     Returns the ETH DMA Receive Process Status.
param   ETHx (The input parameters must be the following values):
          - ETH
return  One of the following values:
          - ETH_DMACH0_RXPRO_FLAG_STOP
          - ETH_DMACH0_RXPRO_FLAG_RUN_FTTD
          - ETH_DMACH0_RXPRO_FLAG_RUN_WRP
          - ETH_DMACH0_RXPRO_FLAG_SUSPND
          - ETH_DMACH0_RXPRO_FLAG_RUN_CRD
          - ETH_DMACH0_RXPRO_FLAG_TSTMP
          - ETH_DMACH0_RXPRO_FLAG_RUN_TRP
FlagStatus ETH_GetDMACh0FlagStatus(ETH_Module* ETHx, uint32_t Flag)Checks whether the specified ETH DMA-CH0 flag is set or not.
Source comment
name    ETH_GetDMACh0FlagStatus.
fun     Checks whether the specified ETH DMA-CH0 flag is set or not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_DMACH0_FLAG_TI
          - ETH_DMACH0_FLAG_TPS
          - ETH_DMACH0_FLAG_TBU
          - ETH_DMACH0_FLAG_RI
          - ETH_DMACH0_FLAG_RBU
          - ETH_DMACH0_FLAG_RPS
          - ETH_DMACH0_FLAG_RWT
          - ETH_DMACH0_FLAG_ETI
          - ETH_DMACH0_FLAG_ERI
          - ETH_DMACH0_FLAG_FBE
          - ETH_DMACH0_FLAG_CDE
          - ETH_DMACH0_FLAG_AIS
          - ETH_DMACH0_FLAG_NIS
return  SET or RESET
INTStatus ETH_GetDMACh0InterruptStatus(ETH_Module* ETHx, uint32_t IntFlag)Checks whether the specified ETH DMA-CH0 Interrupt flag is set or not.
Source comment
name    ETH_GetDMACh0InterruptStatus.
fun     Checks whether the specified ETH DMA-CH0 Interrupt flag is set or
        not.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_DMACH0_INT_FLAG_TI
          - ETH_DMACH0_INT_FLAG_TPS
          - ETH_DMACH0_INT_FLAG_TBU
          - ETH_DMACH0_INT_FLAG_RI
          - ETH_DMACH0_INT_FLAG_RBU
          - ETH_DMACH0_INT_FLAG_RPS
          - ETH_DMACH0_INT_FLAG_RWT
          - ETH_DMACH0_INT_FLAG_ETI
          - ETH_DMACH0_INT_FLAG_ERI
          - ETH_DMACH0_INT_FLAG_FBE
          - ETH_DMACH0_INT_FLAG_CDE
          - ETH_DMACH0_INT_FLAG_AIS
          - ETH_DMACH0_INT_FLAG_NIS
return  SET or RESET
void ETH_ClearMACPHYInterruptFlag(ETH_Module* ETHx)Clears the MAC PHY Interrupt pending flag for the ETH.
Source comment
name    ETH_ClearMACPHYInterruptFlag.
fun     Clears the MAC PHY Interrupt pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_ClearPMTFlag(ETH_Module* ETHx, uint32_t Flag)Clears the MAC PMT pending flag for the ETH.
Source comment
name    ETH_ClearPMTFlag.
fun     Clears the MAC PMT pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_PMT_FLAG_WUPR
          - ETH_PMT_FLAG_MPR
return  none
void ETH_ClearMMCRxInterruptFlag(ETH_Module* ETHx, uint32_t IntFlag)Clears the MMC RX Interrupt pending flag for the ETH.
Source comment
name    ETH_ClearMMCRxInterruptFlag.
fun     Clears the MMC RX Interrupt pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MMCRX_INT_FLAG_BCGPIS
          - ETH_MMCRX_INT_FLAG_MCGPIS
          - ETH_MMCRX_INT_FLAG_CRCERPIS
          - ETH_MMCRX_INT_FLAG_ALGNERPIS
          - ETH_MMCRX_INT_FLAG_UCGPIS
return  none
void ETH_ClearMMCTxInterruptFlag(ETH_Module* ETHx, uint32_t IntFlag)Clears the MMC TX Interrupt pending flag for the ETH.
Source comment
name    ETH_ClearMMCTxInterruptFlag.
fun     Clears the MMC TX Interrupt pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MMCTX_INT_FLAG_SCOLGPIS
          - ETH_MMCTX_INT_FLAG_MCOLGPIS
          - ETH_MMCTX_INT_FLAG_GPKTIS
return  none
void ETH_ClearMACTimeStampFlag(ETH_Module* ETHx, uint32_t Flag)Clears the MAC Time Stamp pending flag for the ETH.
Source comment
name    ETH_ClearMACTimeStampFlag.
fun     Clears the MAC Time Stamp pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_MACTS_FLAG_SOVF
          - ETH_MACTS_FLAG_TARGT0
          - ETH_MACTS_FLAG_TRGTERR0
          - ETH_MACTS_FLAG_TXTSSIS
return  none
void ETH_ClearMACTxRxFlag(ETH_Module* ETHx, uint32_t Flag)Clears the MAC TX RX pending flag for the ETH.
Source comment
name    ETH_ClearMACTxRxFlag.
fun     Clears the MAC TX RX pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_MACTX_FLAG_TJT
          - ETH_MACTX_FLAG_NCARR
          - ETH_MACTX_FLAG_LCARR
          - ETH_MACTX_FLAG_EXDEF
          - ETH_MACTX_FLAG_LCOL
          - ETH_MACTX_FLAG_EXCOL
          - ETH_MACRX_FLAG_RWT
return  none
void ETH_ClearMACMDIOInterruptFlag(ETH_Module* ETHx)Clears the MAC MDIO Interrupt pending flag for the ETH.
Source comment
name    ETH_ClearMACMDIOInterruptFlag.
fun     Clears the MAC MDIO Interrupt pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
return  none
void ETH_ClearMTLQueueInterruptFlag(ETH_Module* ETHx, uint32_t IntFlag)Clears the MTL Queue Interrupt pending flag for the ETH.
Source comment
name    ETH_ClearMTLQueueInterruptFlag.
fun     Clears the MTL Queue Interrupt pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_MTLTXQUEUE_INT_FLAG_UNFIS
          - ETH_MTLRXQUEUE_INT_FLAG_OVFIS
return  none
void ETH_ClearDMACh0Flag(ETH_Module* ETHx, uint32_t Flag)Clears the DMA Channel 0 pending flag for the ETH.
Source comment
name    ETH_ClearDMACh0Flag.
fun     Clears the DMA Channel 0 pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Flag (The input parameters must be the following values):
          - ETH_DMACH0_FLAG_TI
          - ETH_DMACH0_FLAG_TPS
          - ETH_DMACH0_FLAG_TBU
          - ETH_DMACH0_FLAG_RI
          - ETH_DMACH0_FLAG_RBU
          - ETH_DMACH0_FLAG_RPS
          - ETH_DMACH0_FLAG_RWT
          - ETH_DMACH0_FLAG_ETI
          - ETH_DMACH0_FLAG_ERI
          - ETH_DMACH0_FLAG_FBE
          - ETH_DMACH0_FLAG_CDE
          - ETH_DMACH0_FLAG_AIS
          - ETH_DMACH0_FLAG_NIS
return  none
void ETH_ClearDMACh0InterruptFlag(ETH_Module* ETHx, uint32_t IntFlag)Clears the DMA Channel 0 Interrupt pending flag for the ETH.
Source comment
name    ETH_ClearDMACh0InterruptFlag.
fun     Clears the DMA Channel 0 Interrupt pending flag for the ETH.
param   ETHx (The input parameters must be the following values):
          - ETH
param   IntFlag (The input parameters must be the following values):
          - ETH_DMACH0_INT_FLAG_TI
          - ETH_DMACH0_INT_FLAG_TPS
          - ETH_DMACH0_INT_FLAG_TBU
          - ETH_DMACH0_INT_FLAG_RI
          - ETH_DMACH0_INT_FLAG_RBU
          - ETH_DMACH0_INT_FLAG_RPS
          - ETH_DMACH0_INT_FLAG_RWT
          - ETH_DMACH0_INT_FLAG_ETI
          - ETH_DMACH0_INT_FLAG_ERI
          - ETH_DMACH0_INT_FLAG_FBE
          - ETH_DMACH0_INT_FLAG_CDE
          - ETH_DMACH0_INT_FLAG_AIS
          - ETH_DMACH0_INT_FLAG_NIS
return  none
void ETH_ConfigMACInterrupt(ETH_Module* ETHx, uint32_t Interrupt, FunctionalStatus Cmd)Enables or disables the specified ETH MAC interrupts.
Source comment
name    ETH_ConfigMACInterrupt.
fun     Enables or disables the specified ETH MAC interrupts.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Interrupt (The input parameters must be the following values):
          - ETH_MAC_INT_PHY
          - ETH_MAC_INT_PMT
          - ETH_MAC_INT_TS
          - ETH_MAC_INT_TX
          - ETH_MAC_INT_RX
          - ETH_MAC_INT_MDIO
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_ConfigMMCRxInterrupt(ETH_Module* ETHx, uint32_t Interrupt, FunctionalStatus Cmd)Enables or disables the specified ETH MMC RX interrupts.
Source comment
name    ETH_ConfigMMCRxInterrupt.
fun     Enables or disables the specified ETH MMC RX interrupts.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Interrupt (The input parameters must be the following values):
          - ETH_MMCRX_INT_BCGPIM
          - ETH_MMCRX_INT_MCGPIM
          - ETH_MMCRX_INT_CRCERPIM
          - ETH_MMCRX_INT_ALGNERPIM
          - ETH_MMCRX_INT_UCGPIM
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_ConfigMMCTxInterrupt(ETH_Module* ETHx, uint32_t Interrupt, FunctionalStatus Cmd)Enables or disables the specified ETH MMC TX interrupts.
Source comment
name    ETH_ConfigMMCTxInterrupt.
fun     Enables or disables the specified ETH MMC TX interrupts.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Interrupt (The input parameters must be the following values):
          - ETH_MMCTX_INT_SCOLGPIM
          - ETH_MMCTX_INT_MCOLGPIM
          - ETH_MMCTX_INT_GPKTIM
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_ConfigMTLQueueInterrupt(ETH_Module* ETHx, uint32_t Interrupt, FunctionalStatus Cmd)Enables or disables the specified ETH MTL Queue interrupts.
Source comment
name    ETH_ConfigMTLQueueInterrupt.
fun     Enables or disables the specified ETH MTL Queue interrupts.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Interrupt (The input parameters must be the following values):
          - ETH_MTLTXQUEUE_INT_UIE
          - ETH_MTLRXQUEUE_INT_OIE
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none
void ETH_ConfigDMACh0Interrupt(ETH_Module* ETHx, uint32_t Interrupt, FunctionalStatus Cmd)Enables or disables the specified ETH DMA Channel 0 interrupts.
Source comment
name    ETH_ConfigDMACh0Interrupt.
fun     Enables or disables the specified ETH DMA Channel 0 interrupts.
param   ETHx (The input parameters must be the following values):
          - ETH
param   Interrupt (The input parameters must be the following values):
          - ETH_DMACH0_INT_TI
          - ETH_DMACH0_INT_TPS
          - ETH_DMACH0_INT_TBU
          - ETH_DMACH0_INT_RI
          - ETH_DMACH0_INT_RBU
          - ETH_DMACH0_INT_RPS
          - ETH_DMACH0_INT_RWT
          - ETH_DMACH0_INT_ETI
          - ETH_DMACH0_INT_ERI
          - ETH_DMACH0_INT_FBE
          - ETH_DMACH0_INT_CDE
          - ETH_DMACH0_INT_AIS
          - ETH_DMACH0_INT_NIS
param   Cmd (The input parameters must be the following values):
          - ENABLE
          - DISABLE
return  none

5.10.3 Demo descriptions

This section describes each of the 12 ETH examples.

5.10.3.1 HTTP_Client HTTP client fetches a web page

Example directory: projects/n32h49x_EVAL/examples/ETH/HTTP_Client/

Initialize the serial port and network interface→Resolve the target host name→Establish a TCP connection→Send the HTTP GET request→Print the server response

Item Source analysis
Function Acts as an HTTP client and sends a GET request to the configured host name.
Receives and prints the server response.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/http_client.c: the SOCKET and NETCONN client implementations.
inc/http_client.h, inc/main.h: macros and task declarations.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
HOST_NAME is www.example.com;
enable USE_NETCONN or USE_SOCKET.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
NetworkInitialize calls tcpip_init, netif_add, netif_set_default and netif_set_up in turn.
The task prints the local IP and calls http_client_init to create the client thread.
The client thread resolves the name with dns_gethostbyname, sends the GET request with send, and receives the response with recv.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification The serial port prints the local IP and the HTTP response header.
If the external site is unreachable, set USE_PHPSTUDY to 1 and run a local server.
Use note HOST_NAME must match the address it resolves to;
update both when changing the host.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example connects lwIP to the ETH driver under FreeRTOS and has an application thread issue one HTTP request.

Data path: DNS callback -> RemoteAddr -> connect -> send the GET request held in SendBuff -> recv the response -> print it over the serial port

1. The task initializes the network before creating the client thread. NetworkApplicationTask calls NetworkInitialize to add the network interface, prints the address, then calls http_client_init.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
#if LWIP_DHCP
        log_info("The IP address is dynamically assigned by DHCP, if you need to use a static IP address, please redefine LWIP_DHCP in the lwipopts.h file\n");
        /* Enable DHCP and determine whether it is enabled successfully */
        if (dhcp_start(&sNetif) == ERR_OK)
        {
            log_info("DHCP initialization successful, please wait...\n");
            /* Wait for IP address assignment to complete */
            while (ip_addr_cmp(&sNetif.ip_addr, &ipaddr))
            {
                /* System can switch to other tasks */
                vTaskDelay(5);
            }
        }
        else
        {
            log_info("DHCP initialization failure\n");
        }
#endif
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize HTTP client task */
    http_client_init();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. The name is resolved in a non-blocking way. The SOCKET thread calls dns_gethostbyname; a local cache hit returns the address directly, otherwise the callback stores it into RemoteAddr.

src/http_client.csrc/http_client.c · http_client_socket_thread
#if LWIP_DNS && (!USE_PHPSTUDY)
    ip4_addr_t dnsAddr;
    /* Non-blocking domain name resolution */
    err_t Err = dns_gethostbyname(HOST_NAME, &dnsAddr, http_dns_found_callback, NULL);
    /* Get IP from local resolver cache */
    if (Err == ERR_OK)
    {
        RemoteAddr.addr = dnsAddr.addr;
    }
    /* Get IP from DNS server */
    else if (Err == ERR_INPROGRESS)
    {
        while (RemoteAddr.addr == 0)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }
    else
    {
        printf("dns_gethostbyname err, err code: %d\n", Err);
    }
#else
    /* Set the server IP address */
    IP4_ADDR(&RemoteAddr, REMOTE_IP_ADDR0, REMOTE_IP_ADDR1, REMOTE_IP_ADDR2, REMOTE_IP_ADDR3);

3. Thread creation is wrapped in an init function. http_client_init chooses the SOCKET or the NETCONN client thread according to the USE_NETCONN and USE_SOCKET macros.

src/http_client.csrc/http_client.c · http_client_init
void http_client_init(void)
{
    printf("\r\nCall %s\r\n", __FUNCTION__);
    printf("Set USE_NETCONN to 1 to use the NETCONN API\n");
    printf("Set USE_NETCONN to 0 to use the SOCKET API\n");

    /* Create a http client task thread */
#if USE_NETCONN
    sys_thread_new("http_client_netconn_thread", /* Task name */
                   http_client_netconn_thread,   /* Task entry function */
                   NULL,                         /* Task entry function parameter */
                   HTTP_CLIENT_TASK_STACK_SIZE,  /* Task stack size */
                   HTTP_CLIENT_TASK_PRIORITY);   /* Task priority */
#endif /* USE_NETCONN */

#if USE_SOCKET
    sys_thread_new("http_client_socket_thread",  /* Task name */
                   http_client_socket_thread,    /* Task entry function */
                   NULL,                         /* Task entry function parameter */
                   HTTP_CLIENT_TASK_STACK_SIZE,  /* Task stack size */
                   HTTP_CLIENT_TASK_PRIORITY);   /* Task priority */
#endif /* USE_SOCKET */

Corresponding source files: src/main.c, src/http_client.c

5.10.3.2 HTTP_Server HTTP server returns a web page

Example directory: projects/n32h49x_EVAL/examples/ETH/HTTP_Server/

Initialize the serial port and network interface→Listen on the local port→Accept a browser connection→Recognize the GET request→Return the built-in web page

Item Source analysis
Function Acts as an HTTP server listening on a local port.
Returns the built-in HTML page for a browser GET request.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/http_server.c: the SOCKET and NETCONN server implementations with the built-in page data.
inc/http_server.h, inc/main.h: macros and task declarations.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The server port is set by LOCAL_PORT;
enable USE_NETCONN or USE_SOCKET.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
NetworkInitialize calls tcpip_init, netif_add, netif_set_default and netif_set_up in turn.
The task prints the local IP and calls http_server_init to create the server thread.
The server thread binds the port and listens;
when a packet starts with GET it writes the response header and then the page data.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification A browser opens the board IP 192.168.0.32 and shows the built-in page.
The serial port prints the local IP information.
Use note The PC and the board must be on the same subnet.
The page is static;
edit the page data array in http_server.c to change it.
Core-code walkthrough and porting

The example turns the board into a minimal HTTP server that returns a fixed page for every GET request.

Data path: read fills the request buffer -> test whether the first bytes are GET -> write the htmlHeader -> write the htmlData -> the browser renders the page

1. The task initializes the network before creating the server thread. NetworkApplicationTask finishes network initialization and then calls http_server_init.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
#if LWIP_DHCP
        log_info("The IP address is dynamically assigned by DHCP, if you need to use a static IP address, please redefine LWIP_DHCP in the lwipopts.h file\n");
        /* Enable DHCP and determine whether it is enabled successfully */
        if (dhcp_start(&sNetif) == ERR_OK)
        {
            log_info("DHCP initialization successful, please wait...\n");
            /* Wait for IP address assignment to complete */
            while (ip_addr_cmp(&sNetif.ip_addr, &ipaddr))
            {
                /* System can switch to other tasks */
                vTaskDelay(5);
            }
        }
        else
        {
            log_info("DHCP initialization failure\n");
        }
#endif
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize HTTP server task */
    http_server_init();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. A GET request is recognized and the page is returned. The server thread reads the packet and checks whether the first bytes are GET followed by a slash; on a match it writes the response header and then the page data.

src/http_server.csrc/http_server.c · http_server_socket_thread
                /* Check if it is an HTTP GET command packet */
                if ((Len >= 5) && (RecvBuf[0] == 'G') && (RecvBuf[1] == 'E') && (RecvBuf[2] == 'T') && (RecvBuf[3] == ' ') && (RecvBuf[4] == '/'))
                {
                    /* Sends the HTTP HTML response header */
                    write(SockNew, htmlHeader, sizeof(htmlHeader) - 1);

                    /* Sends HTTP HTML data */
                    write(SockNew, htmlData, sizeof(htmlData) - 1);

3. Thread creation is wrapped in an init function. http_server_init chooses the SOCKET or the NETCONN server thread according to the macros.

src/http_server.csrc/http_server.c · http_server_init
void http_server_init(void)
{
    printf("\r\nCall %s\r\n", __FUNCTION__);
    printf("Set USE_NETCONN to 1 to use the NETCONN API\n");
    printf("Set USE_NETCONN to 0 to use the SOCKET API\n");
    /* Create a HTTP server task thread */
#if USE_NETCONN
    sys_thread_new("http_server_netconn_thread", /* Task name */
                   http_server_netconn_thread,   /* Task entry function */
                   NULL,                         /* Task entry function parameter */
                   HTTP_SERVER_TASK_STACK_SIZE,  /* Task stack size */
                   HTTP_SERVER_TASK_PRIORITY);   /* Task priority */
#endif /* USE_NETCONN */

#if USE_SOCKET
    sys_thread_new("http_server_socket_thread",  /* Task name */
                   http_server_socket_thread,    /* Task entry function */
                   NULL,                         /* Task entry function parameter */
                   HTTP_SERVER_TASK_STACK_SIZE,  /* Task stack size */
                   HTTP_SERVER_TASK_PRIORITY);   /* Task priority */
#endif /* USE_SOCKET */

Corresponding source files: src/main.c, src/http_server.c

5.10.3.3 iPerf_Netconn iPerf throughput test (NETCONN)

Example directory: projects/n32h49x_EVAL/examples/ETH/iPerf_Netconn/

Initialize the serial port and network interface→Print the menu and read a serial choice→Create the server or client accordingly→Continuously send and receive fixed-size data→Measure throughput with JPerf

Item Source analysis
Function Implements an iPerf server and client over the NETCONN interface.
Server mode measures receive throughput;
client mode measures transmit throughput.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/iperf.c: the NETCONN server and client threads plus mode selection.
inc/iperf.h, inc/main.h: macros and task declarations.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The port is set by IPERF_PORT;
each test uses IPERF_DATA_LEN bytes.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
The task prints the local IP and then calls LwIP_iPerfInit.
LwIP_iPerfModeSelect reads a character S or C from the serial port to pick the mode.
The server thread listens with netconn_listen and receives in a loop;
the client thread sends fixed-size buffers with netconn_write.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification JPerf connects to the board IP and IPERF_PORT for the throughput test.
The serial port prints the mode menu and connection information.
Use note Reset the board before switching between server and client mode.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements iPerf over the NETCONN interface and selects the server or client mode from the serial port.

Data path: Read S or C from the serial port -> LwIP_iPerfInit creates the matching thread -> the server receives after netconn_accept, the client sends with netconn_write -> JPerf reports the rate

1. The task initializes the network before starting the throughput test. NetworkApplicationTask finishes network initialization and then calls LwIP_iPerfInit.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize iperf task */
    LwIP_iPerfInit();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. A serial character selects the working mode. LwIP_iPerfModeSelect prints a menu and reads one character; S sets server mode and C sets client mode.

src/iperf.csrc/iperf.c · LwIP_iPerfModeSelect
static bool LwIP_iPerfModeSelect(bool *serverMode, bool *clientMode)
{
    char code;

    printf("\r\n");
    printf("S: TCP Server Mode\n");
    printf("C: TCP Client Mode\n");
    printf("Please enter 'S' or 'C' to select the mode: ");

    code = getchar();
    printf("%c\n", code);

    switch (code)
    {
        case 'S':
            *serverMode = true;
            *clientMode = false;
            break;

        case 'C':
            *serverMode = false;
            *clientMode = true;
            break;

        default:
            return false;
    }

    return true;

3. The server creates its connection and listens. iperf_server_netconn_thread creates the connection, binds IPERF_PORT and starts listening.

src/iperf.csrc/iperf.c · iperf_server_netconn_thread
    Conn = netconn_new(NETCONN_TCP);
    LWIP_ERROR("Invalid Conn\n", (Conn != NULL), while (1););
    /* Bind local port and IP address */
    netconn_bind(Conn, IP_ADDR_ANY, IPERF_PORT);
#endif /* LWIP_IPV6 */

    printf("Local port: %d\n", IPERF_PORT);
    printf("Start listening...\n");

    /* Tell connection to go into listening mode */
    netconn_listen(Conn);

Corresponding source files: src/main.c, src/iperf.c

5.10.3.4 iPerf_Socket iPerf throughput test (SOCKET)

Example directory: projects/n32h49x_EVAL/examples/ETH/iPerf_Socket/

Initialize the serial port and network interface→Print the menu and read a serial choice→Create the server or client accordingly→Continuously send and receive fixed-size data→Measure throughput with JPerf

Item Source analysis
Function Implements an iPerf server and client over the SOCKET interface.
Server mode measures receive throughput;
client mode measures transmit throughput.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/iperf.c: the SOCKET server and client threads plus mode selection.
inc/iperf.h, inc/main.h: macros and task declarations.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The port is set by IPERF_PORT;
the send buffer is IPERF_DATA_LEN bytes from pvPortMalloc.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
The task prints the local IP and then calls LwIP_iPerfInit.
LwIP_iPerfModeSelect reads a character from the serial port to pick the mode.
The server thread uses socket and listen then reads in a loop;
the client thread sends fixed-size buffers with send.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification JPerf connects to the board IP and IPERF_PORT for the throughput test.
The serial port prints the mode menu and connection information.
Use note Reset the board before switching between server and client mode.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements iPerf over the SOCKET interface; the rest of the structure matches the NETCONN version.

Data path: Read S or C from the serial port -> LwIP_iPerfInit creates the matching thread -> the server receives after accept, the client sends with send -> JPerf reports the rate

1. The task initializes the network before starting the throughput test. NetworkApplicationTask finishes network initialization and then calls LwIP_iPerfInit.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize iperf task */
    LwIP_iPerfInit();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. A serial character selects the working mode. LwIP_iPerfModeSelect prints a menu and reads one character, returning whether the choice was accepted.

src/iperf.csrc/iperf.c · LwIP_iPerfModeSelect
static bool LwIP_iPerfModeSelect(bool *serverMode, bool *clientMode)
{
    char code;

    printf("\r\n");
    printf("S: TCP Server Mode\n");
    printf("C: TCP Client Mode\n");
    printf("Please enter 'S' or 'C' to select the mode: ");

    code = getchar();
    printf("%c\n", code);

    switch (code)
    {
        case 'S':
            *serverMode = true;
            *clientMode = false;
            break;

        case 'C':
            *serverMode = false;
            *clientMode = true;
            break;

        default:
            return false;
    }

    return true;

3. The server creates its socket and listens. iperf_server_socket_thread creates a socket, binds the port and starts listening.

src/iperf.csrc/iperf.c · iperf_server_socket_thread
    Sock = socket(AF_INET, SOCK_STREAM, 0);
    if (Sock < 0)
    {
        printf("socket error\n");
        while (1)
        {
        }
    }

    /* Set the server address information */
    ServerAddr.sin_family = AF_INET;
    ServerAddr.sin_addr.s_addr = INADDR_ANY;
    ServerAddr.sin_port = htons(IPERF_PORT);

    /* Bind local port and IP address */
    if (bind(Sock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr)) != 0)
    {
        printf("Unable to bind\n");
        closesocket(Sock);
        free(pData);
        while (1)
        {
        }
    }

    printf("Local port: %d\n", IPERF_PORT);
    printf("Start listening...\n");

    /* Tell connection to go into listening mode */
    if (listen(Sock, SOCKET_LISTEN_BACKLOG) != 0)

Corresponding source files: src/main.c, src/iperf.c

5.10.3.5 NetBIOS NetBIOS name service (NBNS)

Example directory: projects/n32h49x_EVAL/examples/ETH/NetBIOS/

Initialize the system clock and SysTick→Configure the network interface and lwIP→Register the NetBIOS name→Answer name query broadcasts→Ping the device by host name

Item Source analysis
Function Answers name queries as a NetBIOS name server.
Lets the device be reached and pinged by host name.
Source files src/main.c: network initialization and the main loop without an operating system.
src/netbiosns.c: the NetBIOS name service implementation.
inc/main.h: macros such as NETBIOS_HOST_NAME.
bsp/ethernetif.c, bsp/lwipopts.h: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
NETBIOS_HOST_NAME must be shorter than 15 characters.
Program and data path main configures a 1ms SysTick time base and calls NetworkInitialize.
NetworkInitialize calls lwip_init and netif_add, mounting ethernet_input as the input function.
It then calls netbiosns_init and netbiosns_set_name to register the name.
The main loop polls ReceiveDataFlag to call ethernetif_input and periodically calls sys_check_timeouts.
Main APIs ETH_Init, ETH_Start, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Ping the board by host name from a PC.
The serial port prints the local IP and the NetBIOS name.
Use note The host name must be shorter than 15 characters.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example lets lwIP answer NetBIOS name queries without an operating system so the device can be reached by name.

Data path: main configures SysTick -> NetworkInitialize -> netbiosns_init binds the NBNS port -> the main loop runs ethernetif_input and sys_check_timeouts -> a name query is answered with a reply

1. Startup, time base and network initialization. main prints a startup message, reads the system clock, configures SysTick as a 1ms time base and sets its interrupt priority, then calls NetworkInitialize to bring up lwIP and the network interface.

src/main.csrc/main.c · main
    log_info("ETH no RTOS NetBIOS Name Service (NBNS) demo go...\r\n");

    /* Get clock frequency value */
    RCC_GetClocksFreqValue(&clk);

    /* Configure SysTick to generate a 1ms time base */
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
    SysTick_Config(clk.HclkFreq / 1000);
    NVIC_SetPriority(SysTick_IRQn, 1);

2. lwIP initialization and interface registration. NetworkInitialize writes the IP, mask and gateway, calls lwip_init to initialize the stack, and uses netif_add to register the interface with ethernet_input mounted as the input function.

src/main.csrc/main.c · NetworkInitialize
    IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
    IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
    IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);

    /* Initilialize the LwIP stack without RTOS */
    lwip_init();

    /* add the network interface (IPv4/IPv6) without RTOS */
    netif_add(&sNetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

    /* Registers the default network interface */
    netif_set_default(&sNetif);

3. NetBIOS name registration and polling. main calls netbiosns_init and netbiosns_set_name to register the name, then in the loop checks ReceiveDataFlag to call ethernetif_input and periodically calls sys_check_timeouts.

src/main.csrc/main.c · main
    netbiosns_init();
    /* Note that the hostname must be less than 15 characters */
    netbiosns_set_name(NETBIOS_HOST_NAME);

    log_info("Local NetBIOS name: %s\n", NETBIOS_HOST_NAME);
    log_info("You can test the ping command with this name\n");

    while (1)
    {
        if (ReceiveDataFlag)
        {
            ReceiveDataFlag = 0;

            /* Receive data and LwIP process */
            ethernetif_input(&sNetif);
        }

        /* Handling LwIP timeout */
        sys_check_timeouts();

Corresponding source files: src/main.c

5.10.3.6 PING Bare-metal ping reply (no OS)

Example directory: projects/n32h49x_EVAL/examples/ETH/PING/

Initialize the system clock and SysTick→Configure the network interface and lwIP→Poll the receive flag in the main loop→Call the lwIP timeout handler→Answer ping requests

Item Source analysis
Function Verifies basic lwIP and ETH transfer without an operating system.
Answers ping requests from a PC.
Source files src/main.c: network initialization, the SysTick time base and the main loop.
inc/main.h: macros for IP, gateway, port and the RMII pins.
bsp/ethernetif.c, bsp/lwipopts.h: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
SysTick is configured as a 1ms time base for lwIP.
Program and data path main configures SysTick as a 1ms time base and sets its priority.
NetworkInitialize calls lwip_init, netif_add, netif_set_default and netif_set_up, mounting ethernet_input.
The main loop checks ReceiveDataFlag;
when set it clears the flag and calls ethernetif_input.
At the end of the loop it calls sys_check_timeouts to process lwIP timer events.
Main APIs ETH_Init, ETH_Start, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Run ping 192.168.0.32 from a PC;
replies should come back.
The serial port prints the local IP information.
Use note Without an operating system you must provide the sys_now time base yourself.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example is a minimal lwIP port without an operating system that transfers data by polling in the main loop.

Data path: SysTick produces a 1ms time base -> sys_now returns it -> the main loop receives with ethernetif_input -> sys_check_timeouts handles timeouts -> a ping reply is sent

1. A 1ms time base is created. main reads the clock frequency and uses SysTick to produce a 1ms interrupt for the lwIP timeout mechanism.

src/main.csrc/main.c · main
    RCC_GetClocksFreqValue(&clk);

    /* Configure SysTick to generate a 1ms time base */
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
    SysTick_Config(clk.HclkFreq / 1000);
    NVIC_SetPriority(SysTick_IRQn, 1);

2. The main loop polls for reception and handles timeouts. When the receive flag is set it is cleared before ethernetif_input, and sys_check_timeouts follows.

src/main.csrc/main.c · main
        if (ReceiveDataFlag)
        {
            ReceiveDataFlag = 0;

            /* Receive data and LwIP process */
            ethernetif_input(&sNetif);
        }

        /* Handling LwIP timeout */
        sys_check_timeouts();

3. The network interface is added without an operating system. NetworkInitialize starts the stack with lwip_init and passes ethernet_input as the input function of netif_add.

src/main.csrc/main.c · NetworkInitialize
void NetworkInitialize(void)
{
    /* IP addresses initialization */
    IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
    IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
    IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);

    /* Initilialize the LwIP stack without RTOS */
    lwip_init();

    /* add the network interface (IPv4/IPv6) without RTOS */
    netif_add(&sNetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

    /* Registers the default network interface */
    netif_set_default(&sNetif);

    if (netif_is_link_up(&sNetif))
    {
        /* When the netif is fully configured this function must be called */
        netif_set_up(&sNetif);
    }
    else
    {
        /* When the netif link is down this function must be called */
        netif_set_down(&sNetif);

Corresponding source files: src/main.c

5.10.3.7 TCP_Client TCP echo client (with OS)

Example directory: projects/n32h49x_EVAL/examples/ETH/TCP_Client/

Initialize the serial port and network interface→Connect to the remote server→Receive data in a blocking call→Build the echo string→Send it back to the server

Item Source analysis
Function Acts as a TCP client connecting to a remote server.
Adds a prefix to received data and sends it back to the server.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/tcp_client.c: the SOCKET and NETCONN client implementations.
inc/tcp_client.h, inc/main.h: macros for the remote IP and port.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The server address is set by REMOTE_IP_ADDR0~3 and REMOTE_PORT.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
The task prints the local IP and calls tcp_client_init to create the client thread.
The client thread connects with connect and then blocks on recv.
Received data is wrapped with snprintf and sent with send.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Set up a TCP server on a PC with a debug assistant using the same port as REMOTE_PORT.
Data sent by the server comes back with the added prefix.
Use note REMOTE_IP_ADDR0~3 must point at the real server address.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements a TCP echo client under FreeRTOS that adds a prefix before sending data back.

Data path: connect to the server -> recv blocks for data -> snprintf adds the prefix -> send returns it -> reconnect after a delay on disconnect

1. The task initializes the network before creating the client thread. NetworkApplicationTask finishes network initialization and then calls tcp_client_init.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize TCP client task */
    tcp_client_init();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. The server address is assembled from macros. The SOCKET thread writes the remote IP and port into a sockaddr_in structure for the later connect.

src/tcp_client.csrc/tcp_client.c · tcp_client_socket_thread
    /* Set the server IP address */
    IP4_ADDR(&IpAddr, REMOTE_IP_ADDR0, REMOTE_IP_ADDR1, REMOTE_IP_ADDR2, REMOTE_IP_ADDR3);
    printf("Server IP: %d.%d.%d.%d\n", REMOTE_IP_ADDR0, REMOTE_IP_ADDR1, REMOTE_IP_ADDR2, REMOTE_IP_ADDR3);
    printf("Server Port: %d\n", REMOTE_PORT);

    /* Set the server address information */
    ServerAddr.sin_family = AF_INET;
    ServerAddr.sin_addr.s_addr = IpAddr.addr;
    ServerAddr.sin_port = htons(REMOTE_PORT);

3. Thread creation is wrapped in an init function. tcp_client_init chooses the SOCKET or the NETCONN client thread according to the macros.

src/tcp_client.csrc/tcp_client.c · tcp_client_init
void tcp_client_init(void)
{
    printf("\r\nCall %s\r\n", __FUNCTION__);
    printf("Set USE_NETCONN to 1 to use the NETCONN API\n");
    printf("Set USE_NETCONN to 0 to use the SOCKET API\n");

    /* Create a TCP client task thread */
#if USE_NETCONN
    sys_thread_new("tcp_client_netconn_thread", /* Task name */
                   tcp_client_netconn_thread,   /* Task entry function */
                   NULL,                        /* Task entry function parameter */
                   TCP_CLIENT_TASK_STACK_SIZE,  /* Task stack size */
                   TCP_CLIENT_TASK_PRIORITY);   /* Task priority */
#endif /* USE_NETCONN */

#if USE_SOCKET
    sys_thread_new("tcp_client_socket_thread",  /* Task name */
                   tcp_client_socket_thread,    /* Task entry function */
                   NULL,                        /* Task entry function parameter */
                   TCP_CLIENT_TASK_STACK_SIZE,  /* Task stack size */
                   TCP_CLIENT_TASK_PRIORITY);   /* Task priority */
#endif /* USE_SOCKET */

Corresponding source files: src/main.c, src/tcp_client.c

5.10.3.8 TCP_Client_RAW TCP echo client (RAW)

Example directory: projects/n32h49x_EVAL/examples/ETH/TCP_Client_RAW/

Initialize the system clock and SysTick→Configure the network interface and lwIP→Connect to the remote server→Register the connect and receive callbacks→Echo and reconnect after a disconnect

Item Source analysis
Function Implements a TCP echo client with the RAW API.
Sends messages periodically after connecting and echoes any received data.
Source files src/main.c: network initialization and the main loop without an operating system.
src/tcp_client.c: the RAW callbacks and connection management.
inc/tcp_client.h, inc/main.h: macros for the remote IP and port.
bsp/ethernetif.c, bsp/lwipopts.h: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The server address is set by REMOTE_IP_ADDR0~3 and REMOTE_PORT.
Program and data path main configures SysTick, calls NetworkInitialize and then tcp_client_init.
tcp_client_init creates a control block and calls tcp_connect.
The connect callback registers the periodic send and receive callbacks.
The main loop calls ethernetif_input and sys_check_timeouts to drive the stack.
Main APIs ETH_Init, ETH_Start, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Set up a TCP server on a PC with a debug assistant.
After connecting, the client sends messages periodically and server data is echoed.
Use note On a disconnect the callback calls the init function again to reconnect.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements an OS-free echo client with the lwIP RAW API, driven entirely by callbacks.

Data path: tcp_connect starts the connection -> the connect callback registers the periodic and receive callbacks -> the periodic callback sends with tcp_write and the receive callback echoes -> the error callback reconnects

1. The main loop drives the stack. When the receive flag is set it calls ethernetif_input and then sys_check_timeouts.

src/main.csrc/main.c · main
        if (ReceiveDataFlag)
        {
            ReceiveDataFlag = 0;

            /* Receive data and LwIP process */
            ethernetif_input(&sNetif);
        }

        /* Handling LwIP timeout */
        sys_check_timeouts();

2. Callbacks are registered once the connection is up. tcp_connect_callback registers the periodic send callback and the receive callback after the connection is established.

src/tcp_client.csrc/tcp_client.c · tcp_connect_callback
static err_t tcp_connect_callback(void *arg, struct tcp_pcb *tpcb, err_t err)
{
    LWIP_UNUSED_ARG(arg);

    if ((err != ERR_OK) || (tpcb == NULL))
    {
        return ERR_VAL;
    }

    printf("Connect successful!!\n");

    /* Registers a callback function for periodic processing */
    tcp_poll(tpcb, tcp_poll_callback, 10);

    /* Registers a callback function for receiving */
    tcp_recv(tpcb, tcp_recv_callback);

3. The connection is started from the init function. tcp_client_init creates a control block, calls tcp_connect and registers the error callback.

src/tcp_client.csrc/tcp_client.c · tcp_client_init
void tcp_client_init(void)
{
    ip4_addr_t RemoteIpAddr;

    /* Set the server IP address */
    IP4_ADDR(&RemoteIpAddr, REMOTE_IP_ADDR0, REMOTE_IP_ADDR1, REMOTE_IP_ADDR2, REMOTE_IP_ADDR3);

    /* Creates a new TCP protocol control block */
    tcp_raw_pcb = tcp_new();

    if (FirstInitFlag)
    {
        FirstInitFlag = 0U;
        printf("Server IP: %d.%d.%d.%d\n", REMOTE_IP_ADDR0, REMOTE_IP_ADDR1, REMOTE_IP_ADDR2, REMOTE_IP_ADDR3);
        printf("Try to connect to the server...\n");
    }

    /* Try to connect to the server */
    tcp_connect(tcp_raw_pcb, &RemoteIpAddr, REMOTE_PORT, tcp_connect_callback);

    /* Registers a callback function for error handling */
    tcp_err(tcp_raw_pcb, tcp_err_callback);

Corresponding source files: src/main.c, src/tcp_client.c

5.10.3.9 TCP_Server TCP echo server (with OS)

Example directory: projects/n32h49x_EVAL/examples/ETH/TCP_Server/

Initialize the serial port and network interface→Bind the local port and listen→Accept a client connection→Receive data in a blocking call→Send the data straight back

Item Source analysis
Function Acts as a TCP server listening on a local port.
Sends every received byte straight back to the client.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/tcp_server.c: the SOCKET and NETCONN server implementations.
inc/tcp_server.h, inc/main.h: macros such as the local port.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The listening port is set by LOCAL_PORT.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
The task prints the local IP and calls tcp_server_init to create the server thread.
The server thread creates a socket, binds the port and starts listening.
After accepting a connection it blocks on read and writes the data back with write.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Connect to 192.168.0.32 on LOCAL_PORT from a PC debug assistant.
The data you send is echoed unchanged.
Use note LOCAL_PORT must not clash with an already used port.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements a TCP echo server under FreeRTOS that returns received data unchanged.

Data path: socket and bind set the port -> listen starts listening -> accept takes a connection -> read receives -> write sends the same bytes back

1. The task initializes the network before creating the server thread. NetworkApplicationTask finishes network initialization and then calls tcp_server_init.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize TCP server task */
    tcp_server_init();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. The socket is created and listening starts. The SOCKET thread creates a socket, binds the port and calls listen.

src/tcp_server.csrc/tcp_server.c · tcp_server_socket_thread
    /* Creates a socket */
    Sock = socket(AF_INET, SOCK_STREAM, 0);
    if (Sock < 0)
    {
        printf("socket error\n");
        while (1);
    }

    /* Set the server address information */
    ServerAddr.sin_family = AF_INET;
    ServerAddr.sin_addr.s_addr = INADDR_ANY;
    ServerAddr.sin_port = htons(LOCAL_PORT);

    /* Bind local port and IP address */
    if (bind(Sock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr)) != 0)
    {
        printf("Unable to bind\n");
        closesocket(Sock);
        free(pData);
        while (1);
    }

    printf("Local port: %d\n", LOCAL_PORT);
    printf("Start listening...\n");

    /* Tell connection to go into listening mode */
    if (listen(Sock, SOCKET_LISTEN_BACKLOG) != 0)

3. Thread creation is wrapped in an init function. tcp_server_init chooses the SOCKET or the NETCONN server thread according to the macros.

src/tcp_server.csrc/tcp_server.c · tcp_server_init
void tcp_server_init(void)
{
    printf("\r\nCall %s\r\n", __FUNCTION__);
    printf("Set USE_NETCONN to 1 to use the NETCONN API\n");
    printf("Set USE_NETCONN to 0 to use the SOCKET API\n");
    /* Create a TCP server task thread */
#if USE_NETCONN
    sys_thread_new("tcp_server_netconn_thread", /* Task name */
                   tcp_server_netconn_thread,   /* Task entry function */
                   NULL,                        /* Task entry function parameter */
                   TCP_SERVER_TASK_STACK_SIZE,  /* Task stack size */
                   TCP_SERVER_TASK_PRIORITY);   /* Task priority */
#endif /* USE_NETCONN */

#if USE_SOCKET
    sys_thread_new("tcp_server_socket_thread",  /* Task name */
                   tcp_server_socket_thread,    /* Task entry function */
                   NULL,                        /* Task entry function parameter */
                   TCP_SERVER_TASK_STACK_SIZE,  /* Task stack size */
                   TCP_SERVER_TASK_PRIORITY);   /* Task priority */
#endif /* USE_SOCKET */

Corresponding source files: src/main.c, src/tcp_server.c

5.10.3.10 TCP_Server_RAW TCP echo server (RAW)

Example directory: projects/n32h49x_EVAL/examples/ETH/TCP_Server_RAW/

Initialize the system clock and SysTick→Configure the network interface and lwIP→Create a control block and listen→Accept and register the callbacks→Echo inside the receive callback

Item Source analysis
Function Implements a TCP echo server with the RAW API.
Sends data back from the receive callback after accepting a connection.
Source files src/main.c: network initialization and the main loop without an operating system.
src/tcp_server.c: the RAW callbacks and server initialization.
inc/tcp_server.h, inc/main.h: macros such as the local port.
bsp/ethernetif.c, bsp/lwipopts.h: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The listening port is set by LOCAL_PORT.
Program and data path main configures SysTick, calls NetworkInitialize and then tcp_server_init.
tcp_server_init creates a control block, binds the port and calls tcp_listen.
It then registers the accept callback with tcp_accept.
The main loop calls ethernetif_input and sys_check_timeouts to drive the stack.
Main APIs ETH_Init, ETH_Start, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Connect to 192.168.0.32 on LOCAL_PORT from a PC debug assistant.
The data you send is echoed unchanged.
Use note The receive callback must free the buffer with pbuf_free.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements an OS-free echo server with the lwIP RAW API, sending and receiving inside callbacks.

Data path: tcp_new and tcp_bind set the port -> tcp_listen starts listening -> tcp_accept registers the accept callback -> the receive callback echoes with tcp_write -> pbuf_free releases the buffer

1. The main loop drives the stack. When the receive flag is set it calls ethernetif_input and then sys_check_timeouts.

src/main.csrc/main.c · main
        if (ReceiveDataFlag)
        {
            ReceiveDataFlag = 0;

            /* Receive data and LwIP process */
            ethernetif_input(&sNetif);
        }

        /* Handling LwIP timeout */
        sys_check_timeouts();

2. The receive callback echoes and frees the buffer. tcp_recv_callback updates the receive window, sends the data back with tcp_write, then frees the pbuf.

src/tcp_server.csrc/tcp_server.c · tcp_recv_callback
static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
    err_t retErr = ERR_OK;

    LWIP_UNUSED_ARG(arg);

    if (tpcb == NULL)
    {
        return ERR_VAL;
    }

    /* Valid data received, sent back to remote */
    if (p != NULL)
    {
        /*Update the receive data window*/
        tcp_recved(tpcb, p->tot_len);

        /*Echo the received data*/
        tcp_write(tpcb, p->payload, p->tot_len, 1);

        memset(p->payload, 0, p->tot_len);
        pbuf_free(p);

3. The connection is created and the accept callback registered from the init function. tcp_server_init creates a control block, binds, listens and registers the accept callback.

src/tcp_server.csrc/tcp_server.c · tcp_server_init
void tcp_server_init(void)
{
    err_t err;

    /* Creates a new TCP protocol control block */
    tcp_raw_pcb = tcp_new();

    /* Bind local port and IP address */
    err = tcp_bind(tcp_raw_pcb, IP_ADDR_ANY, LOCAL_PORT);
    if (err == ERR_OK)
    {
        printf("Bind local IP address and port successful!!\n");
        printf("Local port: %d\n", LOCAL_PORT);
        /* Listen for client connections */
        tcp_raw_pcb = tcp_listen(tcp_raw_pcb);
        /* Accept the connection from the client and register the callback function */
        tcp_accept(tcp_raw_pcb, tcp_accept_callback);

Corresponding source files: src/main.c, src/tcp_server.c

5.10.3.11 UDP UDP echo (with OS)

Example directory: projects/n32h49x_EVAL/examples/ETH/UDP/

Initialize the serial port and network interface→Bind the local port→Receive a datagram in a blocking call→Build the echo string→Send it back to the source address

Item Source analysis
Function Acts as a UDP server bound to a local port.
Adds a prefix to each datagram and sends it back to the source address.
Source files src/main.c: network initialization and NetworkApplicationTask under FreeRTOS.
src/udp_echo.c: the SOCKET and NETCONN echo implementations.
inc/udp_echo.h, inc/main.h: macros such as the local port.
bsp/ethernetif.c, bsp/lwipopts.h, bsp/sys_arch.c: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The local port is set by LOCAL_PORT.
Program and data path main creates NetworkApplicationTask and starts the scheduler.
The task prints the local IP and calls udp_echo_init to create the echo thread.
The echo thread creates a socket and binds the local port.
It blocks on recvfrom, adds a prefix and replies with sendto.
Main APIs ETH_Init, ETH_StartIT, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Send UDP data to LOCAL_PORT from a PC debug assistant.
You receive the echo with the added prefix.
Use note LOCAL_PORT must not clash with an already used port.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements a UDP echo server under FreeRTOS that adds a prefix and replies to the source address.

Data path: socket and bind set the port -> recvfrom receives and returns the source address -> snprintf adds the prefix -> sendto replies

1. The task initializes the network before creating the echo thread. NetworkApplicationTask finishes network initialization and then calls udp_echo_init.

src/main.csrc/main.c · NetworkApplicationTask
static void NetworkApplicationTask(void)
{
    /* Network initialization, adding network interfaces */
    NetworkInitialize();

    /* Link successful, print local IP information */
    if (netif_is_up(&sNetif))
    {
        log_info("Network connection successful\n");
        log_info("Local IP: %s\n", ipaddr_ntoa(&sNetif.ip_addr));
        log_info("Netmask: %s\n", ipaddr_ntoa(&sNetif.netmask));
        log_info("Gateway: %s\n", ipaddr_ntoa(&sNetif.gw));
    }
    else
    {
        log_info("Network not connected\n");
        while (1)
        {
            /* System can switch to other tasks */
            vTaskDelay(5);
        }
    }

    /* Initialize UDP echo task */
    udp_echo_init();

    /* Close the task */
    vTaskDelete(NetworkApplicationTaskHandle);

2. The local address is assembled and the port bound. The SOCKET thread writes the port into a sockaddr_in structure and binds it.

src/udp_echo.csrc/udp_echo.c · udp_echo_socket_thread
    LocalAddr.sin_port = htons(LOCAL_PORT);

    printf("Local port: %d\n", LOCAL_PORT);

3. Thread creation is wrapped in an init function. udp_echo_init chooses the SOCKET or the NETCONN echo thread according to the macros.

src/udp_echo.csrc/udp_echo.c · udp_echo_init
void udp_echo_init(void)
{
    printf("\r\nCall %s\r\n", __FUNCTION__);
    printf("Set USE_NETCONN to 1 to use the NETCONN API\n");
    printf("Set USE_NETCONN to 0 to use the SOCKET API\n");

    /* Create a UDP echo task thread */
#if USE_NETCONN
    sys_thread_new("udp_echo_netconn_thread", /* Task name */
                   udp_echo_netconn_thread,   /* Task entry function */
                   NULL,                      /* Task entry function parameter */
                   UDP_ECHO_TASK_STACK_SIZE,  /* Task stack size */
                   UDP_ECHO_TASK_PRIORITY);   /* Task priority */
#endif /* USE_NETCONN */

#if USE_SOCKET
    sys_thread_new("udp_echo_socket_thread",  /* Task name */
                   udp_echo_socket_thread,    /* Task entry function */
                   NULL,                      /* Task entry function parameter */
                   UDP_ECHO_TASK_STACK_SIZE,  /* Task stack size */
                   UDP_ECHO_TASK_PRIORITY);   /* Task priority */
#endif /* USE_SOCKET */

Corresponding source files: src/main.c, src/udp_echo.c

5.10.3.12 UDP_RAW UDP echo (RAW)

Example directory: projects/n32h49x_EVAL/examples/ETH/UDP_RAW/

Initialize the system clock and SysTick→Configure the network interface and lwIP→Create a control block and bind the port→Register the receive callback→Reply unchanged from the callback

Item Source analysis
Function Implements a UDP echo with the RAW API.
Sends each datagram back to its source address from the receive callback.
Source files src/main.c: network initialization and the main loop without an operating system.
src/udp_echo.c: the RAW receive callback and initialization.
inc/udp_echo.h, inc/main.h: macros such as the local port.
bsp/ethernetif.c, bsp/lwipopts.h: the lwIP-to-ETH adaptation layer.
readme.txt: function, environment and usage notes.
MDK-ARM/, EWARM/: the Keil and IAR projects.
Key configuration Clock source HSI+PLL, system frequency 240MHz, UART PA9 at 115200 baud.
RMII uses MDC on PC1, MDIO on PA2, REF_CLK on PA1 and CRS_DV on PA7.
Default static IP 192.168.0.32, mask 255.255.255.0, gateway 192.168.0.1.
The local port is set by LOCAL_PORT.
Program and data path main configures SysTick, calls NetworkInitialize and then udp_echo_init.
udp_echo_init creates a UDP control block and binds the port with udp_bind.
It then registers the receive callback with udp_recv.
The main loop calls ethernetif_input and sys_check_timeouts to drive the stack.
Main APIs ETH_Init, ETH_Start, ETH_Transmit, ETH_GetRxDataBuffer, ETH_GetRxDataLength, ETH_BuildRxDescriptors
Verification Send UDP data to LOCAL_PORT from a PC debug assistant.
You receive the datagram back unchanged.
Use note The receive callback must free the buffer with pbuf_free.
The PC and the board must be on the same subnet.
Core-code walkthrough and porting

The example implements an OS-free UDP echo with the lwIP RAW API, sending and receiving inside a callback.

Data path: udp_new_ip_type creates the control block -> udp_bind sets the port -> udp_recv registers the callback -> the callback replies with udp_sendto -> pbuf_free releases the buffer

1. The main loop drives the stack. When the receive flag is set it calls ethernetif_input and then sys_check_timeouts.

src/main.csrc/main.c · main
        if (ReceiveDataFlag)
        {
            ReceiveDataFlag = 0;

            /* Receive data and LwIP process */
            ethernetif_input(&sNetif);
        }

        /* Handling LwIP timeout */
        sys_check_timeouts();

2. The receive callback replies unchanged. udp_recv_callback sends the whole packet back to the source address with udp_sendto, then frees the pbuf.

src/udp_echo.csrc/udp_echo.c · udp_recv_callback
static void udp_recv_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
    LWIP_UNUSED_ARG(arg);

    if (p != NULL)
    {
        /* Send received packet back to sender */
        udp_sendto(upcb, p, addr, port);
        /* Free the pbuf */
        pbuf_free(p);

3. The port is bound and the callback registered from the init function. udp_echo_init creates a control block, binds the port and registers the receive callback.

src/udp_echo.csrc/udp_echo.c · udp_echo_init
void udp_echo_init(void)
{
    err_t err;

    /* Creates a new UDP protocol control block */
    udp_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);

    /* Bind local IP address and port */
    err = udp_bind(udp_raw_pcb, IP_ANY_TYPE, LOCAL_PORT);
    if (err == ERR_OK)
    {
        printf("Bind local IP address and port successful!!\n");
        printf("Local port: %d\n", LOCAL_PORT);
        /* Registers a callback function to receive data */
        udp_recv(udp_raw_pcb, udp_recv_callback, NULL);

Corresponding source files: src/main.c, src/udp_echo.c

5.10.4 Notes and troubleshooting

The table lists the operational constraints stated in the user manual for this peripheral.

Scenario Check & action Source
Register access right after a software reset After a software reset, poll bit 0 of the DMA mode register until it clears to confirm the reset has finished before configuring registers. User manual
Descriptor ring length too small The transmit and receive descriptor ring length must be at least 4;
the descriptor addresses from the start to the end of the ring must not cross a 4GB boundary.
User manual
Enabling the MAC receiver too early If MAC initialization completes before the DMA is configured, enable the MAC receiver only after the DMA is active, otherwise received frames fill the Rx FIFO and overflow. User manual
Two writes to the same register Leave at least four destination clock cycles between two writes to the same register location (PHY receive clock, PHY transmit clock or PTP clock). User manual
Changing configuration while running Do not change duplex mode, speed, port or loopback while the MAC is transmitting or receiving;
do not change DMA settings while the DMA is active.
User manual
RMII speed and reference clock RMII supports only 10Mbps and 100Mbps and not 1000Mbps;
the RMII reference clock needs a continuous 50MHz input.
User manual
Restarting the time stamp If the time stamp is disabled by clearing bit 0 of the MAC time stamp control register, repeat all initialization steps to restart it. User manual
Nations Technologies DevKit Docs

Datasheets, SDK, driver APIs and demo guides for Nations Technologies MCU development kits, organized by chip series.

© 2026 Nations Technologies Inc. All rights reserved.粤ICP备11069485号This site uses cookie-free anonymous analytics.