From 13acf60c7eeec027766795abab775744cfe4bd42 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Fri, 28 Jul 2023 12:44:23 +1000 Subject: [PATCH] AP_Networking: fix allocation of mac trx buffers --- libraries/AP_Networking/AP_Networking.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/AP_Networking/AP_Networking.cpp b/libraries/AP_Networking/AP_Networking.cpp index 02d9107476..d534f13bf4 100644 --- a/libraries/AP_Networking/AP_Networking.cpp +++ b/libraries/AP_Networking/AP_Networking.cpp @@ -173,8 +173,8 @@ AP_Networking::AP_Networking(void) #ifdef STM32_ETH_BUFFERS_EXTERN stm32_eth_rx_descriptor_t *__eth_rd; stm32_eth_tx_descriptor_t *__eth_td; -uint32_t **__eth_rb; -uint32_t **__eth_tb; +uint32_t *__eth_rb[STM32_MAC_RECEIVE_BUFFERS]; +uint32_t *__eth_tb[STM32_MAC_TRANSMIT_BUFFERS]; #endif @@ -187,7 +187,7 @@ static bool allocate_buffers() const uint32_t eth_td_size = sizeof(stm32_eth_tx_descriptor_t)*STM32_MAC_TRANSMIT_BUFFERS; const uint32_t eth_rb_size = sizeof(uint32_t)*STM32_MAC_RECEIVE_BUFFERS*BUFFER_SIZE; const uint32_t eth_tb_size = sizeof(uint32_t)*STM32_MAC_TRANSMIT_BUFFERS*BUFFER_SIZE; - const uint32_t total_size = eth_rd_size + eth_rd_size + eth_rb_size + eth_tb_size; // == 9240 + const uint32_t total_size = eth_rd_size + eth_td_size + eth_rb_size + eth_tb_size; // == 9240 // ensure that we allocate 32-bit aligned memory, and mark it non-cacheable uint32_t size = 2; @@ -219,8 +219,14 @@ static bool allocate_buffers() // assign buffers __eth_rd = (stm32_eth_rx_descriptor_t *)mem; __eth_td = (stm32_eth_tx_descriptor_t *)&__eth_rd[STM32_MAC_RECEIVE_BUFFERS]; - __eth_rb = (uint32_t **)((uint32_t)__eth_td + eth_td_size); - __eth_tb = (uint32_t **)((uint32_t)__eth_rb + eth_rb_size); + __eth_rb[0] = (uint32_t*)&__eth_td[STM32_MAC_TRANSMIT_BUFFERS]; + for (uint16_t i = 1; i < STM32_MAC_RECEIVE_BUFFERS; i++) { + __eth_rb[i] = &(__eth_rb[i-1][BUFFER_SIZE]); + } + __eth_tb[0] = &(__eth_rb[STM32_MAC_RECEIVE_BUFFERS-1][BUFFER_SIZE]); + for (uint16_t i = 1; i < STM32_MAC_TRANSMIT_BUFFERS; i++) { + __eth_tb[i] = &(__eth_tb[i-1][BUFFER_SIZE]); + } #endif return true;