From 51fe77afa4ec6b07af55c405c9a85b774c166499 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 24 Jul 2020 17:53:06 +0200 Subject: [PATCH] cpu/stm32/periph_eth: configurable buffer size 1. Move buffer configuration from boards to cpu/stm32 2. Allow overwriting buffer configuration - If the default configuration ever needs touching, this will be due to a use case and should be done by the application rather than the board 3. Reduce default RX buffer size - Now that handling of frames split up into multiple DMA descriptors works, we can make use of this Note: With the significantly smaller RX buffers the driver will now perform much worse when receiving data at maximum throughput. But as long as frames are small (which is to be expected for IoT or boarder gateway scenarios) the performance should not be affected. --- boards/nucleo-f207zg/include/periph_conf.h | 6 ------ boards/nucleo-f767zi/include/periph_conf.h | 6 ------ cpu/stm32/periph/eth.c | 25 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/boards/nucleo-f207zg/include/periph_conf.h b/boards/nucleo-f207zg/include/periph_conf.h index 11027824fa..b79b321436 100644 --- a/boards/nucleo-f207zg/include/periph_conf.h +++ b/boards/nucleo-f207zg/include/periph_conf.h @@ -274,12 +274,6 @@ static const eth_conf_t eth_config = { } }; -#define ETH_RX_BUFFER_COUNT (4) -#define ETH_TX_BUFFER_COUNT (4) - -#define ETH_RX_BUFFER_SIZE (1524) -#define ETH_TX_BUFFER_SIZE (1524) - #define ETH_DMA_ISR isr_dma2_stream0 /** @} */ diff --git a/boards/nucleo-f767zi/include/periph_conf.h b/boards/nucleo-f767zi/include/periph_conf.h index 4c5398cd51..c6589560e4 100644 --- a/boards/nucleo-f767zi/include/periph_conf.h +++ b/boards/nucleo-f767zi/include/periph_conf.h @@ -178,12 +178,6 @@ static const eth_conf_t eth_config = { } }; -#define ETH_RX_BUFFER_COUNT (4) -#define ETH_TX_BUFFER_COUNT (4) - -#define ETH_RX_BUFFER_SIZE (1524) -#define ETH_TX_BUFFER_SIZE (1524) - #define ETH_DMA_ISR isr_dma2_stream0 /** @} */ diff --git a/cpu/stm32/periph/eth.c b/cpu/stm32/periph/eth.c index 93fa145670..75431fbc2a 100644 --- a/cpu/stm32/periph/eth.c +++ b/cpu/stm32/periph/eth.c @@ -49,6 +49,31 @@ #define CLOCK_RANGE ETH_MACMIIAR_CR_Div102 #endif /* CLOCK_CORECLOCK < (20000000U) */ +/* Default DMA buffer setup */ +#ifndef ETH_RX_BUFFER_COUNT +#define ETH_RX_BUFFER_COUNT (6U) +#endif +#ifndef ETH_TX_BUFFER_COUNT +#define ETH_TX_BUFFER_COUNT (4U) +#endif +#ifndef ETH_TX_BUFFER_SIZE +#define ETH_TX_BUFFER_SIZE (1524U) +#endif +#ifndef ETH_RX_BUFFER_SIZE +#define ETH_RX_BUFFER_SIZE (256U) +#endif + +#if (ETH_RX_BUFFER_SIZE % 16) != 0 +/* For compatibility with 128bit memory interfaces, the buffer size needs to + * be a multiple of 16 Byte. For 64 bit memory interfaces need the size to be + * a multiple of 8 Byte, for 32 bit a multiple of 4 byte is sufficient. */ +#warning "ETH_RX_BUFFER_SIZE is not a multiple of 16. (See comment above.)" +#endif + +#if ETH_RX_BUFFER_COUNT * ETH_RX_BUFFER_SIZE < 1524U +#warning "Total RX buffers lower than MTU, you won't receive huge frames!" +#endif + #define MIN(a, b) (((a) <= (b)) ? (a) : (b)) /* Descriptors */