@@ -295,6 +295,7 @@ void eth_set_trace(eth_t *self, uint32_t value) {
295295}
296296
297297static int eth_mac_init (eth_t * self ) {
298+ mp_printf (& mp_plat_print , "ETH: MAC init starting\n" );
298299 // Configure MPU
299300 uint32_t irq_state = mpu_config_start ();
300301 #if defined(STM32H5 ) || defined(STM32N6 )
@@ -333,8 +334,10 @@ static int eth_mac_init(eth_t *self) {
333334 #elif defined(STM32N6 )
334335 #if defined(MICROPY_HW_ETH_RGMII_CLK125 )
335336 LL_RCC_SetETHPHYInterface (LL_RCC_ETH1PHY_IF_RGMII );
337+ mp_printf (& mp_plat_print , "ETH: N6 PHY interface = RGMII\n" );
336338 #else
337339 LL_RCC_SetETHPHYInterface (LL_RCC_ETH1PHY_IF_RMII );
340+ mp_printf (& mp_plat_print , "ETH: N6 PHY interface = RMII\n" );
338341 #endif
339342 #else
340343 __HAL_RCC_SYSCFG_CLK_ENABLE ();
@@ -596,13 +599,15 @@ static int eth_mac_init(eth_t *self) {
596599 mp_hal_delay_ms (2 );
597600
598601 // Start MAC layer
602+ mp_printf (& mp_plat_print , "ETH: Starting MAC TX/RX\n" );
599603 ETH -> MACCR |=
600604 ETH_MACCR_TE // enable TX
601605 | ETH_MACCR_RE // enable RX
602606 ;
603607 mp_hal_delay_ms (2 );
604608
605609 // Start DMA layer
610+ mp_printf (& mp_plat_print , "ETH: Starting DMA\n" );
606611 #if defined(STM32H5 ) || defined(STM32H7 )
607612 ETH -> DMACRCR |= ETH_DMACRCR_SR ; // start RX
608613 ETH -> DMACTCR |= ETH_DMACTCR_ST ; // start TX
@@ -618,13 +623,18 @@ static int eth_mac_init(eth_t *self) {
618623 ETH -> DMA_CH [0 ].DMACTXCR |= ETH_DMACxTXCR_ST ;
619624 // Clear TX/RX process stopped flags
620625 ETH -> DMA_CH [0 ].DMACSR |= ETH_DMACxSR_TPS | ETH_DMACxSR_RPS ;
626+ mp_printf (& mp_plat_print , "ETH: N6 DMA CH0: CSR=0x%08x TXCR=0x%08x RXCR=0x%08x\n" ,
627+ (unsigned )ETH -> DMA_CH [0 ].DMACSR ,
628+ (unsigned )ETH -> DMA_CH [0 ].DMACTXCR ,
629+ (unsigned )ETH -> DMA_CH [0 ].DMACRXCR );
621630 #else
622631 ETH -> DMAOMR |=
623632 ETH_DMAOMR_ST // start TX
624633 | ETH_DMAOMR_SR // start RX
625634 ;
626635 #endif
627636 mp_hal_delay_ms (2 );
637+ mp_printf (& mp_plat_print , "ETH: MAC/DMA started, MACCR=0x%08x\n" , (unsigned )ETH -> MACCR );
628638
629639 // Enable interrupts
630640 NVIC_SetPriority (ETH_IRQn , IRQ_PRI_PENDSV );
@@ -1157,11 +1167,14 @@ int eth_start(eth_t *self) {
11571167 }
11581168
11591169 // Initialize PHY (reset and configure)
1170+ mp_printf (& mp_plat_print , "ETH: Calling PHY init\n" );
11601171 ret = eth_phy_init (self );
11611172 if (ret < 0 ) {
1173+ mp_printf (& mp_plat_print , "ETH: PHY init failed: %d\n" , ret );
11621174 eth_mac_deinit (self );
11631175 return ret ;
11641176 }
1177+ mp_printf (& mp_plat_print , "ETH: PHY init success\n" );
11651178
11661179 MICROPY_PY_LWIP_ENTER
11671180 struct netif * n = & self -> netif ;
@@ -1232,27 +1245,44 @@ void eth_low_power_mode(eth_t *self, bool enable) {
12321245
12331246static int eth_phy_init (eth_t * self ) {
12341247 // Reset and initialize the PHY
1248+ mp_printf (& mp_plat_print , "ETH: PHY init addr=%d\n" , (int )self -> phy_addr );
12351249 self -> phy_init (self -> phy_addr );
12361250 mp_hal_delay_ms (10 );
12371251
12381252 // Wait for PHY reset to complete (but don't wait for link)
12391253 uint32_t t0 = mp_hal_ticks_ms ();
12401254 while (eth_phy_read (self -> phy_addr , PHY_BCR ) & PHY_BCR_SOFT_RESET ) {
12411255 if (mp_hal_ticks_ms () - t0 > 1000 ) { // 1 second timeout for reset
1256+ mp_printf (& mp_plat_print , "ETH: PHY reset timeout\n" );
12421257 return - MP_ETIMEDOUT ;
12431258 }
12441259 mp_hal_delay_ms (2 );
12451260 }
1261+ mp_printf (& mp_plat_print , "ETH: PHY reset complete\n" );
1262+
1263+ // Read PHY ID to verify MDIO communication
1264+ uint32_t phy_id1 = eth_phy_read (self -> phy_addr , 0x02 );
1265+ uint32_t phy_id2 = eth_phy_read (self -> phy_addr , 0x03 );
1266+ mp_printf (& mp_plat_print , "ETH: PHY ID=0x%04x%04x\n" , (int )phy_id1 , (int )phy_id2 );
12461267
12471268 // Enable autonegotiation for all speed/duplex modes
12481269 // This starts the autonegotiation process in the background
1270+ mp_printf (& mp_plat_print , "ETH: Configuring autoneg\n" );
1271+
1272+ // Configure 10/100 speeds
12491273 eth_phy_write (self -> phy_addr , PHY_ANAR ,
12501274 PHY_ANAR_SPEED_10HALF |
12511275 PHY_ANAR_SPEED_10FULL |
12521276 PHY_ANAR_SPEED_100HALF |
12531277 PHY_ANAR_SPEED_100FULL |
12541278 PHY_ANAR_IEEE802_3 );
1279+
1280+ // For gigabit PHYs, also advertise 1000Mbps capability
1281+ eth_phy_write (self -> phy_addr , PHY_1000BTCR ,
1282+ PHY_1000BTCR_1000HALF | PHY_1000BTCR_1000FULL );
1283+
12551284 eth_phy_write (self -> phy_addr , PHY_BCR , PHY_BCR_AUTONEG_EN | PHY_BCR_AUTONEG_RESTART );
1285+ mp_printf (& mp_plat_print , "ETH: Autoneg started\n" );
12561286
12571287 // Initialize link status tracking (current state, whatever it is)
12581288 self -> last_link_status = false;
0 commit comments