Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ETH support to PIC32 boards #2890

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions hw/bsp/olimex-pic32-emz64/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "os/mynewt.h"

#include <bsp/bsp.h>
#include <hal/hal_gpio.h>
#include <hal/hal_bsp.h>
#include <mcu/mips_bsp.h>
#include <mcu/mips_hal.h>
Expand Down Expand Up @@ -75,6 +76,20 @@
*/
#pragma config WINDIS=1, WDTSPGM=1, WDTPS=15

#if MYNEWT_VAL(ETH_0)
#if MYNEWT_VAL_CHOICE(PIC32_ETH_0_PHY_ITF, RMII)
#pragma config FMIIEN=OFF
#else
#pragma config FMIIEN=ON
#endif

#if MYNEWT_VAL(PIC32_ETH_0_PHY_ALT_PINS)
#pragma config FETHIO=OFF
#else
#pragma config FETHIO=ON
#endif
#endif

#endif

#if MYNEWT_VAL(SPIFLASH)
Expand Down Expand Up @@ -109,6 +124,11 @@ hal_bsp_flash_dev(uint8_t id)
void
hal_bsp_init(void)
{
if (MYNEWT_VAL(ETH_0)) {
/* Remove reset from LAN8720 */
hal_gpio_init_out(MCU_GPIO_PORTB(11), 1);
}

pic32mz_periph_create();
#if MYNEWT_VAL(SPIFLASH) && MYNEWT_VAL(BUS_DRIVER_PRESENT)
rc = spiflash_create_spi_dev(&spiflash_dev.dev,
Expand Down
4 changes: 4 additions & 0 deletions hw/bsp/olimex-pic32-emz64/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ syscfg.vals:
SPI_3_MASTER: 1
SPI_3_MASTER_PIN_MOSI: MCU_GPIO_PORTD(5)
SPI_3_MASTER_PIN_MISO: MCU_GPIO_PORTD(11)
PIC32_ETH_0_PHY_ADDR: 0
PIC32_ETH_0_PHY_ITF: RMII
PIC32_ETH_0_PHY_IRQ_PIN: MCU_GPIO_PORTB(1)
PIC32_ETH_0_PHY_ALT_PINS: 0
CONSOLE_UART_DEV: '"uart3"'

SYSTEM_CLOCK_SRC: POSC_PLL
Expand Down
14 changes: 14 additions & 0 deletions hw/bsp/olimex-pic32-hmz144/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
*/
#pragma config WINDIS=1, WDTSPGM=1, WDTPS=15

#if MYNEWT_VAL(ETH_0)
#if MYNEWT_VAL_CHOICE(PIC32_ETH_0_PHY_ITF, RMII)
#pragma config FMIIEN=OFF
#else
#pragma config FMIIEN=ON
#endif

#if MYNEWT_VAL(PIC32_ETH_0_PHY_ALT_PINS)
#pragma config FETHIO=OFF
#else
#pragma config FETHIO=ON
#endif
#endif

#endif

#if MYNEWT_VAL(SPIFLASH)
Expand Down
3 changes: 3 additions & 0 deletions hw/mcu/microchip/pic32mz/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ pkg.deps.(UART_0 || UART_1 || UART_2 || UART_3 || UART_4 || UART_5):

pkg.deps:
- "@apache-mynewt-core/hw/hal"

pkg.deps.ETH_0:
- "@apache-mynewt-core/hw/drivers/lwip/pic32_eth"
24 changes: 24 additions & 0 deletions hw/mcu/microchip/pic32mz/src/pic32mz_periph.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <mcu/mips_hal.h>
#include <uart_hal/uart_hal.h>
#include <bsp/bsp.h>
#if MYNEWT_VAL(ETH_0)
#include <pic32_eth/pic32_eth.h>
#endif

static struct uart_dev uart_0_dev;
static struct uart_dev uart_1_dev;
Expand Down Expand Up @@ -200,6 +203,15 @@ static const struct mips_i2c_cfg i2c_3_cfg = {
.frequency = MYNEWT_VAL(I2C_3_FREQ_KHZ) * 1000,
};

#if MYNEWT_VAL(ETH_0)
static const struct pic32_eth_cfg eth0_cfg = {
.phy_addr = MYNEWT_VAL(PIC32_ETH_0_PHY_ADDR),
.phy_type = MYNEWT_VAL(PIC32_ETH_0_PHY_CHIP),
.phy_irq_pin = MYNEWT_VAL(PIC32_ETH_0_PHY_IRQ_PIN),
.phy_irq_pin_pull_up = MYNEWT_VAL(PIC32_ETH_0_PHY_IRQ_PIN_PULLUP),
};
#endif

/*
* I2C_4 -> I2C5
* SCL5 -> RF5
Expand Down Expand Up @@ -372,11 +384,23 @@ pic32mz_periph_i2c_devs(void)
}
}

static void
pic32mz_periph_create_eth(void)
{
#if MYNEWT_VAL(ETH_0)
int rc;
rc = pic32_eth_init(&eth0_cfg);
assert(rc == 0);
(void)rc;
#endif
}

void
pic32mz_periph_create(void)
{
pic32mz_periph_create_timer_devs();
pic32mz_periph_create_uart_devs();
pic32mz_periph_spi_devs();
pic32mz_periph_i2c_devs();
pic32mz_periph_create_eth();
}
4 changes: 4 additions & 0 deletions hw/mcu/microchip/pic32mz/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ syscfg.defs:
description: "Whether to enable Timer 7"
value: 0

ETH_0:
description: 'Ethernet driver for LwIP'
value: 0

SYSTEM_CLOCK_OSC_FREQ:
descriprion: HS Oscilator/External clock freqency.
value:
Expand Down