I've encountered a problem. I can get the Ethernet to function on my STM32F4, but only after a "system reset", on the st-link utility. If I just power it up or press the reset button on my board, the Ethernet will not work. I can tell this by reading the THE_DMASR. If I do a power cycling reset the register reads 0x3000000 which means it's not recieving or transmitting. If I press the "system reset" the ETH_DMASR register hold 0x00006000, which means that the receiver is ready and waiting for a new packet.
I assume I'm enabling the peripherals and clocks in the wrong order. my initialization follows.
_start:
ldr R0, = RCC_CR @ RCC_APB1ENR
ldr R1, = 0x00010083 @ ENABLE HSE clock
str R1, [R0]
ldr r0, = RCC_CFGR @ set the system clock to the external crystal
ldr r1, = 0x00400000 @
str r1, [R0]
HSENRdy:
ldr r1, = RCC_CR @load the reset and clock control register into a working register
ldr r0, [r1] @ r0 = RCC_CR
lsrs r0, r0, #2 @update condition flags and pop off bit 1
bcc HSENRdy
ldr r0, = RCC_CFGR @ set the system clock to the external crystal
ldr r1, = 0x00400001 @
str r1, [R0]
ldr r0, = RCC_APB1ENR @ RCC_APB1ENR
ldr r1, = 0x10040000 @ ENABLE power CLOCK and USART3
str r1, [R0]
ldr r0, = RCC_AHB1ENR @ RCC_APB1ENR
ldr r1, = 0x1E7411FF @ ENABLE power CLOCK GPIOA,B,C,G,H,I,CRC
str r1, [R0]
ldr r0, = RCC_APB2ENR @ RCC_APB1ENR
ldr r1, = 0x00004000 @ ENABLE power CLOCK GPIOA,B,C,G,H,I,CRC
str r1, [R0]
ldr r0, = PWR_CR @ RCC_APB2ENR
ldr r1, = 0x00000100 @ ENABLE SYSCFG CLOCK
str r1, [R0]
ldr r0, = RCC_BDCR @ this enables the real time clock to external clock source
ldr r1, = 0x00000001 @ this enables the real time clock to external clock source
str r1, [r0] @ this enables the real time clock to external clock source
LSENRdy:
ldr r1, = RCC_BDCR @load the reset and clock control register into a working register
ldr r0, [r1] @ r0 = RCC_BDCR
lsrs r0, r0, #2 @update condition flags and pop off bit 1
bcc LSENRdy
ldr r0, = RCC_BDCR @ this enables the real time clock to external clock source
ldr r1, = 0x00008103 @ this enables the real time clock to external clock source
str r1, [r0] @ this enables the real time clock to external clock source
ldr r0, = RCC_AHB1RSTR @ this resets the Ethernet MAC
ldr r1, = 0x02000000
str r1, [r0]
ldr r0, = RCC_AHB1RSTR @ this resets the Ethernet MAC
ldr r1, = 0x00000000
str r1, [r0]
ldr r0, = SYSCFG_CMPCR @ this enables the real time clock to external clock source
ldr r1, = 0x00000001 @ this enables the real time clock to external clock source
str r1, [r0] @ this enables the real time clock to external clock source
ldr r0, = GPIOC_MODER @ this enables the general purpose port C to alternat function
ldr r1, = 0x00A00AA8 @ this enables the general purpose port C to alternat function
str r1, [r0] @ this enables the general purpose port C to alternat function
ldr r0, = GPIOC_OSPEEDR @ this enables the general purpose port C to alternat function
ldr r1, = 0x00000AA8 @ this enables the general purpose port C to alternat function
str r1, [r0] @ this enables the general purpose port C to alternat function
ldr r0, = GPIOC_AFRL @ this sets the general purspoer port C to Ethernet function
ldr r1, = 0x00BBBBB0 @ this sets the general purspoer port C to Ethernet function
str r1, [r0] @ this sets the general purspoer port C to Ethernet function
ldr r0, = GPIOC_AFRH @ this sets the general purspoer port C to USART function
ldr r1, = 0x00007700 @ this sets the general purspoer port C to USART function
str r1, [r0] @ this sets the general purspoer port C to USART function
ldr r0, = USART3_CR1 @ this enables the USART
ldr r1, = 0x00002000
str r1, [r0]
ldr r0, = USART3_BRR @ this sets the baud rate for the USART
ldr r1, = 0x00000A2C
str r1, [r0]
ldr r0, = GPIOA_MODER @ this enables the general purpose port A to alternat function
ldr r1, = 0xA80280AA @ this enables the general purpose port A to alternat function
str r1, [r0] @ this enables the general purpose port A to alternat function
ldr r0, = GPIOA_OTYPER @ this enables the general purpose port A to alternat function
ldr r1, = 0x00000004 @ this enables the general purpose port A to alternat function
str r1, [r0] @ this enables the general purpose port A to alternat function
ldr r0, = GPIOA_OSPEEDR @ this enables the general purpose port A to alternat function
ldr r1, = 0x000280AA @ this enables the general purpose port A to alternat function
str r1, [r0] @ this enables the general purpose port A to alternat function
ldr r0, = GPIOA_AFRL @ this enables the general purpose port A to alternat function
ldr r1, = 0xB000BBBB @ this enables the general purpose port A to alternat function
str r1, [r0] @ this enables the general purpose port A to alternat function
ldr r0, = GPIOB_MODER @ this enables the general purpose port B to alternat function
ldr r1, = 0x1AA2028A @ this enables the general purpose port B to alternat function
str r1, [r0] @ this enables the general purpose port B to alternat function
ldr r0, = GPIOB_OSPEEDR @ this enables the general purpose port B to alternat function
ldr r1, = 0x0AA200CA @ this enables the general purpose port B to alternat function
str r1, [r0] @ this enables the general purpose port B to alternat function
ldr r0, = GPIOB_BSRR @ this enables the general purpose port B to alternat function
ldr r1, = 0x00004000 @ this enables the general purpose port B to alternat function
str r1, [r0] @ this enables the general purpose port B to alternat function
ldr r0, = GPIOB_AFRL @ this enables the general purpose port A to alternat function
ldr r1, = 0x000000BB @ this enables the general purpose port A to alternat function
str r1, [r0] @ this enables the general purpose port A to alternat function
ldr r0, = GPIOB_AFRH @ this enables the general purpose port B to alternat function
ldr r1, = 0x00BBBB0B @ this enables the general purpose port B to alternat function
str r1, [r0] @ this enables the general purpose port B to alternat function
ldr r0, = ETH_MACCR @ this sets the ethernet to 100Mbps and full duplex
ldr r1, = 0x0000C80C
str r1, [r0]
ldr r0, = ETH_DMAIER @ this sets the ethernet to generate an interrupt
ldr r1, = 0x0001E7FF
str r1, [r0]
ldr r0, = ETH_MACA0HR @ this is the high word of the mac address
ldr r1, = MACAH
str r1, [r0]
ldr r0, = ETH_MACA0LR @ this is the low word of the mac address
ldr r1, = MACAL
str r1, [r0]
@Setup the descriptor in memory put at boundary of system memory
ldr r0, = Descriptor0 @ this gives the descriptor to the CPU
ldr r1, = 0x80000300
str r1, [r0]
ldr r0, = Descriptor1 @ this sets the size of the recieve buffer
ldr r1, = 0x00008100
str r1, [r0]
ldr r0, = Descriptor2 @ this sets the base address of the recieve buffer
ldr r1, = EthBuff1
str r1, [r0]
ldr r0, = Descriptor3 @ this is nothing
ldr r1, = 0x00000000
str r1, [r0]
ldr r0, = ETH_DMARDLAR @ this points to the base address of the recieve descriptor
ldr r1, = Descriptor0
str r1, [r0]
ldr r0, = ETH_DMATDLAR @ this points to the base address of the recieve descriptor
ldr r1, = TransDescr0
str r1, [r0]
ldr r0, = ETH_DMAOMR @ this starts the ethernet DMA recieving and transmitting
ldr r1, = 0x00000002
str r1, [r0]
ldr r0, = NVIC_ISER1 @ this enables the Ethernet to interrupt the core
ldr r1, = 0x20000000
str r1, [r0]
@poll the phy to get the negotiation settings
AutoNeg:
ldr r0, = ETH_MACMIIAR @ this enables the general purpose port G to alternat function
ldr r1, = 0x00000849 @ this enables the general purpose port G to alternat function
str r1, [r0] @ this enables the general purpose port G to alternat function
MIIBusy:
ldr r1, = ETH_MACMIIAR @load the reset and clock control register into a working register
ldr r0, [r1] @ r0 = ETH_MACMIIAR
lsrs r0, r0, #1 @update condition flags and pop off bit 1
bcs MIIBusy
ldr r1, = ETH_MACMIIDR @load the reset and clock control register into a working register
ldr r0, [r1] @ r0 = ETH_MACMIIAR
lsrs r0, r0, #6 @update condition flags and pop off bit 1
bcc AutoNeg
then follows remainder of program where the Ethernet is not initialized properly, on hard reset