mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-29 04:23:54 +00:00
gpio: Disable USB JTAG when setting pins 18 and 19 as GPIOs on ESP32C3
When `DIS_USB_JTAG` eFuse is NOT burned (`False`), it is not possible to set pins 18 and 19 as GPIOs. This commit solves this by manually disabling USB JTAG when using pins 18 or 19. The functions shall use `gpio_hal_iomux_func_sel` instead of `PIN_FUNC_SELELECT`.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "soc/gpio_periph.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "hal/emac.h"
|
||||
#include "hal/gpio_hal.h"
|
||||
|
||||
#define ETH_CRC_LENGTH (4)
|
||||
|
||||
@@ -63,27 +64,27 @@ void emac_hal_lowlevel_init(emac_hal_context_t *hal)
|
||||
{
|
||||
/* GPIO configuration */
|
||||
/* TX_EN to GPIO21 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
|
||||
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[21]);
|
||||
/* TXD0 to GPIO19 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
|
||||
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[19]);
|
||||
/* TXD1 to GPIO22 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
|
||||
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[22]);
|
||||
/* RXD0 to GPIO25 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO25_U, FUNC_GPIO25_EMAC_RXD0);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO25_U, FUNC_GPIO25_EMAC_RXD0);
|
||||
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[25]);
|
||||
/* RXD1 to GPIO26 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO26_U, FUNC_GPIO26_EMAC_RXD1);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO26_U, FUNC_GPIO26_EMAC_RXD1);
|
||||
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[26]);
|
||||
/* CRS_DV to GPIO27 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV);
|
||||
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[27]);
|
||||
#if CONFIG_ETH_RMII_CLK_INPUT
|
||||
#if CONFIG_ETH_RMII_CLK_IN_GPIO == 0
|
||||
/* RMII clock (50MHz) input to GPIO0 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_EMAC_TX_CLK);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_EMAC_TX_CLK);
|
||||
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[0]);
|
||||
#else
|
||||
#error "ESP32 EMAC only support input RMII clock to GPIO0"
|
||||
@@ -92,15 +93,15 @@ void emac_hal_lowlevel_init(emac_hal_context_t *hal)
|
||||
#if CONFIG_ETH_RMII_CLK_OUTPUT
|
||||
#if CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0
|
||||
/* APLL clock output to GPIO0 (must be configured to 50MHz!) */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
|
||||
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[0]);
|
||||
#elif CONFIG_ETH_RMII_CLK_OUT_GPIO == 16
|
||||
/* RMII CLK (50MHz) output to GPIO16 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT);
|
||||
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[16]);
|
||||
#elif CONFIG_ETH_RMII_CLK_OUT_GPIO == 17
|
||||
/* RMII CLK (50MHz) output to GPIO17 */
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO17_U, FUNC_GPIO17_EMAC_CLK_OUT_180);
|
||||
gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO17_U, FUNC_GPIO17_EMAC_CLK_OUT_180);
|
||||
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[17]);
|
||||
#endif
|
||||
#endif // CONFIG_ETH_RMII_CLK_OUTPUT
|
||||
|
||||
@@ -567,6 +567,17 @@ static inline void gpio_ll_iomux_in(gpio_dev_t *hw, uint32_t gpio, uint32_t sign
|
||||
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select a function for the pin in the IOMUX
|
||||
*
|
||||
* @param pin_name Pin name to configure
|
||||
* @param func Function to assign to the pin
|
||||
*/
|
||||
static inline void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func)
|
||||
{
|
||||
PIN_FUNC_SELECT(pin_name, func);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set peripheral output to an GPIO pad through the IOMUX.
|
||||
*
|
||||
@@ -580,7 +591,7 @@ static inline void gpio_ll_iomux_out(gpio_dev_t *hw, uint8_t gpio_num, int func,
|
||||
{
|
||||
hw->func_out_sel_cfg[gpio_num].oen_sel = 0;
|
||||
hw->func_out_sel_cfg[gpio_num].oen_inv_sel = oen_inv;
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[gpio_num], func);
|
||||
gpio_ll_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_num], func);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user