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

Makes the Ethernet reset pin optional. #2794

Merged
merged 3 commits into from
Jul 26, 2024
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
24 changes: 21 additions & 3 deletions hal/network/lwip/wiznet/wiznetif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,15 @@ err_t WizNetif::initInterface() {
if (!isPresent()) {
pwrState_ = IF_POWER_STATE_DOWN;
if (postpone_) {
// Note: We don't need to perform soft-reset when the chip is detected later on,
// since the other time the chip is probably powered cycled.
return ERR_OK;
}
return ERR_IF;
}
if (reset_ == PIN_INVALID) {
swReset();
}
pwrState_ = IF_POWER_STATE_UP;

return ERR_OK;
Expand All @@ -302,9 +307,22 @@ void WizNetif::hwReset() {
HAL_Delay_Milliseconds(1);
}

bool WizNetif::isPresent() {
/* VERSIONR always indicates the W5500 version as 0x04 */
const uint8_t cv = getVERSIONR();
void WizNetif::swReset() {
wizchip_sw_reset();
}

bool WizNetif::isPresent(bool retry) {
uint8_t retries = retry ? 10 : 1;
uint8_t cv = 0;
for (uint8_t i = 0; i < retries; i++) {
cv = getVERSIONR();
/* VERSIONR always indicates the W5500 version as 0x04 */
if (cv != 0x04 && retry) {
HAL_Delay_Milliseconds(50);
continue;
}
break;
}
if (cv != 0x04) {
LOG(INFO, "No W5500 present");
return false;
Expand Down
3 changes: 2 additions & 1 deletion hal/network/lwip/wiznet/wiznetif.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WizNetif : public BaseNetif {

virtual int getPowerState(if_power_state_t* state) const override;
virtual int getNcpState(unsigned int* state) const override;
bool isPresent();
bool isPresent(bool retry = false);

static WizNetif* instance() {
return instance_;
Expand All @@ -59,6 +59,7 @@ class WizNetif : public BaseNetif {
err_t initInterface();

void hwReset();
void swReset();

static void interruptCb(void* arg);
static void loop(void* arg);
Expand Down
6 changes: 1 addition & 5 deletions hal/network/lwip/wiznet/wiznetif_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ int WizNetifConfig::getConfigData(WizNetifConfigData* configData) {
if (configData->cs_pin == PIN_INVALID) {
configData->cs_pin = HAL_PLATFORM_ETHERNET_WIZNETIF_CS_PIN_DEFAULT;
}
if (configData->reset_pin == PIN_INVALID) {
configData->reset_pin = HAL_PLATFORM_ETHERNET_WIZNETIF_RESET_PIN_DEFAULT;
}
logWizNetifConfigData(wizNetifConfigData_);

return SYSTEM_ERROR_NONE;
Expand All @@ -164,8 +161,7 @@ int WizNetifConfig::validateWizNetifConfigData(const WizNetifConfigData* configD
// XXX: If we add a new version in the future this will need to handle that
if (configData->size != sizeof(WizNetifConfigData) ||
configData->version != WIZNETIF_CONFIG_DATA_VERSION ||
!isPinValid(configData->cs_pin) ||
!isPinValid(configData->reset_pin)) {
!isPinValid(configData->cs_pin)) {
LOG(ERROR, "configData not valid! size:%u ver:%u cs_pin:%u reset_pin:%u int_pin:%u",
configData->size,
configData->version,
Expand Down
5 changes: 3 additions & 2 deletions hal/src/b5som/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ int if_init_platform_postpone(void*) {
uint8_t dummy;
if (!if_get_index(en2->interface(), &dummy)) {
auto wizNetif = reinterpret_cast<WizNetif*>(en2);
if (wizNetif->isPresent()) {
if (wizNetif->isPresent(true)) {
LOG(INFO, "W5500 present");
return 0;
}
LOG(INFO, "Remove Ethernet interface");
netifapi_netif_remove(en2->interface());
}
LOG(INFO, "Ethernet interface is not present");
delete en2;
en2 = nullptr;
}
Expand Down
5 changes: 3 additions & 2 deletions hal/src/boron/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ int if_init_platform_postpone(void*) {
uint8_t dummy;
if (!if_get_index(en2->interface(), &dummy)) {
auto wizNetif = reinterpret_cast<WizNetif*>(en2);
if (wizNetif->isPresent()) {
if (wizNetif->isPresent(true)) {
LOG(INFO, "W5500 present");
return 0;
}
LOG(INFO, "Remove Ethernet interface");
netifapi_netif_remove(en2->interface());
}
LOG(INFO, "Ethernet interface is not present");
delete en2;
en2 = nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion hal/src/msom/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ int if_init_platform_postpone(void*) {
uint8_t dummy;
if (!if_get_index(en2->interface(), &dummy)) {
auto wizNetif = reinterpret_cast<WizNetif*>(en2);
if (wizNetif->isPresent()) {
if (wizNetif->isPresent(true)) {
LOG(INFO, "W5500 present");
return 0;
}
LOG(INFO, "Remove Ethernet interface");
Expand Down