Skip to content

Corrected STM+K64F eth driver flagging, memory allocation and thread init #6266

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

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include "netsocket/nsapi_types.h"
#include "mbed_shared_queues.h"

#if DEVICE_EMAC

#include "fsl_phy.h"

#include "k64f_emac_config.h"
Expand Down Expand Up @@ -614,7 +612,5 @@ MBED_WEAK EMAC &EMAC::get_default_instance() {
* @}
*/

#endif // DEVICE_EMAC

/* --------------------------------- End Of File ------------------------------ */

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if MBED_CONF_LWIP_ETHERNET_ENABLED

#include <stdlib.h>
#include <stdlib.h>

#include "cmsis_os.h"

Expand Down Expand Up @@ -69,7 +67,9 @@ void ETH_IRQHandler(void);
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
{
STM32_EMAC &emac = STM32_EMAC::get_instance();
osThreadFlagsSet(emac.thread, FLAG_RX);
if (emac.thread) {
osThreadFlagsSet(emac.thread, FLAG_RX);
}
}

/**
Expand All @@ -85,6 +85,7 @@ void ETH_IRQHandler(void)
}

STM32_EMAC::STM32_EMAC()
: thread(0)
{
}

Expand Down Expand Up @@ -247,8 +248,10 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
uint16_t len = 0;
uint8_t *buffer;
__IO ETH_DMADescTypeDef *dmarxdesc;
uint32_t bufferoffset = 0;
uint32_t byteslefttocopy = 0;
emac_mem_buf_t *buf = 0;
emac_mem_buf_t *q;
uint32_t payloadoffset = 0;

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

if (len > 0) {
/* Allocate a contiguous memory buffer, if not available drop incoming frame */
buf = memory_manager->alloc_heap(len, 0);
/* Allocate a memory buffer chain from buffer pool */
buf = memory_manager->alloc_pool(len, 0);
}

if (buf) {
/* Check if the length of bytes to copy in current memory buffer is bigger than Rx buffer size*/
while (byteslefttocopy > ETH_RX_BUF_SIZE) {
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(buf)) + payloadoffset, buffer, ETH_RX_BUF_SIZE);

/* Point to next descriptor */
dmarxdesc = reinterpret_cast<ETH_DMADescTypeDef *>(dmarxdesc->Buffer2NextDescAddr);
buffer = reinterpret_cast<uint8_t *>(dmarxdesc->Buffer1Addr);

byteslefttocopy = byteslefttocopy - ETH_RX_BUF_SIZE;
payloadoffset = payloadoffset + ETH_RX_BUF_SIZE;
if (buf != NULL) {
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
bufferoffset = 0;
for (q = buf; q != NULL; q = memory_manager->get_next(q)) {
byteslefttocopy = memory_manager->get_len(q);
payloadoffset = 0;

/* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size*/
while ((byteslefttocopy + bufferoffset) > ETH_RX_BUF_SIZE) {
/* Copy data to pbuf */
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(q)) + payloadoffset, static_cast<uint8_t *>(buffer) + bufferoffset, ETH_RX_BUF_SIZE - bufferoffset);

/* Point to next descriptor */
dmarxdesc = reinterpret_cast<ETH_DMADescTypeDef *>(dmarxdesc->Buffer2NextDescAddr);
buffer = reinterpret_cast<uint8_t *>(dmarxdesc->Buffer1Addr);

byteslefttocopy = byteslefttocopy - (ETH_RX_BUF_SIZE - bufferoffset);
payloadoffset = payloadoffset + (ETH_RX_BUF_SIZE - bufferoffset);
bufferoffset = 0;
}
/* Copy remaining data in pbuf */
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(q)) + payloadoffset, static_cast<uint8_t *>(buffer) + bufferoffset, byteslefttocopy);
bufferoffset = bufferoffset + byteslefttocopy;
}
memcpy(static_cast<uint8_t *>(memory_manager->get_ptr(buf)) + payloadoffset, buffer, byteslefttocopy);
}

/* Release descriptors to DMA */
Expand Down Expand Up @@ -553,5 +567,3 @@ STM32_EMAC &STM32_EMAC::get_instance() {
MBED_WEAK EMAC &EMAC::get_default_instance() {
return STM32_EMAC::get_instance();
}

#endif
24 changes: 12 additions & 12 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
"supported_form_factors": ["ARDUINO"],
"core": "Cortex-M4F",
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "KPSDK_MCUS", "KPSDK_CODE", "MCU_K64F"],
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "KPSDK_MCUS", "KPSDK_CODE", "MCU_K64F", "Freescale_EMAC"],
"is_disk_virtual": true,
"macros": ["CPU_MK64FN1M0VMD12", "FSL_RTOS_MBED"],
"inherits": ["Target"],
Expand Down Expand Up @@ -671,7 +671,7 @@
"supported_form_factors": ["ARDUINO"],
"core": "Cortex-M4F",
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM"],
"extra_labels": ["Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "Freescale_EMAC"],
"is_disk_virtual": true,
"macros": ["CPU_MK66FN2M0VMD18", "FSL_RTOS_MBED"],
"inherits": ["Target"],
Expand Down Expand Up @@ -903,7 +903,7 @@
"inherits": ["FAMILY_STM32"],
"supported_form_factors": ["ARDUINO", "MORPHO"],
"core": "Cortex-M3",
"extra_labels_add": ["STM32F2", "STM32F207ZG"],
"extra_labels_add": ["STM32F2", "STM32F207ZG", "STM_EMAC"],
"config": {
"d11_configuration": {
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
Expand Down Expand Up @@ -1192,7 +1192,7 @@
"macro_name": "CLOCK_SOURCE_USB"
}
},
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI"],
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI", "STM_EMAC"],
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
"device_has_add": ["ANALOGOUT", "CAN", "EMAC", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"],
"detect_code": ["0796"],
Expand Down Expand Up @@ -1222,7 +1222,7 @@
"macro_name": "CLOCK_SOURCE_USB"
}
},
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI"],
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI", "STM_EMAC"],
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT", "USB_STM_HAL", "USBHOST_OTHER"],
"device_has_add": ["ANALOGOUT", "CAN", "EMAC", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"],
"detect_code": ["0797"],
Expand Down Expand Up @@ -1281,7 +1281,7 @@
"NUCLEO_F746ZG": {
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M7F",
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746ZG"],
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746ZG", "STM_EMAC"],
"config": {
"d11_configuration": {
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
Expand Down Expand Up @@ -1310,7 +1310,7 @@
"NUCLEO_F756ZG": {
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M7F",
"extra_labels_add": ["STM32F7", "STM32F756", "STM32F756xG", "STM32F756ZG"],
"extra_labels_add": ["STM32F7", "STM32F756", "STM32F756xG", "STM32F756ZG", "STM_EMAC"],
"config": {
"d11_configuration": {
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
Expand Down Expand Up @@ -1338,7 +1338,7 @@
"NUCLEO_F767ZI": {
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M7FD",
"extra_labels_add": ["STM32F7", "STM32F767", "STM32F767xI", "STM32F767ZI"],
"extra_labels_add": ["STM32F7", "STM32F767", "STM32F767xI", "STM32F767ZI", "STM_EMAC"],
"config": {
"d11_configuration": {
"help": "Value: PA_7 for the default board configuration, PB_5 in case of solder bridge update (SB121 off/ SB122 on)",
Expand Down Expand Up @@ -1791,7 +1791,7 @@
"DISCO_F746NG": {
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M7F",
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746NG"],
"extra_labels_add": ["STM32F7", "STM32F746", "STM32F746xG", "STM32F746NG", "STM_EMAC"],
"supported_form_factors": ["ARDUINO"],
"config": {
"clock_source": {
Expand All @@ -1818,7 +1818,7 @@
"DISCO_F769NI": {
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M7FD",
"extra_labels_add": ["STM32F7", "STM32F769", "STM32F769xI", "STM32F769NI"],
"extra_labels_add": ["STM32F7", "STM32F769", "STM32F769xI", "STM32F769NI", "STM_EMAC"],
"supported_form_factors": ["ARDUINO"],
"config": {
"clock_source": {
Expand Down Expand Up @@ -2039,7 +2039,7 @@
"MODULE_UBLOX_ODIN_W2": {
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M4F",
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI","STM32F439xx", "STM32F439xI"],
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI","STM32F439xx", "STM32F439xI", "STM_EMAC"],
"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"],
"device_has_add": ["CAN", "EMAC", "TRNG", "FLASH"],
"device_has_remove": ["RTC", "SLEEP"],
Expand Down Expand Up @@ -2085,7 +2085,7 @@
"supported_form_factors": ["ARDUINO"],
"core": "Cortex-M4F",
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
"extra_labels_add": ["STM32F4", "STM32F437", "STM32F437VG", "STM32F437xx", "STM32F437xG"],
"extra_labels_add": ["STM32F4", "STM32F437", "STM32F437VG", "STM32F437xx", "STM32F437xG", "STM_EMAC"],
"config": {
"modem_is_on_board": {
"help": "Value: Tells the build system that the modem is on-board as oppose to a plug-in shield/module.",
Expand Down