Skip to content

Commit 1cc95f6

Browse files
authored
Merge pull request #6266 from kjbracey-arm/emac_stm_corr
Corrected STM+K64F eth driver flagging, memory allocation and thread init
2 parents 8b0e2e0 + a7e9d95 commit 1cc95f6

File tree

31 files changed

+44
-36
lines changed

31 files changed

+44
-36
lines changed

features/netsocket/emac-drivers/TARGET_Freescale/k64f_emac.cpp renamed to features/netsocket/emac-drivers/TARGET_Freescale_EMAC/k64f_emac.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include "netsocket/nsapi_types.h"
4343
#include "mbed_shared_queues.h"
4444

45-
#if DEVICE_EMAC
46-
4745
#include "fsl_phy.h"
4846

4947
#include "k64f_emac_config.h"
@@ -614,7 +612,5 @@ MBED_WEAK EMAC &EMAC::get_default_instance() {
614612
* @}
615613
*/
616614

617-
#endif // DEVICE_EMAC
618-
619615
/* --------------------------------- End Of File ------------------------------ */
620616

features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp renamed to features/netsocket/emac-drivers/TARGET_STM_EMAC/stm32xx_emac.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#if MBED_CONF_LWIP_ETHERNET_ENABLED
2-
3-
#include <stdlib.h>
1+
#include <stdlib.h>
42

53
#include "cmsis_os.h"
64

@@ -69,7 +67,9 @@ void ETH_IRQHandler(void);
6967
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
7068
{
7169
STM32_EMAC &emac = STM32_EMAC::get_instance();
72-
osThreadFlagsSet(emac.thread, FLAG_RX);
70+
if (emac.thread) {
71+
osThreadFlagsSet(emac.thread, FLAG_RX);
72+
}
7373
}
7474

7575
/**
@@ -85,6 +85,7 @@ void ETH_IRQHandler(void)
8585
}
8686

8787
STM32_EMAC::STM32_EMAC()
88+
: thread(0)
8889
{
8990
}
9091

@@ -247,8 +248,10 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
247248
uint16_t len = 0;
248249
uint8_t *buffer;
249250
__IO ETH_DMADescTypeDef *dmarxdesc;
251+
uint32_t bufferoffset = 0;
250252
uint32_t byteslefttocopy = 0;
251253
emac_mem_buf_t *buf = 0;
254+
emac_mem_buf_t *q;
252255
uint32_t payloadoffset = 0;
253256

254257
/* get received frame */
@@ -264,23 +267,34 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
264267
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
265268

266269
if (len > 0) {
267-
/* Allocate a contiguous memory buffer, if not available drop incoming frame */
268-
buf = memory_manager->alloc_heap(len, 0);
270+
/* Allocate a memory buffer chain from buffer pool */
271+
buf = memory_manager->alloc_pool(len, 0);
269272
}
270273

271-
if (buf) {
272-
/* Check if the length of bytes to copy in current memory buffer is bigger than Rx buffer size*/
273-
while (byteslefttocopy > ETH_RX_BUF_SIZE) {
274-
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(buf)) + payloadoffset, buffer, ETH_RX_BUF_SIZE);
275-
276-
/* Point to next descriptor */
277-
dmarxdesc = reinterpret_cast<ETH_DMADescTypeDef *>(dmarxdesc->Buffer2NextDescAddr);
278-
buffer = reinterpret_cast<uint8_t *>(dmarxdesc->Buffer1Addr);
279-
280-
byteslefttocopy = byteslefttocopy - ETH_RX_BUF_SIZE;
281-
payloadoffset = payloadoffset + ETH_RX_BUF_SIZE;
274+
if (buf != NULL) {
275+
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
276+
bufferoffset = 0;
277+
for (q = buf; q != NULL; q = memory_manager->get_next(q)) {
278+
byteslefttocopy = memory_manager->get_len(q);
279+
payloadoffset = 0;
280+
281+
/* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size*/
282+
while ((byteslefttocopy + bufferoffset) > ETH_RX_BUF_SIZE) {
283+
/* Copy data to pbuf */
284+
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(q)) + payloadoffset, static_cast<uint8_t *>(buffer) + bufferoffset, ETH_RX_BUF_SIZE - bufferoffset);
285+
286+
/* Point to next descriptor */
287+
dmarxdesc = reinterpret_cast<ETH_DMADescTypeDef *>(dmarxdesc->Buffer2NextDescAddr);
288+
buffer = reinterpret_cast<uint8_t *>(dmarxdesc->Buffer1Addr);
289+
290+
byteslefttocopy = byteslefttocopy - (ETH_RX_BUF_SIZE - bufferoffset);
291+
payloadoffset = payloadoffset + (ETH_RX_BUF_SIZE - bufferoffset);
292+
bufferoffset = 0;
293+
}
294+
/* Copy remaining data in pbuf */
295+
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(q)) + payloadoffset, static_cast<uint8_t *>(buffer) + bufferoffset, byteslefttocopy);
296+
bufferoffset = bufferoffset + byteslefttocopy;
282297
}
283-
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(buf)) + payloadoffset, buffer, byteslefttocopy);
284298
}
285299

286300
/* Release descriptors to DMA */
@@ -553,5 +567,3 @@ STM32_EMAC &STM32_EMAC::get_instance() {
553567
MBED_WEAK EMAC &EMAC::get_default_instance() {
554568
return STM32_EMAC::get_instance();
555569
}
556-
557-
#endif

targets/targets.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609
"supported_form_factors": ["ARDUINO"],
610610
"core": "Cortex-M4F",
611611
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
612-
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "KPSDK_MCUS", "KPSDK_CODE", "MCU_K64F"],
612+
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "KPSDK_MCUS", "KPSDK_CODE", "MCU_K64F", "Freescale_EMAC"],
613613
"is_disk_virtual": true,
614614
"macros": ["CPU_MK64FN1M0VMD12", "FSL_RTOS_MBED"],
615615
"inherits": ["Target"],
@@ -671,7 +671,7 @@
671671
"supported_form_factors": ["ARDUINO"],
672672
"core": "Cortex-M4F",
673673
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
674-
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM"],
674+
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "Freescale_EMAC"],
675675
"is_disk_virtual": true,
676676
"macros": ["CPU_MK66FN2M0VMD18", "FSL_RTOS_MBED"],
677677
"inherits": ["Target"],
@@ -903,7 +903,7 @@
903903
"inherits": ["FAMILY_STM32"],
904904
"supported_form_factors": ["ARDUINO", "MORPHO"],
905905
"core": "Cortex-M3",
906-
"extra_labels_add": ["STM32F2", "STM32F207ZG"],
906+
"extra_labels_add": ["STM32F2", "STM32F207ZG", "STM_EMAC"],
907907
"config": {
908908
"d11_configuration": {
909909
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
@@ -1192,7 +1192,7 @@
11921192
"macro_name": "CLOCK_SOURCE_USB"
11931193
}
11941194
},
1195-
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI"],
1195+
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI", "STM_EMAC"],
11961196
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
11971197
"device_has_add": ["ANALOGOUT", "CAN", "EMAC", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"],
11981198
"detect_code": ["0796"],
@@ -1222,7 +1222,7 @@
12221222
"macro_name": "CLOCK_SOURCE_USB"
12231223
}
12241224
},
1225-
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI"],
1225+
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI", "STM_EMAC"],
12261226
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT", "USB_STM_HAL", "USBHOST_OTHER"],
12271227
"device_has_add": ["ANALOGOUT", "CAN", "EMAC", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"],
12281228
"detect_code": ["0797"],
@@ -1281,7 +1281,7 @@
12811281
"NUCLEO_F746ZG": {
12821282
"inherits": ["FAMILY_STM32"],
12831283
"core": "Cortex-M7F",
1284-
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746ZG"],
1284+
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746ZG", "STM_EMAC"],
12851285
"config": {
12861286
"d11_configuration": {
12871287
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
@@ -1310,7 +1310,7 @@
13101310
"NUCLEO_F756ZG": {
13111311
"inherits": ["FAMILY_STM32"],
13121312
"core": "Cortex-M7F",
1313-
"extra_labels_add": ["STM32F7", "STM32F756", "STM32F756xG", "STM32F756ZG"],
1313+
"extra_labels_add": ["STM32F7", "STM32F756", "STM32F756xG", "STM32F756ZG", "STM_EMAC"],
13141314
"config": {
13151315
"d11_configuration": {
13161316
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
@@ -1338,7 +1338,7 @@
13381338
"NUCLEO_F767ZI": {
13391339
"inherits": ["FAMILY_STM32"],
13401340
"core": "Cortex-M7FD",
1341-
"extra_labels_add": ["STM32F7", "STM32F767", "STM32F767xI", "STM32F767ZI"],
1341+
"extra_labels_add": ["STM32F7", "STM32F767", "STM32F767xI", "STM32F767ZI", "STM_EMAC"],
13421342
"config": {
13431343
"d11_configuration": {
13441344
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
@@ -1791,7 +1791,7 @@
17911791
"DISCO_F746NG": {
17921792
"inherits": ["FAMILY_STM32"],
17931793
"core": "Cortex-M7F",
1794-
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746NG"],
1794+
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746NG", "STM_EMAC"],
17951795
"supported_form_factors": ["ARDUINO"],
17961796
"config": {
17971797
"clock_source": {
@@ -1818,7 +1818,7 @@
18181818
"DISCO_F769NI": {
18191819
"inherits": ["FAMILY_STM32"],
18201820
"core": "Cortex-M7FD",
1821-
"extra_labels_add": ["STM32F7", "STM32F769", "STM32F769xI", "STM32F769NI"],
1821+
"extra_labels_add": ["STM32F7", "STM32F769", "STM32F769xI", "STM32F769NI", "STM_EMAC"],
18221822
"supported_form_factors": ["ARDUINO"],
18231823
"config": {
18241824
"clock_source": {
@@ -2039,7 +2039,7 @@
20392039
"MODULE_UBLOX_ODIN_W2": {
20402040
"inherits": ["FAMILY_STM32"],
20412041
"core": "Cortex-M4F",
2042-
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI","STM32F439xx", "STM32F439xI"],
2042+
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI","STM32F439xx", "STM32F439xI", "STM_EMAC"],
20432043
"macros": ["MBEDTLS_CONFIG_HW_SUPPORT", "HSE_VALUE=24000000", "HSE_STARTUP_TIMEOUT=5000", "CB_INTERFACE_SDIO","CB_CHIP_WL18XX","SUPPORT_80211D_ALWAYS","WLAN_ENABLED","MBEDTLS_ARC4_C","MBEDTLS_DES_C","MBEDTLS_MD4_C","MBEDTLS_MD5_C","MBEDTLS_SHA1_C"],
20442044
"device_has_add": ["CAN", "EMAC", "TRNG", "FLASH"],
20452045
"device_has_remove": ["RTC", "SLEEP"],
@@ -2085,7 +2085,7 @@
20852085
"supported_form_factors": ["ARDUINO"],
20862086
"core": "Cortex-M4F",
20872087
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
2088-
"extra_labels_add": ["STM32F4", "STM32F437", "STM32F437VG", "STM32F437xx", "STM32F437xG"],
2088+
"extra_labels_add": ["STM32F4", "STM32F437", "STM32F437VG", "STM32F437xx", "STM32F437xG", "STM_EMAC"],
20892089
"config": {
20902090
"modem_is_on_board": {
20912091
"help": "Value: Tells the build system that the modem is on-board as oppose to a plug-in shield/module.",

0 commit comments

Comments
 (0)