summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Grayson <pdg@alum.mit.edu>2022-12-24 09:55:12 -0800
committerDamien George <damien@micropython.org>2023-01-12 16:36:03 +1100
commitb208cf23e290c169bf346137c30bc2a0176a223d (patch)
treee4a61304bff8b8bea5e3bb1a4284a9a515288700
parentf0f5c6568de8a194f4f77c19f4e2087b87d1ab7e (diff)
rp2/mphalport: Change order of pin operations to prevent glitches.
When switching from a special function like SPI to an input or output, there was a brief period after the function was disabled but before the pin's I/O state was configured, in which the state would be poorly defined. This fixes the problem by switching off the special function after fully configuring the I/O state. Fixes #10226. Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
-rw-r--r--ports/rp2/mphalport.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h
index 73a503f5a..2cb9121fa 100644
--- a/ports/rp2/mphalport.h
+++ b/ports/rp2/mphalport.h
@@ -91,22 +91,22 @@ static inline unsigned int mp_hal_pin_name(mp_hal_pin_obj_t pin) {
}
static inline void mp_hal_pin_input(mp_hal_pin_obj_t pin) {
- gpio_set_function(pin, GPIO_FUNC_SIO);
gpio_set_dir(pin, GPIO_IN);
machine_pin_open_drain_mask &= ~(1 << pin);
+ gpio_set_function(pin, GPIO_FUNC_SIO);
}
static inline void mp_hal_pin_output(mp_hal_pin_obj_t pin) {
- gpio_set_function(pin, GPIO_FUNC_SIO);
gpio_set_dir(pin, GPIO_OUT);
machine_pin_open_drain_mask &= ~(1 << pin);
+ gpio_set_function(pin, GPIO_FUNC_SIO);
}
static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) {
- gpio_set_function(pin, GPIO_FUNC_SIO);
gpio_set_dir(pin, GPIO_IN);
gpio_put(pin, 0);
machine_pin_open_drain_mask |= 1 << pin;
+ gpio_set_function(pin, GPIO_FUNC_SIO);
}
static inline void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt) {