pico_time/time.c using GPIO pins #28

Closed
opened 2021-01-27 08:50:07 -06:00 by sde1000 · 7 comments
sde1000 commented 2021-01-27 08:50:07 -06:00 (Migrated from github.com)

I've been having a problem with calls to functions in time.c (eg. sleep_ms()) having side effects on GPIO pins.

I'm pretty sure this is related to the DEBUG_PINS macros; changing #define PICO_DEBUG_PIN_BASE 19u in src/rp2_common/hardware_gpio/include/hardware/gpio.h to something else changes the GPIO pins that are affected. (My project is using GPIO 21 as an output, which is how I discovered this.)

I don't immediately see how to turn this off!

I've been having a problem with calls to functions in time.c (eg. `sleep_ms()`) having side effects on GPIO pins. I'm pretty sure this is related to the DEBUG_PINS macros; changing `#define PICO_DEBUG_PIN_BASE 19u` in src/rp2_common/hardware_gpio/include/hardware/gpio.h to something else changes the GPIO pins that are affected. (My project is using GPIO 21 as an output, which is how I discovered this.) I don't immediately see how to turn this off!
sde1000 commented 2021-01-27 10:46:42 -06:00 (Migrated from github.com)

time.c lines 16–17 is currently:

CU_REGISTER_DEBUG_PINS(core)
CU_SELECT_DEBUG_PINS(core)

This appears to be enough for DEBUG_PINS_ENABLED(core) to be true and for the DEBUG_PINS_foo(core, v) macros to call gpio_set_mask() etc. as appropriate, whether or not gpio_debug_pins_init() has been called at any point.

I think the correct fix is to comment out CU_SELECT_DEBUG_PINS(core) in time.c

[time.c](https://github.com/raspberrypi/pico-sdk/blob/master/src/common/pico_time/time.c) lines 16–17 is currently: ``` CU_REGISTER_DEBUG_PINS(core) CU_SELECT_DEBUG_PINS(core) ``` This appears to be enough for `DEBUG_PINS_ENABLED(core)` to be true and for the DEBUG_PINS_foo(core, v) macros to call `gpio_set_mask()` etc. as appropriate, whether or not `gpio_debug_pins_init()` has been called at any point. I think the correct fix is to comment out `CU_SELECT_DEBUG_PINS(core)` in time.c
kilograham commented 2021-01-27 10:50:01 -06:00 (Migrated from github.com)

Doh! Yes that should not be enabled; will fix (and grep for others) - that probably snuck back in while testing something!

Doh! Yes that should not be enabled; will fix (and grep for others) - that probably snuck back in while testing something!
PeterOGB commented 2021-01-27 11:40:48 -06:00 (Migrated from github.com)

Does this mean that gpio_debug_pins_init() also doesn't work as intended in so far as it is not the only way to enable the debug pins ?

Does this mean that gpio_debug_pins_init() also doesn't work as intended in so far as it is not the only way to enable the debug pins ?
kilograham commented 2021-01-27 11:44:39 -06:00 (Migrated from github.com)

Nope, gpio_debug_pins_init() sets up the pins for output. The macros turn on/off code that writes values to the pins for debugging (mostly for use with logic analyzers when debugging higher frequency stuff)

the macros should not be enabled in any library code.

Nope, gpio_debug_pins_init() sets up the pins for output. The macros turn on/off code that writes values to the pins for debugging (mostly for use with logic analyzers when debugging higher frequency stuff) the macros should not be enabled in any library code.
PeterOGB commented 2021-01-27 12:01:28 -06:00 (Migrated from github.com)

Ok, but you did write "for the debug pins to do anything, you have to call gpio_debug_pins_init()" which sounded like it enabled them as well as setting them to output and l can't see where gpio_debug_pins_init() is covered in the SDK documentation.

Ok, but you did write "for the debug pins to do anything, you have to call gpio_debug_pins_init()" which sounded like it enabled them as well as setting them to output and l can't see where gpio_debug_pins_init() is covered in the SDK documentation.
kilograham commented 2021-01-31 16:46:00 -06:00 (Migrated from github.com)

merged into develop

merged into develop
aallan commented 2021-02-02 03:07:50 -06:00 (Migrated from github.com)

This should now be fixed in MicroPython mainline, see micropython/micropython#6826. Nightly UF2 builds of MicroPython are available from https://micropython.org/download/rp2-pico/.

This should now be fixed in MicroPython mainline, see micropython/micropython#6826. Nightly UF2 builds of MicroPython are available from https://micropython.org/download/rp2-pico/.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#28
No description provided.