Skip to content

Commit 5f6e4af

Browse files
Allow LWIP Ethernet HW IRQs > 32 (#2464)
Allow RP2350B boards to use GPIOs 31+ for the Ethernet HW IRQ line. Also update SPI debug output with the new registers.
1 parent 4d1d1d2 commit 5f6e4af

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

libraries/SPI/src/SPI.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ void SPIClassRP2040::transfer(const void *txbuf, void *rxbuf, size_t count) {
179179
DEBUGSPI("SPI::transfer completed\n");
180180
}
181181

182+
#ifdef PICO_RP2350B
183+
#define GPIOIRQREGS 6
184+
#else
185+
#define GPIOIRQREGS 4
186+
#endif
187+
182188
void SPIClassRP2040::beginTransaction(SPISettings settings) {
183189
noInterrupts(); // Avoid possible race conditions if IRQ comes in while main app is in middle of this
184190
DEBUGSPI("SPI::beginTransaction(clk=%lu, bo=%s)\n", settings.getClockFreq(), (settings.getBitOrder() == MSBFIRST) ? "MSB" : "LSB");
@@ -201,7 +207,7 @@ void SPIClassRP2040::beginTransaction(SPISettings settings) {
201207
}
202208
// Disable any IRQs that are being used for SPI
203209
io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ? &iobank0_hw->proc1_irq_ctrl : &iobank0_hw->proc0_irq_ctrl;
204-
DEBUGSPI("SPI: IRQ masks before = %08x %08x %08x %08x\n", (unsigned)irq_ctrl_base->inte[0], (unsigned)irq_ctrl_base->inte[1], (unsigned)irq_ctrl_base->inte[2], (unsigned)irq_ctrl_base->inte[3]);
210+
DEBUGSPI("SPI: IRQ masks before = %08x %08x %08x %08x %08x %08x\n", (unsigned)irq_ctrl_base->inte[0], (unsigned)irq_ctrl_base->inte[1], (unsigned)irq_ctrl_base->inte[2], (unsigned)irq_ctrl_base->inte[3], (GPIOIRQREGS > 4) ? (unsigned)irq_ctrl_base->inte[4] : 0, (GPIOIRQREGS > 5) ? (unsigned)irq_ctrl_base->inte[5] : 0);
205211
for (auto entry : _usingIRQs) {
206212
int gpio = entry.first;
207213

@@ -212,7 +218,7 @@ void SPIClassRP2040::beginTransaction(SPISettings settings) {
212218
DEBUGSPI("SPI: GPIO %d = %lu\n", gpio, val);
213219
(*en_reg) ^= val << (4 * (gpio % 8));
214220
}
215-
DEBUGSPI("SPI: IRQ masks after = %08x %08x %08x %08x\n", (unsigned)irq_ctrl_base->inte[0], (unsigned)irq_ctrl_base->inte[1], (unsigned)irq_ctrl_base->inte[2], (unsigned)irq_ctrl_base->inte[3]);
221+
DEBUGSPI("SPI: IRQ masks after = %08x %08x %08x %08x %08x %08x\n", (unsigned)irq_ctrl_base->inte[0], (unsigned)irq_ctrl_base->inte[1], (unsigned)irq_ctrl_base->inte[2], (unsigned)irq_ctrl_base->inte[3], (GPIOIRQREGS > 4) ? (unsigned)irq_ctrl_base->inte[4] : 0, (GPIOIRQREGS > 5) ? (unsigned)irq_ctrl_base->inte[5] : 0);
216222
interrupts();
217223
}
218224

@@ -227,7 +233,7 @@ void SPIClassRP2040::endTransaction(void) {
227233
}
228234
io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ? &iobank0_hw->proc1_irq_ctrl : &iobank0_hw->proc0_irq_ctrl;
229235
(void) irq_ctrl_base;
230-
DEBUGSPI("SPI: IRQ masks = %08x %08x %08x %08x\n", (unsigned)irq_ctrl_base->inte[0], (unsigned)irq_ctrl_base->inte[1], (unsigned)irq_ctrl_base->inte[2], (unsigned)irq_ctrl_base->inte[3]);
236+
DEBUGSPI("SPI: IRQ masks = %08x %08x %08x %08x %08x %08x\n", (unsigned)irq_ctrl_base->inte[0], (unsigned)irq_ctrl_base->inte[1], (unsigned)irq_ctrl_base->inte[2], (unsigned)irq_ctrl_base->inte[3], (GPIOIRQREGS > 4) ? (unsigned)irq_ctrl_base->inte[4] : 0, (GPIOIRQREGS > 5) ? (unsigned)irq_ctrl_base->inte[5] : 0);
231237
interrupts();
232238
}
233239

libraries/lwIP_Ethernet/src/LwipEthernet.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,22 @@ void __removeEthernetPacketHandler(int id) {
7575
}
7676

7777
#define GPIOSTACKSIZE 8
78-
static uint32_t gpioMaskStack[GPIOSTACKSIZE][4];
79-
static uint32_t gpioMask[4] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};
78+
#ifdef PICO_RP2350B
79+
#define GPIOIRQREGS 6
80+
#define GPIOIRQREGSINIT 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
81+
#else
82+
#define GPIOIRQREGS 4
83+
#define GPIOIRQREGSINIT 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
84+
#endif
85+
86+
static uint32_t gpioMaskStack[GPIOSTACKSIZE][GPIOIRQREGS];
87+
static uint32_t gpioMask[GPIOIRQREGS] = {GPIOIRQREGSINIT};
8088

8189
void ethernet_arch_lwip_gpio_mask() {
8290
noInterrupts();
83-
memmove(gpioMaskStack[1], gpioMaskStack[0], 4 * sizeof(uint32_t) * (GPIOSTACKSIZE - 1)); // Push down the stack
91+
memmove(gpioMaskStack[1], gpioMaskStack[0], GPIOIRQREGS * sizeof(uint32_t) * (GPIOSTACKSIZE - 1)); // Push down the stack
8492
io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ? &io_bank0_hw->proc1_irq_ctrl : &io_bank0_hw->proc0_irq_ctrl;
85-
for (int i = 0; i < 4; i++) {
93+
for (int i = 0; i < GPIOIRQREGS; i++) {
8694
gpioMaskStack[0][i] = irq_ctrl_base->inte[i];
8795
irq_ctrl_base->inte[i] = irq_ctrl_base->inte[i] & gpioMask[i];
8896
}
@@ -92,10 +100,10 @@ void ethernet_arch_lwip_gpio_mask() {
92100
void ethernet_arch_lwip_gpio_unmask() {
93101
noInterrupts();
94102
io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ? &io_bank0_hw->proc1_irq_ctrl : &io_bank0_hw->proc0_irq_ctrl;
95-
for (int i = 0; i < 4; i++) {
103+
for (int i = 0; i < GPIOIRQREGS; i++) {
96104
irq_ctrl_base->inte[i] = gpioMaskStack[0][i];
97105
}
98-
memmove(gpioMaskStack[0], gpioMaskStack[1], 4 * sizeof(uint32_t) * (GPIOSTACKSIZE - 1)); // Pop up the stack
106+
memmove(gpioMaskStack[0], gpioMaskStack[1], GPIOIRQREGS * sizeof(uint32_t) * (GPIOSTACKSIZE - 1)); // Pop up the stack
99107
interrupts();
100108
}
101109

0 commit comments

Comments
 (0)