/* Initialize pins in complex peripheral */ void init_eth(void) { int phy_pins[] = { PHY_CRSDV, PHY_RXD0, PHY_RXD1, PHY_REFCLK, PHY_TXEN, PHY_TXD0, PHY_TXD1, PHY_MDIO, PHY_MDC }; /* Initialize all pins that belongs to RMII */ for (int i = 0; i < sizeof(phy_pins) / sizeof(phy_pins[0]); i++) { pin_clock_enable(phy_pins[i]); pin_af_pushpull(phy_pins[i]); pin_speed_high(phy_pins[i]); pin_af_map(phy_pins[i], GPIO_AF_ETH); } pin_input(PHY_INTRP); pin_pull_up(PHY_INTRP); pin_set(PHY_RST, true); pin_output_pushpull(PHY_RST); /* Reset the connected PHY by signal */ pin_set(PHY_RST, false); for (int i = 0; i < 10000; i++) { __asm volatile ("nop"); } pin_set(PHY_RST, true); for (int i = 0; i < 10000; i++) { __asm volatile ("nop"); } /* Initialize phy over SNI */ phy_reset(1); /* out of scope of this example */ /* Initialize ethernet MAC */ eth_init(); /* out of scope of this example */ }
int main(void) { if (PM->RCAUSE.reg & (PM_RCAUSE_POR | PM_RCAUSE_BOD12 | PM_RCAUSE_BOD33)) { // On powerup, force a clean reset of the MT7620 pin_low(PIN_SOC_RST); pin_out(PIN_SOC_RST); // turn off 3.3V to SoC pin_low(PIN_SOC_PWR); pin_out(PIN_SOC_PWR); // pull 1.8V low pin_low(PIN_18_V); pin_out(PIN_18_V); clock_init_crystal(GCLK_SYSTEM, GCLK_32K); timer_clock_enable(TC_BOOT); // hold everything low boot_delay_ms(50); // power off for 50ms pin_high(PIN_SOC_PWR); boot_delay_ms(2); // 2ms until 1.8 rail comes on pin_high(PIN_18_V); boot_delay_ms(50); // 50ms before soc rst comes on } else { clock_init_crystal(GCLK_SYSTEM, GCLK_32K); } pin_mux(PIN_USB_DM); pin_mux(PIN_USB_DP); usb_init(); usb_attach(); NVIC_SetPriority(USB_IRQn, 0xff); pin_high(PIN_LED); pin_out(PIN_LED); pin_in(PIN_SOC_RST); pin_high(PIN_SOC_PWR); pin_out(PIN_SOC_PWR); pin_low(PORT_A.power); pin_out(PORT_A.power); pin_low(PORT_B.power); pin_out(PORT_B.power); pin_pull_up(PIN_BRIDGE_CS); pin_pull_up(PIN_FLASH_CS); pin_pull_up(PIN_SERIAL_TX); pin_pull_up(PIN_SERIAL_RX); dma_init(); NVIC_EnableIRQ(DMAC_IRQn); NVIC_SetPriority(DMAC_IRQn, 0xff); eic_init(); NVIC_EnableIRQ(EIC_IRQn); NVIC_SetPriority(EIC_IRQn, 0xff); evsys_init(); NVIC_EnableIRQ(EVSYS_IRQn); NVIC_SetPriority(EVSYS_IRQn, 0); adc_init(GCLK_SYSTEM, ADC_REFCTRL_REFSEL_INTVCC1); dac_init(GCLK_32K); bridge_init(); port_init(&port_a, 1, &PORT_A, GCLK_PORT_A, TCC_PORT_A, DMA_PORT_A_TX, DMA_PORT_A_RX); port_init(&port_b, 2, &PORT_B, GCLK_PORT_B, TCC_PORT_B, DMA_PORT_B_TX, DMA_PORT_B_RX); __enable_irq(); SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk; init_systick(); while (1) { __WFI(); } }