Skip to content

Commit c735dce

Browse files
authored
Merge pull request #3099 from hierophect/stm32-timer-allocator
STM32: Add timer allocator, PulseIO adjustments
2 parents 5437084 + c1f731d commit c735dce

File tree

27 files changed

+1003
-880
lines changed

27 files changed

+1003
-880
lines changed

locale/circuitpython.pot

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ msgstr ""
316316
#: ports/cxd56/common-hal/pulseio/PulseOut.c
317317
#: ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
318318
#: ports/nrf/common-hal/pulseio/PulseIn.c ports/nrf/peripherals/nrf/timers.c
319-
#: shared-bindings/pulseio/PWMOut.c
319+
#: ports/stm/peripherals/timers.c shared-bindings/pulseio/PWMOut.c
320320
msgid "All timers in use"
321321
msgstr ""
322322

@@ -1332,11 +1332,7 @@ msgstr ""
13321332
msgid "Pull not used when direction is output."
13331333
msgstr ""
13341334

1335-
#: ports/stm/common-hal/pulseio/PulseIn.c
1336-
msgid "PulseIn not supported on this chip"
1337-
msgstr ""
1338-
1339-
#: ports/stm/common-hal/pulseio/PulseOut.c
1335+
#: ports/stm/ref/pulseout-pre-timeralloc.c
13401336
msgid "PulseOut not supported on this chip"
13411337
msgstr ""
13421338

@@ -1545,6 +1541,11 @@ msgstr ""
15451541
msgid "Timeout is too long: Maximum timeout length is %d seconds"
15461542
msgstr ""
15471543

1544+
#: ports/stm/common-hal/pulseio/PWMOut.c
1545+
msgid ""
1546+
"Timer was reserved for internal use - declare PWM pins earlier in the program"
1547+
msgstr ""
1548+
15481549
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
15491550
msgid "Too many channels in sample."
15501551
msgstr ""

ports/stm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ SRC_C += \
207207
mphalport.c \
208208
boards/$(BOARD)/board.c \
209209
boards/$(BOARD)/pins.c \
210+
peripherals/timers.c \
210211
peripherals/stm32$(MCU_SERIES_LOWER)/clocks.c \
211212
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/pins.c \
212213
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/gpio.c \

ports/stm/common-hal/analogio/AnalogIn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "py/runtime.h"
3030
#include "supervisor/shared/translate.h"
3131

32-
#include "common-hal/microcontroller/Pin.h"
32+
#include "shared-bindings/microcontroller/Pin.h"
3333

3434
#include "stm32f4xx_hal.h"
3535
#include "stm32f4xx_ll_gpio.h"
@@ -57,7 +57,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
5757
} else {
5858
mp_raise_ValueError(translate("Invalid ADC Unit value"));
5959
}
60-
claim_pin(pin);
60+
common_hal_mcu_pin_claim(pin);
6161
self->pin = pin;
6262
}
6363

ports/stm/common-hal/analogio/AnalogOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
8686

8787
dac_on[self->dac_index] = true;
8888
self->pin = pin;
89-
claim_pin(pin);
89+
common_hal_mcu_pin_claim(pin);
9090
#endif
9191
}
9292

ports/stm/common-hal/busio/I2C.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#include "shared-bindings/microcontroller/__init__.h"
3434
#include "supervisor/shared/translate.h"
35-
#include "common-hal/microcontroller/Pin.h"
35+
#include "shared-bindings/microcontroller/Pin.h"
3636

3737
// I2C timing specs for the H7 and F7
3838
// Configured for maximum possible clock settings for the family
@@ -161,8 +161,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
161161
if (HAL_I2C_Init(&(self->handle)) != HAL_OK) {
162162
mp_raise_RuntimeError(translate("I2C Init Error"));
163163
}
164-
claim_pin(sda);
165-
claim_pin(scl);
164+
common_hal_mcu_pin_claim(sda);
165+
common_hal_mcu_pin_claim(scl);
166166
}
167167

168168
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {

ports/stm/common-hal/busio/SPI.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "shared-bindings/microcontroller/__init__.h"
3434
#include "boards/board.h"
3535
#include "supervisor/shared/translate.h"
36-
#include "common-hal/microcontroller/Pin.h"
36+
#include "shared-bindings/microcontroller/Pin.h"
3737

3838
// Note that any bugs introduced in this file can cause crashes at startup
3939
// for chips using external SPI flash.
@@ -233,12 +233,12 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
233233
self->phase = 0;
234234
self->bits = 8;
235235

236-
claim_pin(sck);
236+
common_hal_mcu_pin_claim(sck);
237237
if (self->mosi != NULL) {
238-
claim_pin(mosi);
238+
common_hal_mcu_pin_claim(mosi);
239239
}
240240
if (self->miso != NULL) {
241-
claim_pin(miso);
241+
common_hal_mcu_pin_claim(miso);
242242
}
243243
}
244244

ports/stm/common-hal/busio/UART.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include "shared-bindings/microcontroller/__init__.h"
28+
#include "shared-bindings/microcontroller/Pin.h"
2829
#include "shared-bindings/busio/UART.h"
2930

3031
#include "mpconfigport.h"
@@ -224,10 +225,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
224225
mp_raise_ValueError(translate("UART Buffer allocation error"));
225226
}
226227
}
227-
claim_pin(rx);
228+
common_hal_mcu_pin_claim(rx);
228229
}
229230
if (self->tx != NULL) {
230-
claim_pin(tx);
231+
common_hal_mcu_pin_claim(tx);
231232
}
232233
self->baudrate = baudrate;
233234
self->timeout_ms = timeout * 1000;

ports/stm/common-hal/digitalio/DigitalInOut.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include "shared-bindings/digitalio/DigitalInOut.h"
29+
#include "shared-bindings/microcontroller/Pin.h"
2930
#include "py/runtime.h"
3031
#include "supervisor/shared/translate.h"
3132

@@ -46,7 +47,7 @@ void common_hal_digitalio_digitalinout_never_reset(
4647
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
4748
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
4849

49-
claim_pin(pin);
50+
common_hal_mcu_pin_claim(pin);
5051
self->pin = pin;
5152

5253
GPIO_InitTypeDef GPIO_InitStruct = {0};

ports/stm/common-hal/microcontroller/Pin.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
8989

9090
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
9191
never_reset_pins[pin_port] |= 1<<pin_number;
92+
// Make sure never reset pins are also always claimed
93+
claimed_pins[pin_port] |= 1<<pin_number;
9294
}
9395

9496
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
@@ -99,15 +101,9 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
99101
reset_pin_number(pin->port, pin->number);
100102
}
101103

102-
void claim_pin(const mcu_pin_obj_t* pin) {
104+
void claim_pin(uint8_t pin_port, uint8_t pin_number) {
103105
// Set bit in claimed_pins bitmask.
104-
claimed_pins[pin->port] |= 1<<pin->number;
105-
106-
#ifdef MICROPY_HW_NEOPIXEL
107-
if (pin == MICROPY_HW_NEOPIXEL) {
108-
neopixel_in_use = true;
109-
}
110-
#endif
106+
claimed_pins[pin_port] |= 1<<pin_number;
111107
}
112108

113109
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
@@ -137,7 +133,12 @@ uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t* pin) {
137133
}
138134

139135
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
140-
claim_pin(pin);
136+
claim_pin(pin->port, pin->number);
137+
#ifdef MICROPY_HW_NEOPIXEL
138+
if (pin == MICROPY_HW_NEOPIXEL) {
139+
neopixel_in_use = true;
140+
}
141+
#endif
141142
}
142143

143144
void common_hal_mcu_pin_reset_number(uint8_t pin_no) {

0 commit comments

Comments
 (0)