-
Notifications
You must be signed in to change notification settings - Fork 8.1k
enable ethernet support on the stm32mp135f-dk #96134
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
base: main
Are you sure you want to change the base?
Changes from all commits
b228fe1
d3468c1
603fc55
5a30dfd
8193108
a61c3c6
41afe67
31349e5
b15664c
9f79d6b
80bd370
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,7 @@ config GPIO_MCP230XX_INIT_PRIORITY | |
|
||
endif # GPIO_MCP230XX | ||
|
||
config NET_L2_ETHERNET | ||
default y if NETWORKING | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use configdefault |
||
|
||
endif # BOARD_STM32MP135F_DK |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,13 @@ | |
gpio-map = <CSI_IO0 0 &mcp23017 4 0>, | ||
<CSI_IO1 0 &mcp23017 3 0>; | ||
}; | ||
|
||
eth_ram: sram@30000000 { | ||
compatible = "zephyr,memory-region", "mmio-sram"; | ||
reg = <0x2FFE0000 DT_SIZE_K(16)>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why |
||
#memory-region-cells = <0>; | ||
zephyr,memory-region = "ETH_SRAM"; | ||
}; | ||
}; | ||
|
||
&clk_hsi { | ||
|
@@ -111,6 +118,17 @@ | |
status = "okay"; | ||
}; | ||
|
||
&pll4 { | ||
clocks = <&clk_hsi>; | ||
div-m = <2>; | ||
mul-n = <50>; | ||
div-p = <12>; | ||
div-q = <60>; | ||
div-r = <6>; | ||
fracn = <0>; | ||
status = "okay"; | ||
}; | ||
|
||
&rcc { | ||
clock-frequency = <DT_FREQ_M(1000)>; | ||
clocks = <&pll>; | ||
|
@@ -250,3 +268,30 @@ csi_interface: &dcmipp { | |
|
||
status = "disabled"; | ||
}; | ||
|
||
&mac { | ||
status = "okay"; | ||
pinctrl-0 = <ð1_txd0_pg13 | ||
ð1_txd1_pg14 | ||
ð1_tx_ctl_pb11 | ||
ð1_ref_clk_pa1 | ||
ð1_rxd0_pc4 | ||
ð1_rxd1_pc5 | ||
ð1_crs_dv_pc1>; | ||
pinctrl-names = "default"; | ||
phy-connection-type = "rmii"; | ||
phy-handle = <ð_phy>; | ||
memory-regions = <ð_ram>; | ||
}; | ||
|
||
&mdio { | ||
status = "okay"; | ||
pinctrl-0 = <ð1_mdio_pa2 ð1_mdc_pg2>; | ||
pinctrl-names = "default"; | ||
|
||
eth_phy: ethernet-phy@0 { | ||
compatible = "microchip,lan8742"; | ||
reg = <0>; | ||
reset-gpios = <&mcp23017 9 GPIO_ACTIVE_LOW>; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ choice ETH_STM32_HAL_API_VERSION | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also in this commit message: - - Add support of PHY with/without crystal 50MHz
+ - Add support of PHY with/without crystal 50MHz |
||
config ETH_STM32_HAL_API_V2 | ||
bool "Use official STM32Cube HAL driver" | ||
depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H5X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32N6X | ||
select USE_STM32_HAL_ETH_EX if SOC_SERIES_STM32N6X | ||
depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H5X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32N6X || SOC_SERIES_STM32MP13X | ||
select USE_STM32_HAL_ETH_EX if SOC_SERIES_STM32N6X || SOC_SERIES_STM32MP13X | ||
help | ||
Use the official STM32Cube HAL driver instead of the legacy one. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#include <zephyr/drivers/clock_control.h> | ||
#include <zephyr/drivers/clock_control/stm32_clock_control.h> | ||
#include <zephyr/linker/devicetree_regions.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/net/ethernet.h> | ||
#include <zephyr/net/phy.h> | ||
|
@@ -36,6 +37,11 @@ extern const struct device *eth_stm32_phy_dev; | |
#elif defined(CONFIG_SOC_SERIES_STM32H7X) | ||
#define __eth_stm32_desc __attribute__((section(".eth_stm32_desc"))) | ||
#define __eth_stm32_buf __attribute__((section(".eth_stm32_buf"))) | ||
#elif defined(CONFIG_SOC_SERIES_STM32MP13X) | ||
#define ETH_DMA_REGION DT_PHANDLE(DT_NODELABEL(mac), memory_regions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. access by Instance and not by label |
||
#define ETH_DMA_LINKER_REGION_NAME LINKER_DT_NODE_REGION_NAME(ETH_DMA_REGION) | ||
#define __eth_stm32_desc ALIGN_32BYTES(__attribute__((__section__(ETH_DMA_LINKER_REGION_NAME)))) | ||
#define __eth_stm32_buf ALIGN_32BYTES(__attribute__((__section__(ETH_DMA_LINKER_REGION_NAME)))) | ||
#elif defined(CONFIG_NOCACHE_MEMORY) | ||
#define __eth_stm32_desc __nocache __aligned(4) | ||
#define __eth_stm32_buf __nocache __aligned(4) | ||
|
@@ -102,6 +108,15 @@ extern ETH_DMADescTypeDef dma_tx_desc_tab[ETH_TXBUFNB]; | |
struct eth_stm32_hal_dev_cfg { | ||
void (*config_func)(void); | ||
struct stm32_pclken pclken; | ||
#if DT_INST_CLOCKS_HAS_NAME(0, mac_clk) | ||
struct stm32_pclken pclken_mac; | ||
#endif | ||
#if DT_INST_CLOCKS_HAS_NAME(0, eth_ker) | ||
struct stm32_pclken pclken_ker; | ||
#endif | ||
#if defined(CONFIG_SOC_SERIES_STM32MP13X) | ||
ETH_ClkSrcTypeDef clockselection; | ||
#endif /* CONFIG_SOC_SERIES_STM32MP13X */ | ||
struct stm32_pclken pclken_rx; | ||
struct stm32_pclken pclken_tx; | ||
#if DT_INST_CLOCKS_HAS_NAME(0, mac_clk_ptp) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#include <zephyr/sys/util.h> | ||
#include <zephyr/sys/__assert.h> | ||
#include <ethernet/eth_stats.h> | ||
#include <zephyr/linker/devicetree_regions.h> | ||
|
||
#include <errno.h> | ||
#include <stdbool.h> | ||
|
@@ -32,7 +33,7 @@ struct eth_stm32_tx_buffer_header { | |
bool used; | ||
}; | ||
|
||
static ETH_TxPacketConfig tx_config; | ||
static ETH_TxPacketConfigTypeDef tx_config; | ||
|
||
static struct eth_stm32_rx_buffer_header dma_rx_buffer_header[ETH_RXBUFNB]; | ||
static struct eth_stm32_tx_buffer_header dma_tx_buffer_header[ETH_TXBUFNB]; | ||
|
@@ -41,7 +42,11 @@ static struct eth_stm32_tx_context dma_tx_context[ETH_TX_DESC_CNT]; | |
/* Pointer to an array of ETH_STM32_RX_BUF_SIZE uint8_t's */ | ||
typedef uint8_t (*RxBufferPtr)[ETH_STM32_RX_BUF_SIZE]; | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32mp13_ethernet) | ||
void HAL_ETH_RxAllocateCallback(ETH_HandleTypeDef *heth, uint8_t **buf) | ||
#else | ||
void HAL_ETH_RxAllocateCallback(uint8_t **buf) | ||
#endif | ||
{ | ||
for (size_t i = 0; i < ETH_RXBUFNB; ++i) { | ||
if (!dma_rx_buffer_header[i].used) { | ||
|
@@ -56,7 +61,12 @@ void HAL_ETH_RxAllocateCallback(uint8_t **buf) | |
} | ||
|
||
/* called by HAL_ETH_ReadData() */ | ||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32mp13_ethernet) | ||
void HAL_ETH_RxLinkCallback(ETH_HandleTypeDef *heth, void **pStart, void **pEnd, | ||
uint8_t *buff, uint16_t Length) | ||
#else | ||
void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length) | ||
#endif | ||
{ | ||
/* buff points to the begin on one of the rx buffers, | ||
* so we can compute the index of the given buffer | ||
|
@@ -81,7 +91,11 @@ void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t | |
} | ||
|
||
/* Called by HAL_ETH_ReleaseTxPacket */ | ||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32mp13_ethernet) | ||
void HAL_ETH_TxFreeCallback(ETH_HandleTypeDef *heth, uint32_t *buff) | ||
#else | ||
void HAL_ETH_TxFreeCallback(uint32_t *buff) | ||
#endif | ||
{ | ||
__ASSERT_NO_MSG(buff != NULL); | ||
|
||
|
@@ -279,7 +293,11 @@ int eth_stm32_tx(const struct device *dev, struct net_pkt *pkt) | |
HAL_ETH_ReleaseTxPacket(heth); | ||
} else { | ||
/* We need to release the tx context and its buffers */ | ||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32mp13_ethernet) | ||
HAL_ETH_TxFreeCallback(heth, (uint32_t *)ctx); | ||
#else | ||
HAL_ETH_TxFreeCallback((uint32_t *)ctx); | ||
#endif | ||
Comment on lines
+296
to
+300
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposal:
With:
|
||
} | ||
|
||
k_mutex_unlock(&dev_data->tx_mutex); | ||
|
@@ -454,6 +472,9 @@ void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth) | |
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) | ||
dev_data->stats.error_details.rx_crc_errors = heth->Instance->MMCRCRCEPR; | ||
dev_data->stats.error_details.rx_align_errors = heth->Instance->MMCRAEPR; | ||
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32mp13_ethernet) | ||
dev_data->stats.error_details.rx_crc_errors = heth->Instance->MMCRXCRCEPR; | ||
dev_data->stats.error_details.rx_align_errors = heth->Instance->MMCRXAEPR; | ||
#else | ||
dev_data->stats.error_details.rx_crc_errors = heth->Instance->MMCRFCECR; | ||
dev_data->stats.error_details.rx_align_errors = heth->Instance->MMCRFAECR; | ||
|
@@ -467,6 +488,9 @@ int eth_stm32_hal_init(const struct device *dev) | |
struct eth_stm32_hal_dev_data *dev_data = dev->data; | ||
ETH_HandleTypeDef *heth = &dev_data->heth; | ||
HAL_StatusTypeDef hal_ret = HAL_OK; | ||
__maybe_unused const struct eth_stm32_hal_dev_cfg *cfg = dev->config; | ||
__maybe_unused uint8_t *desc_uncached_addr; | ||
__maybe_unused int ret; | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet) | ||
for (int ch = 0; ch < ETH_DMA_CH_CNT; ch++) { | ||
|
@@ -479,6 +503,37 @@ int eth_stm32_hal_init(const struct device *dev) | |
#endif | ||
heth->Init.RxBuffLen = ETH_STM32_RX_BUF_SIZE; | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32mp13_ethernet) | ||
/* Map memory region for DMA descriptor and buffer as non cacheable */ | ||
k_mem_map_phys_bare(&desc_uncached_addr, | ||
DT_REG_ADDR(ETH_DMA_REGION), | ||
DT_REG_SIZE(ETH_DMA_REGION), | ||
K_MEM_PERM_RW | K_MEM_DIRECT_MAP | K_MEM_CACHE_NONE | | ||
K_MEM_ARM_NORMAL_NC); | ||
|
||
heth->Init.ClockSelection = cfg->clockselection; | ||
#endif | ||
|
||
#if DT_INST_CLOCKS_HAS_NAME(0, eth_ker) | ||
/* Turn on DCMIPP peripheral clock */ | ||
ret = clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE), | ||
(clock_control_subsys_t)&cfg->pclken_ker, | ||
NULL); | ||
if (ret < 0) { | ||
LOG_ERR("Failed to configure ETH kernel clock. Error %d", ret); | ||
return ret; | ||
} | ||
#endif | ||
|
||
#if DT_INST_CLOCKS_HAS_NAME(0, mac_clk) | ||
ret = clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE), | ||
(clock_control_subsys_t)&cfg->pclken_mac); | ||
if (ret < 0) { | ||
LOG_ERR("Failed to configure mac clock. Error %d", ret); | ||
return ret; | ||
} | ||
#endif | ||
|
||
hal_ret = HAL_ETH_Init(heth); | ||
if (hal_ret == HAL_TIMEOUT) { | ||
/* HAL Init time out. This could be linked to */ | ||
|
@@ -507,7 +562,7 @@ int eth_stm32_hal_init(const struct device *dev) | |
k_sem_init(&dev_data->tx_int_sem, 0, K_SEM_MAX_LIMIT); | ||
|
||
/* Tx config init: */ | ||
memset(&tx_config, 0, sizeof(ETH_TxPacketConfig)); | ||
memset(&tx_config, 0, sizeof(ETH_TxPacketConfigTypeDef)); | ||
tx_config.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | | ||
ETH_TX_PACKETS_FEATURES_CRCPAD; | ||
tx_config.ChecksumCtrl = IS_ENABLED(CONFIG_ETH_STM32_HW_CHECKSUM) ? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title of the commit is also after the signature:
Signed-off-by: Arnaud Pouliquen arnaud.pouliquen@foss.st.comarch: arm: mmu: allow selecting memory type for non-cacheable memory