Content-Length: 356065 | pFad | http://github.com/adafruit/circuitpython/commit/10a801e8e38f84c1b9d07a9b1a20fa93dd071a97

A9 Fix signedness bug in StateMachine.c:use_existing_program(). · adafruit/circuitpython@10a801e · GitHub
Skip to content

Commit 10a801e

Browse files
committed
Fix signedness bug in StateMachine.c:use_existing_program().
Fix crash on deinit of incompletely initied state machine. Fix processor-dependent includes.
1 parent 9825f62 commit 10a801e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
#include "shared-bindings/microcontroller/Pin.h"
1515
#include "shared-bindings/memorymap/AddressRange.h"
1616

17+
#if defined(PICO_RP2040)
1718
#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+
1825
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
1926
#include "src/rp2_common/hardware_dma/include/hardware/dma.h"
2027
#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h"
21-
#include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h"
2228
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
2329

2430
#include "shared/runtime/interrupt_char.h"
@@ -222,7 +228,7 @@ static bool is_gpio_compatible(PIO pio, uint32_t used_gpio_ranges) {
222228
#endif
223229
}
224230

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) {
226232
uint32_t required_gpio_ranges;
227233
if (gpio_count) {
228234
required_gpio_ranges = (1u << (gpio_base >> 4)) |
@@ -307,12 +313,12 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
307313
.origen = offset,
308314
};
309315
PIO pio;
310-
uint state_machine;
316+
int state_machine;
311317
bool added = false;
312318

313319
if (!use_existing_program(&pio, &state_machine, &offset, program_id, program_len, gpio_base, gpio_count)) {
314320
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);
316322
if (!r) {
317323
return false;
318324
}
@@ -336,6 +342,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
336342
}
337343
}
338344

345+
// Sanity check that state_machine number is valid.
346+
assert(state_machine >= 0);
339347
self->pio = pio;
340348
self->state_machine = state_machine;
341349
self->offset = offset;
@@ -739,6 +747,8 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
739747
fifo_type,
740748
mov_status_type, mov_status_n);
741749
if (!ok) {
750+
// indicate state machine never inited
751+
self->state_machine = NUM_PIO_STATE_MACHINES;
742752
mp_raise_RuntimeError(MP_ERROR_TEXT("All state machines in use"));
743753
}
744754
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/adafruit/circuitpython/commit/10a801e8e38f84c1b9d07a9b1a20fa93dd071a97

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy