Claim USB pins at startup to prevent overwrites
This commit is contained in:
parent
e232ec10ce
commit
c1f731d62e
@ -29,7 +29,7 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
|
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
|
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
#include "stm32f4xx_ll_gpio.h"
|
#include "stm32f4xx_ll_gpio.h"
|
||||||
@ -57,7 +57,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
|
|||||||
} else {
|
} else {
|
||||||
mp_raise_ValueError(translate("Invalid ADC Unit value"));
|
mp_raise_ValueError(translate("Invalid ADC Unit value"));
|
||||||
}
|
}
|
||||||
claim_pin(pin);
|
common_hal_mcu_pin_claim(pin);
|
||||||
self->pin = pin;
|
self->pin = pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
|
|||||||
|
|
||||||
dac_on[self->dac_index] = true;
|
dac_on[self->dac_index] = true;
|
||||||
self->pin = pin;
|
self->pin = pin;
|
||||||
claim_pin(pin);
|
common_hal_mcu_pin_claim(pin);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
|
|
||||||
// I2C timing specs for the H7 and F7
|
// I2C timing specs for the H7 and F7
|
||||||
// Configured for maximum possible clock settings for the family
|
// Configured for maximum possible clock settings for the family
|
||||||
@ -161,8 +161,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
|||||||
if (HAL_I2C_Init(&(self->handle)) != HAL_OK) {
|
if (HAL_I2C_Init(&(self->handle)) != HAL_OK) {
|
||||||
mp_raise_RuntimeError(translate("I2C Init Error"));
|
mp_raise_RuntimeError(translate("I2C Init Error"));
|
||||||
}
|
}
|
||||||
claim_pin(sda);
|
common_hal_mcu_pin_claim(sda);
|
||||||
claim_pin(scl);
|
common_hal_mcu_pin_claim(scl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
|
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
|
|
||||||
// Note that any bugs introduced in this file can cause crashes at startup
|
// Note that any bugs introduced in this file can cause crashes at startup
|
||||||
// for chips using external SPI flash.
|
// for chips using external SPI flash.
|
||||||
@ -233,12 +233,12 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||||||
self->phase = 0;
|
self->phase = 0;
|
||||||
self->bits = 8;
|
self->bits = 8;
|
||||||
|
|
||||||
claim_pin(sck);
|
common_hal_mcu_pin_claim(sck);
|
||||||
if (self->mosi != NULL) {
|
if (self->mosi != NULL) {
|
||||||
claim_pin(mosi);
|
common_hal_mcu_pin_claim(mosi);
|
||||||
}
|
}
|
||||||
if (self->miso != NULL) {
|
if (self->miso != NULL) {
|
||||||
claim_pin(miso);
|
common_hal_mcu_pin_claim(miso);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "shared-bindings/busio/UART.h"
|
#include "shared-bindings/busio/UART.h"
|
||||||
|
|
||||||
#include "mpconfigport.h"
|
#include "mpconfigport.h"
|
||||||
@ -224,10 +225,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||||||
mp_raise_ValueError(translate("UART Buffer allocation error"));
|
mp_raise_ValueError(translate("UART Buffer allocation error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
claim_pin(rx);
|
common_hal_mcu_pin_claim(rx);
|
||||||
}
|
}
|
||||||
if (self->tx != NULL) {
|
if (self->tx != NULL) {
|
||||||
claim_pin(tx);
|
common_hal_mcu_pin_claim(tx);
|
||||||
}
|
}
|
||||||
self->baudrate = baudrate;
|
self->baudrate = baudrate;
|
||||||
self->timeout_ms = timeout * 1000;
|
self->timeout_ms = timeout * 1000;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||||
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ void common_hal_digitalio_digitalinout_never_reset(
|
|||||||
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
||||||
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||||
|
|
||||||
claim_pin(pin);
|
common_hal_mcu_pin_claim(pin);
|
||||||
self->pin = pin;
|
self->pin = pin;
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
@ -101,25 +101,15 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
|
|||||||
reset_pin_number(pin->port, pin->number);
|
reset_pin_number(pin->port, pin->number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void claim_pin(const mcu_pin_obj_t* pin) {
|
void claim_pin(uint8_t pin_port, uint8_t pin_number) {
|
||||||
// Set bit in claimed_pins bitmask.
|
// Set bit in claimed_pins bitmask.
|
||||||
claimed_pins[pin->port] |= 1<<pin->number;
|
claimed_pins[pin_port] |= 1<<pin_number;
|
||||||
|
|
||||||
#ifdef MICROPY_HW_NEOPIXEL
|
|
||||||
if (pin == MICROPY_HW_NEOPIXEL) {
|
|
||||||
neopixel_in_use = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
|
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
|
||||||
return !(claimed_pins[pin_port] & 1<<pin_number);
|
return !(claimed_pins[pin_port] & 1<<pin_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pin_number_is_resettable(uint8_t pin_port, uint8_t pin_number) {
|
|
||||||
return !(never_reset_pins[pin_port] & 1<<pin_number);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
||||||
#ifdef MICROPY_HW_NEOPIXEL
|
#ifdef MICROPY_HW_NEOPIXEL
|
||||||
if (pin == MICROPY_HW_NEOPIXEL) {
|
if (pin == MICROPY_HW_NEOPIXEL) {
|
||||||
@ -143,7 +133,12 @@ uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t* pin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
|
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
|
||||||
claim_pin(pin);
|
claim_pin(pin->port, pin->number);
|
||||||
|
#ifdef MICROPY_HW_NEOPIXEL
|
||||||
|
if (pin == MICROPY_HW_NEOPIXEL) {
|
||||||
|
neopixel_in_use = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_mcu_pin_reset_number(uint8_t pin_no) {
|
void common_hal_mcu_pin_reset_number(uint8_t pin_no) {
|
||||||
|
@ -43,9 +43,8 @@ void reset_all_pins(void);
|
|||||||
// reset_pin_number takes the pin number instead of the pointer so that objects don't
|
// reset_pin_number takes the pin number instead of the pointer so that objects don't
|
||||||
// need to store a full pointer.
|
// need to store a full pointer.
|
||||||
void reset_pin_number(uint8_t pin_port, uint8_t pin_number);
|
void reset_pin_number(uint8_t pin_port, uint8_t pin_number);
|
||||||
void claim_pin(const mcu_pin_obj_t* pin);
|
void claim_pin(uint8_t pin_port, uint8_t pin_number);
|
||||||
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number);
|
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number);
|
||||||
bool pin_number_is_resettable(uint8_t pin_port, uint8_t pin_number)
|
|
||||||
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number);
|
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number);
|
||||||
GPIO_TypeDef * pin_port(uint8_t pin_port);
|
GPIO_TypeDef * pin_port(uint8_t pin_port);
|
||||||
uint16_t pin_mask(uint8_t pin_number);
|
uint16_t pin_mask(uint8_t pin_number);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include STM32_HAL_H
|
#include STM32_HAL_H
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
|
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "shared-bindings/pulseio/PulseIn.h"
|
#include "shared-bindings/pulseio/PulseIn.h"
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu
|
|||||||
// Interrupt starts immediately
|
// Interrupt starts immediately
|
||||||
assign_EXTI_Interrupt(self, pin->number);
|
assign_EXTI_Interrupt(self, pin->number);
|
||||||
HAL_NVIC_EnableIRQ(self->irq);
|
HAL_NVIC_EnableIRQ(self->irq);
|
||||||
claim_pin(pin);
|
common_hal_mcu_pin_claim(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
|
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
|
|
||||||
#include STM32_HAL_H
|
#include STM32_HAL_H
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
// A single timer is shared amongst all PulseOut objects under the assumption that
|
// A single timer is shared amongst all PulseOut objects under the assumption that
|
||||||
|
@ -86,6 +86,8 @@ void init_usb_hardware(void) {
|
|||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
never_reset_pin_number(0, 11);
|
never_reset_pin_number(0, 11);
|
||||||
never_reset_pin_number(0, 12);
|
never_reset_pin_number(0, 12);
|
||||||
|
claim_pin(0, 11);
|
||||||
|
claim_pin(0, 12);
|
||||||
|
|
||||||
/* Configure VBUS Pin */
|
/* Configure VBUS Pin */
|
||||||
#if !(BOARD_NO_VBUS_SENSE)
|
#if !(BOARD_NO_VBUS_SENSE)
|
||||||
@ -94,6 +96,7 @@ void init_usb_hardware(void) {
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
never_reset_pin_number(0, 9);
|
never_reset_pin_number(0, 9);
|
||||||
|
claim_pin(0, 9);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This for ID line debug */
|
/* This for ID line debug */
|
||||||
@ -108,6 +111,7 @@ void init_usb_hardware(void) {
|
|||||||
#endif
|
#endif
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
never_reset_pin_number(0, 10);
|
never_reset_pin_number(0, 10);
|
||||||
|
claim_pin(0, 10);
|
||||||
|
|
||||||
#ifdef STM32F412Zx
|
#ifdef STM32F412Zx
|
||||||
/* Configure POWER_SWITCH IO pin (F412 ONLY)*/
|
/* Configure POWER_SWITCH IO pin (F412 ONLY)*/
|
||||||
@ -116,6 +120,7 @@ void init_usb_hardware(void) {
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||||
never_reset_pin_number(0, 8);
|
never_reset_pin_number(0, 8);
|
||||||
|
claim_pin(0, 8);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CPY_STM32H7
|
#if CPY_STM32H7
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "shared-bindings/touchio/TouchIn.h"
|
#include "shared-bindings/touchio/TouchIn.h"
|
||||||
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
|
|
||||||
// This is a capacitive touch sensing routine using a single digital
|
// This is a capacitive touch sensing routine using a single digital
|
||||||
// pin. The pin should be connected to the sensing pad, and to ground
|
// pin. The pin should be connected to the sensing pad, and to ground
|
||||||
@ -67,7 +68,7 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu_pin_obj_t *pin) {
|
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu_pin_obj_t *pin) {
|
||||||
claim_pin(pin);
|
common_hal_mcu_pin_claim(pin);
|
||||||
self->digitalinout = m_new_obj(digitalio_digitalinout_obj_t);
|
self->digitalinout = m_new_obj(digitalio_digitalinout_obj_t);
|
||||||
self->digitalinout->base.type = &digitalio_digitalinout_type;
|
self->digitalinout->base.type = &digitalio_digitalinout_type;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user