14
14
#include "shared-bindings/microcontroller/Pin.h"
15
15
#include "shared-bindings/memorymap/AddressRange.h"
16
16
17
+ #if defined(PICO_RP2040 )
17
18
#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h"
19
+ #include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h"
20
+ #elif defined(PICO_RP2350 )
21
+ #include "src/rp2350/hardware_regs/include/hardware/platform_defs.h"
22
+ #include "src/rp2350/hardware_structs/include/hardware/structs/iobank0.h"
23
+ #endif
24
+
18
25
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
19
26
#include "src/rp2_common/hardware_dma/include/hardware/dma.h"
20
27
#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h"
21
- #include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h"
22
28
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
23
29
24
30
#include "shared/runtime/interrupt_char.h"
@@ -222,7 +228,7 @@ static bool is_gpio_compatible(PIO pio, uint32_t used_gpio_ranges) {
222
228
#endif
223
229
}
224
230
225
- static bool use_existing_program (PIO * pio_out , uint * sm_out , int * offset_inout , uint32_t program_id , size_t program_len , uint gpio_base , uint gpio_count ) {
231
+ static bool use_existing_program (PIO * pio_out , int * sm_out , int * offset_inout , uint32_t program_id , size_t program_len , uint gpio_base , uint gpio_count ) {
226
232
uint32_t required_gpio_ranges ;
227
233
if (gpio_count ) {
228
234
required_gpio_ranges = (1u << (gpio_base >> 4 )) |
@@ -307,12 +313,12 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
307
313
.origen = offset ,
308
314
};
309
315
PIO pio ;
310
- uint state_machine ;
316
+ int state_machine ;
311
317
bool added = false;
312
318
313
319
if (!use_existing_program (& pio , & state_machine , & offset , program_id , program_len , gpio_base , gpio_count )) {
314
320
uint program_offset ;
315
- bool r = pio_claim_free_sm_and_add_program_for_gpio_range (& program_struct , & pio , & state_machine , & program_offset , gpio_base , gpio_count , true);
321
+ bool r = pio_claim_free_sm_and_add_program_for_gpio_range (& program_struct , & pio , ( uint * ) & state_machine , & program_offset , gpio_base , gpio_count , true);
316
322
if (!r ) {
317
323
return false;
318
324
}
@@ -336,6 +342,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
336
342
}
337
343
}
338
344
345
+ // Sanity check that state_machine number is valid.
346
+ assert (state_machine >= 0 );
339
347
self -> pio = pio ;
340
348
self -> state_machine = state_machine ;
341
349
self -> offset = offset ;
@@ -739,6 +747,8 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
739
747
fifo_type ,
740
748
mov_status_type , mov_status_n );
741
749
if (!ok ) {
750
+ // indicate state machine never inited
751
+ self -> state_machine = NUM_PIO_STATE_MACHINES ;
742
752
mp_raise_RuntimeError (MP_ERROR_TEXT ("All state machines in use" ));
743
753
}
744
754
}
0 commit comments