static void ETH_MACDMAConfig()

in portable/NetworkInterface/STM32Fxx/stm32fxx_hal_eth.c [1127:1360]


        static void ETH_MACDMAConfig( ETH_HandleTypeDef * heth,
                                      uint32_t err )
        {
            ETH_MACInitTypeDef macinit;
            ETH_DMAInitTypeDef dmainit;
            uint32_t tmpreg = 0uL;

            if( err != ETH_SUCCESS ) /* Auto-negotiation failed */
            {
                /* Set Ethernet duplex mode to Full-duplex */
                heth->Init.DuplexMode = ETH_MODE_FULLDUPLEX;

                /* Set Ethernet speed to 100M */
                heth->Init.Speed = ETH_SPEED_100M;
            }

            /* Ethernet MAC default initialization **************************************/
            macinit.Watchdog = ETH_WATCHDOG_ENABLE;
            macinit.Jabber = ETH_JABBER_ENABLE;
            macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;
            macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;
            macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;
            macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;

            if( heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE )
            {
                macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
            }
            else
            {
                macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
            }

            macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;
            macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;
            macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;
            macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;
            macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;
            macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;
            macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;
            macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;
            macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;
            macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;
            macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
            macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;
            macinit.HashTableHigh = 0x0uL;
            macinit.HashTableLow = 0x0uL;
            macinit.PauseTime = 0x0uL;
            macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;
            macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
            macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;
            macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;
            macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;
            macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;
            macinit.VLANTagIdentifier = 0x0uL;

            /*------------------------ ETHERNET MACCR Configuration --------------------*/
            /* Get the ETHERNET MACCR value */
            tmpreg = heth->Instance->MACCR;
            /* Clear WD, PCE, PS, TE and RE bits */
            tmpreg &= ETH_MACCR_CLEAR_MASK;
            /* Set the WD bit according to ETH Watchdog value */
            /* Set the JD: bit according to ETH Jabber value */
            /* Set the IFG bit according to ETH InterFrameGap value */
            /* Set the DCRS bit according to ETH CarrierSense value */
            /* Set the FES bit according to ETH Speed value */
            /* Set the DO bit according to ETH ReceiveOwn value */
            /* Set the LM bit according to ETH LoopbackMode value */
            /* Set the DM bit according to ETH Mode value */
            /* Set the IPCO bit according to ETH ChecksumOffload value */
            /* Set the DR bit according to ETH RetryTransmission value */
            /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */
            /* Set the BL bit according to ETH BackOffLimit value */
            /* Set the DC bit according to ETH DeferralCheck value */
            tmpreg |= ( uint32_t ) ( macinit.Watchdog |
                                     macinit.Jabber |
                                     macinit.InterFrameGap |
                                     macinit.CarrierSense |
                                     heth->Init.Speed |
                                     macinit.ReceiveOwn |
                                     macinit.LoopbackMode |
                                     heth->Init.DuplexMode |
                                     macinit.ChecksumOffload |
                                     macinit.RetryTransmission |
                                     macinit.AutomaticPadCRCStrip |
                                     macinit.BackOffLimit |
                                     macinit.DeferralCheck );

            /* Write to ETHERNET MACCR */
            prvWriteMACCR( heth, tmpreg );

            /*----------------------- ETHERNET MACFFR Configuration --------------------*/
            /* Set the RA bit according to ETH ReceiveAll value */
            /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */
            /* Set the PCF bit according to ETH PassControlFrames value */
            /* Set the DBF bit according to ETH BroadcastFramesReception value */
            /* Set the DAIF bit according to ETH DestinationAddrFilter value */
            /* Set the PR bit according to ETH PromiscuousMode value */
            /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */
            /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */
            /* Write to ETHERNET MACFFR */
            heth->Instance->MACFFR = ( uint32_t ) ( macinit.ReceiveAll |
                                                    macinit.SourceAddrFilter |
                                                    macinit.PassControlFrames |
                                                    macinit.BroadcastFramesReception |
                                                    macinit.DestinationAddrFilter |
                                                    macinit.PromiscuousMode |
                                                    macinit.MulticastFramesFilter |
                                                    macinit.UnicastFramesFilter );

            /* Wait until the write operation will be taken into account:
             * at least four TX_CLK/RX_CLK clock cycles */
            tmpreg = heth->Instance->MACFFR;
            vRegisterDelay();
            heth->Instance->MACFFR = tmpreg;

            /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/
            /* Write to ETHERNET MACHTHR */
            heth->Instance->MACHTHR = ( uint32_t ) macinit.HashTableHigh;

            /* Write to ETHERNET MACHTLR */
            heth->Instance->MACHTLR = ( uint32_t ) macinit.HashTableLow;
            /*----------------------- ETHERNET MACFCR Configuration -------------------*/

            /* Get the ETHERNET MACFCR value */
            tmpreg = heth->Instance->MACFCR;
            /* Clear xx bits */
            tmpreg &= ETH_MACFCR_CLEAR_MASK;

            /* Set the PT bit according to ETH PauseTime value */
            /* Set the DZPQ bit according to ETH ZeroQuantaPause value */
            /* Set the PLT bit according to ETH PauseLowThreshold value */
            /* Set the UP bit according to ETH UnicastPauseFrameDetect value */
            /* Set the RFE bit according to ETH ReceiveFlowControl value */
            /* Set the TFE bit according to ETH TransmitFlowControl value */
            tmpreg |= ( uint32_t ) ( ( macinit.PauseTime << 16 ) |
                                     macinit.ZeroQuantaPause |
                                     macinit.PauseLowThreshold |
                                     macinit.UnicastPauseFrameDetect |
                                     macinit.ReceiveFlowControl |
                                     macinit.TransmitFlowControl );

            /* Write to ETHERNET MACFCR */
            prvWriteMACFCR( heth, tmpreg );

            /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/
            /* Set the ETV bit according to ETH VLANTagComparison value */
            /* Set the VL bit according to ETH VLANTagIdentifier value */
            heth->Instance->MACVLANTR = ( uint32_t ) ( macinit.VLANTagComparison |
                                                       macinit.VLANTagIdentifier );

            /* Wait until the write operation will be taken into account:
             * at least four TX_CLK/RX_CLK clock cycles */
            tmpreg = heth->Instance->MACVLANTR;
            vRegisterDelay();
            heth->Instance->MACVLANTR = tmpreg;

            /* Ethernet DMA default initialization ************************************/
            dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;
            dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;
            dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;
            dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;
            dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
            dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;
            dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;
            dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
            dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;
            dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;
            dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;
            dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
            dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
            dmainit.EnhancedDescriptorFormat = ETH_DMAENHANCEDDESCRIPTOR_ENABLE;
            dmainit.DescriptorSkipLength = 0x0uL;
            dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;

            /* Get the ETHERNET DMAOMR value */
            tmpreg = heth->Instance->DMAOMR;
            /* Clear xx bits */
            tmpreg &= ETH_DMAOMR_CLEAR_MASK;

            /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */
            /* Set the RSF bit according to ETH ReceiveStoreForward value */
            /* Set the DFF bit according to ETH FlushReceivedFrame value */
            /* Set the TSF bit according to ETH TransmitStoreForward value */
            /* Set the TTC bit according to ETH TransmitThresholdControl value */
            /* Set the FEF bit according to ETH ForwardErrorFrames value */
            /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */
            /* Set the RTC bit according to ETH ReceiveThresholdControl value */
            /* Set the OSF bit according to ETH SecondFrameOperate value */
            tmpreg |= ( uint32_t ) ( dmainit.DropTCPIPChecksumErrorFrame |
                                     dmainit.ReceiveStoreForward |
                                     dmainit.FlushReceivedFrame |
                                     dmainit.TransmitStoreForward |
                                     dmainit.TransmitThresholdControl |
                                     dmainit.ForwardErrorFrames |
                                     dmainit.ForwardUndersizedGoodFrames |
                                     dmainit.ReceiveThresholdControl |
                                     dmainit.SecondFrameOperate );

            /* Write to ETHERNET DMAOMR */
            prvWriteDMAOMR( heth, tmpreg );

            /*----------------------- ETHERNET DMABMR Configuration ------------------*/
            /* Set the AAL bit according to ETH AddressAlignedBeats value */
            /* Set the FB bit according to ETH FixedBurst value */
            /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */
            /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */
            /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/
            /* Set the DSL bit according to ETH DesciptorSkipLength value */
            /* Set the PR and DA bits according to ETH DMAArbitration value */
            heth->Instance->DMABMR = ( uint32_t ) ( dmainit.AddressAlignedBeats |
                                                    dmainit.FixedBurst |
                                                    dmainit.RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
                                                    dmainit.TxDMABurstLength |
                                                    dmainit.EnhancedDescriptorFormat |
                                                    ( dmainit.DescriptorSkipLength << 2 ) |
                                                    dmainit.DMAArbitration |
                                                    ETH_DMABMR_USP ); /* Enable use of separate PBL for Rx and Tx */

            /* Wait until the write operation will be taken into account:
             * at least four TX_CLK/RX_CLK clock cycles */
            tmpreg = heth->Instance->DMABMR;
            vRegisterDelay();
            heth->Instance->DMABMR = tmpreg;

            if( heth->Init.RxMode == ETH_RXINTERRUPT_MODE )
            {
                /* Enable the Ethernet Rx Interrupt */
                __HAL_ETH_DMA_ENABLE_IT( ( heth ), ETH_DMA_IT_NIS | ETH_DMA_IT_R );
            }

            /* Initialize MAC address in ethernet MAC */
            ETH_MACAddressConfig( heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr );
        }