Skip to content

Commit 7204508

Browse files
committed
fix that restart interface in case of error (DEBUG LOG TO BE REMOVED)
1 parent f1c8d7a commit 7204508

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,33 @@ bool STM32_EMAC::low_level_init_successful()
402402
}
403403
#endif // ETH_IP_VERSION_V2
404404

405+
/**
406+
* This function get the state of emac interface
407+
*/
408+
int STM32_EMAC::get_interface_status() {
409+
return HAL_ETH_GetStateOnly(&EthHandle);
410+
}
411+
412+
/**
413+
* This function returns true if the status of the interface is in the
414+
* correct state for the trasmission
415+
*/
416+
bool STM32_EMAC::is_ready_to_tx() {
417+
return (HAL_ETH_GetStateOnly(&EthHandle) == HAL_ETH_STATE_READY);
418+
}
419+
420+
/**
421+
* This function reset the emac interface in case the status is in error
422+
* Apparently there was not anything to recover from an error state
423+
*/
424+
void STM32_EMAC::restart() {
425+
if(HAL_ETH_STATE_ERROR == HAL_ETH_GetStateOnly(&EthHandle)){
426+
HAL_ETH_Stop(&EthHandle);
427+
HAL_ETH_Start(&EthHandle);
428+
}
429+
}
430+
431+
405432
/**
406433
* This function should do the actual transmission of the packet. The packet is
407434
* contained in the memory buffer chain that is passed to the function.

connectivity/drivers/emac/TARGET_STM/stm32xx_emac.h

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ class STM32_EMAC : public EMAC {
148148
*/
149149
virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
150150

151+
/* return the status of the interface as integer */
152+
int get_interface_status() override;
153+
/* return true if the interface is in the correct state to transmit */
154+
bool is_ready_to_tx() override;
155+
/* restart only if the interface is in error state */
156+
void restart() override;
157+
151158
// Called from driver functions
152159
ETH_HandleTypeDef EthHandle;
153160
osThreadId_t thread; /**< Processing thread */

connectivity/lwipstack/source/LWIPInterface.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ nsapi_error_t LWIP::Interface::set_dhcp()
175175
}
176176

177177
err_t err = dhcp_start(&netif);
178-
dhcp_has_to_be_set = false;
179178
if (err) {
180179
connected = NSAPI_STATUS_DISCONNECTED;
181180
if (client_callback) {
@@ -204,9 +203,6 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
204203
netif_set_down(&interface->netif);
205204
}
206205
} else {
207-
if(interface->dhcp_started) {
208-
interface->dhcp_has_to_be_set = true;
209-
}
210206
osSemaphoreRelease(interface->unlinked);
211207
if (netif_is_up(&interface->netif)) {
212208
interface->connected = NSAPI_STATUS_CONNECTING;

connectivity/lwipstack/source/LWIPInterfaceEMAC.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,28 @@
2727

2828
#if LWIP_ETHERNET
2929

30+
extern "C" void log_add(const char *fmt, ...);
31+
3032
err_t LWIP::Interface::emac_low_level_output(struct netif *netif, struct pbuf *p)
3133
{
34+
bool ret = false;
3235
/* Increase reference counter since lwip stores handle to pbuf and frees
3336
it after output */
3437
pbuf_ref(p);
3538

3639
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
37-
bool ret = mbed_if->emac->link_out(p);
38-
return ret ? ERR_OK : ERR_IF;
40+
41+
if(mbed_if->emac->is_ready_to_tx()) {
42+
ret = mbed_if->emac->link_out(p);
43+
}
44+
else {
45+
log_add("!!!! emac is NOT OK ---> RESTART!!!");
46+
mbed_if->emac->restart();
47+
ret = mbed_if->emac->link_out(p);
48+
}
49+
50+
err_t rv = ret ? ERR_OK : ERR_IF;
51+
return rv;
3952
}
4053

4154
void LWIP::Interface::emac_input(emac_mem_buf_t *buf)

connectivity/netsocket/include/netsocket/EMAC.h

+4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ class EMAC {
176176
* @param mem_mngr Pointer to memory manager
177177
*/
178178
virtual void set_memory_manager(EMACMemoryManager &mem_mngr) = 0;
179+
180+
virtual bool is_ready_to_tx() { return false;}
181+
virtual void restart() {}
182+
virtual int get_interface_status() { return -1; }
179183
};
180184

181185

targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_eth.c

+4
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,10 @@ HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFi
23332333
* @{
23342334
*/
23352335

2336+
HAL_ETH_StateTypeDef HAL_ETH_GetStateOnly(ETH_HandleTypeDef *heth) {
2337+
return heth->gState;
2338+
}
2339+
23362340
/**
23372341
* @brief Returns the ETH state.
23382342
* @param heth: pointer to a ETH_HandleTypeDef structure that contains

targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_eth.h

+1
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,7 @@ HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFi
16541654
*/
16551655
/* Peripheral State functions **************************************************/
16561656
HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth);
1657+
HAL_ETH_StateTypeDef HAL_ETH_GetStateOnly(ETH_HandleTypeDef *heth);
16571658
uint32_t HAL_ETH_GetError(ETH_HandleTypeDef *heth);
16581659
uint32_t HAL_ETH_GetDMAError(ETH_HandleTypeDef *heth);
16591660
uint32_t HAL_ETH_GetMACError(ETH_HandleTypeDef *heth);

0 commit comments

Comments
 (0)