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

[rtl872x] refactors SPI implementation, a couple of Wiznetif driver workarounds, test #2728

Merged
merged 2 commits into from Jan 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions hal/network/lwip/wiznet/wiznetif.cpp
Expand Up @@ -520,9 +520,9 @@ int WizNetif::input() {
pktSize = (tmp[0] << 8 | tmp[1]) - 2;
}

// LOG_DEBUG(TRACE, "Received packet, %d bytes", pktSize);

if (pktSize >= 1514) {
if (pktSize >= 1522 /* IEEE 802.3ac max size */) {
// Attempt to recover
wiz_recv_ignore(0, pktSize + 2);
closeRaw();
openRaw();
return r;
Expand Down Expand Up @@ -615,7 +615,14 @@ void WizNetif::output(pbuf* p) {

if (p->tot_len > txAvailable || txAvailable == 0xffff) {
/* Drop packet */
LOG(ERROR, "Dropping packet, not enough space in TX buffer");
LOG(ERROR, "Dropping packet, not enough space in TX buffer %u", txAvailable);
// FIXME: this should normally not happen, attempt to recover
setSn_TX_WR(0, 0);
setSn_CR(0, Sn_CR_SEND);
if (getSn_TX_FSR(0) < p->tot_len) {
down();
up();
}
goto cleanup;
}

Expand Down
1 change: 1 addition & 0 deletions hal/shared/spi_lock.h
Expand Up @@ -99,6 +99,7 @@ class SpiConfigurationLock {
return true;
}

// FIXME: clock may not equal if base clock is not divisible by the desired clock
if (lh.mode == rh.mode &&
lh.default_settings == rh.default_settings &&
lh.clock == rh.clock &&
Expand Down
8 changes: 7 additions & 1 deletion hal/src/nRF52840/spi_hal.cpp
Expand Up @@ -29,6 +29,7 @@

#include <memory>
#include <cstdlib>
#include <limits>

#define DEFAULT_SPI_MODE SPI_MODE_MASTER
#define DEFAULT_DATA_MODE SPI_MODE3
Expand Down Expand Up @@ -695,8 +696,13 @@ int32_t hal_spi_release(hal_spi_interface_t spi, void* reserved) {
int hal_spi_get_clock_divider(hal_spi_interface_t spi, uint32_t clock, void* reserved) {
CHECK_TRUE(clock > 0, SYSTEM_ERROR_INVALID_ARGUMENT);

// For clock rates which are not fractions of base clock use next power of 2 divisor
// to be under the requested clock rate
uint32_t div = SPI_SYSTEM_CLOCK / clock;
div = div == 1 ? 1 : 1 << (std::numeric_limits<uint32_t>::digits - __builtin_clz(div - 1));

// Integer division results in clean values
switch (SPI_SYSTEM_CLOCK / clock) {
switch (div) {
case 2:
return SPI_CLOCK_DIV2;
case 4:
Expand Down
2 changes: 2 additions & 0 deletions hal/src/rtl872x/hal_platform_rtl8721x_config.h
Expand Up @@ -148,3 +148,5 @@
#define HAL_PLATFORM_HEAP_REGION_PSRAM (1)

#define HAL_PLATFORM_ASSETS (1)

#define HAL_PLATFORM_ETHERNET_FEATHERWING_SPI_CLOCK (25000000)
2 changes: 1 addition & 1 deletion hal/src/rtl872x/interrupts_hal.cpp
Expand Up @@ -482,7 +482,7 @@ void hal_interrupt_restore(void) {
if (interruptsConfig[i].state == INT_STATE_SUSPENDED) {
uint32_t trigger = 0, polarity = 0;
parseMode(interruptsConfig[i].mode, &trigger, &polarity);
GPIO_INTMode(rtlPin, ENABLE, trigger, polarity, GPIO_INT_DEBOUNCE_ENABLE);
GPIO_INTMode(rtlPin, ENABLE, trigger, polarity, GPIO_INT_DEBOUNCE_DISABLE);
GPIO_INTConfig(rtlPin, ENABLE);
interruptsConfig[i].state = INT_STATE_ENABLED;
} else {
Expand Down