Skip to content
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

fix for dhcp not asking for address when host if goes down and up again #35

Open
wants to merge 5 commits into
base: extrapatches-6.17.0
Choose a base branch
from
Open
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 @@ -66,7 +66,10 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)

#if !(defined(DUAL_CORE) && defined(CORE_CM4))
/* Disable DCache for STM32H7 family */
core_util_critical_section_enter();
SCB_CleanInvalidateDCache();
SCB_DisableDCache();
core_util_critical_section_exit();
#endif

/* GPIO Ports Clock Enable */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
#if !(defined(DUAL_CORE) && defined(CORE_CM4))
/* Disable DCache for STM32H7 family */
core_util_critical_section_enter();
SCB_CleanInvalidateDCache();
SCB_DisableDCache();
core_util_critical_section_exit();
#endif
Expand Down
27 changes: 27 additions & 0 deletions connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,33 @@ bool STM32_EMAC::low_level_init_successful()
}
#endif // ETH_IP_VERSION_V2

/**
* This function get the state of emac interface
*/
int STM32_EMAC::get_interface_status() {
return HAL_ETH_GetStateOnly(&EthHandle);
}

/**
* This function returns true if the status of the interface is in the
* correct state for the trasmission
*/
bool STM32_EMAC::is_ready_to_tx() {
return (HAL_ETH_GetStateOnly(&EthHandle) == HAL_ETH_STATE_READY);
}

/**
* This function reset the emac interface in case the status is in error
* Apparently there was not anything to recover from an error state
*/
void STM32_EMAC::restart() {
if(HAL_ETH_STATE_ERROR == HAL_ETH_GetStateOnly(&EthHandle)){
HAL_ETH_Stop(&EthHandle);
HAL_ETH_Start(&EthHandle);
}
}


/**
* This function should do the actual transmission of the packet. The packet is
* contained in the memory buffer chain that is passed to the function.
Expand Down
7 changes: 7 additions & 0 deletions connectivity/drivers/emac/TARGET_STM/stm32xx_emac.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ class STM32_EMAC : public EMAC {
*/
virtual void set_memory_manager(EMACMemoryManager &mem_mngr);

/* return the status of the interface as integer */
int get_interface_status() override;
/* return true if the interface is in the correct state to transmit */
bool is_ready_to_tx() override;
/* restart only if the interface is in error state */
void restart() override;

// Called from driver functions
ETH_HandleTypeDef EthHandle;
osThreadId_t thread; /**< Processing thread */
Expand Down
6 changes: 5 additions & 1 deletion connectivity/lwipstack/source/LWIPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ nsapi_error_t LWIP::Interface::set_dhcp()

#if LWIP_DHCP
if (dhcp_has_to_be_set) {
if(dhcp_started) {
dhcp_stop(&netif);
dhcp_started = false;
}

err_t err = dhcp_start(&netif);
dhcp_has_to_be_set = false;
if (err) {
connected = NSAPI_STATUS_DISCONNECTED;
if (client_callback) {
Expand Down
15 changes: 13 additions & 2 deletions connectivity/lwipstack/source/LWIPInterfaceEMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@

#if LWIP_ETHERNET


err_t LWIP::Interface::emac_low_level_output(struct netif *netif, struct pbuf *p)
{
bool ret = false;
/* Increase reference counter since lwip stores handle to pbuf and frees
it after output */
pbuf_ref(p);

LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
bool ret = mbed_if->emac->link_out(p);
return ret ? ERR_OK : ERR_IF;

if(mbed_if->emac->is_ready_to_tx()) {
ret = mbed_if->emac->link_out(p);
}
else {
mbed_if->emac->restart();
ret = mbed_if->emac->link_out(p);
}

err_t rv = ret ? ERR_OK : ERR_IF;
return rv;
}

void LWIP::Interface::emac_input(emac_mem_buf_t *buf)
Expand Down
11 changes: 11 additions & 0 deletions connectivity/netsocket/include/netsocket/EMAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ class EMAC {
* @param mem_mngr Pointer to memory manager
*/
virtual void set_memory_manager(EMACMemoryManager &mem_mngr) = 0;

virtual bool is_ready_to_tx() {
return false;
}

virtual void restart() {
}

virtual int get_interface_status() {
return -1;
}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,10 @@ HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFi
* @{
*/

HAL_ETH_StateTypeDef HAL_ETH_GetStateOnly(ETH_HandleTypeDef *heth) {
return heth->gState;
}

/**
* @brief Returns the ETH state.
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,7 @@ HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFi
*/
/* Peripheral State functions **************************************************/
HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth);
HAL_ETH_StateTypeDef HAL_ETH_GetStateOnly(ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetError(ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetDMAError(ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetMACError(ETH_HandleTypeDef *heth);
Expand Down
Loading