From de14b5b02f1ceebabca8f79c8e166e673f039aec Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 8 May 2020 10:48:46 -0500 Subject: [PATCH 1/8] flash: Correctly signal error on invalid flash read This logic was intended to mirror what is done for "write", but the wrong variable name was repeated twice. --- supervisor/shared/flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/shared/flash.c b/supervisor/shared/flash.c index 298e7d83e4..9f52ddbc48 100644 --- a/supervisor/shared/flash.c +++ b/supervisor/shared/flash.c @@ -88,7 +88,7 @@ static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_blo mp_uint_t flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) { if (block_num == 0) { - if (block_num > 1) { + if (num_blocks > 1) { return 1; // error } // fake the MBR so we can decide on our own partition table From 5a3a0a50924e8306690769b0683f836cb9608145 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 21 May 2020 11:02:54 -0500 Subject: [PATCH 2/8] stm: Makefile: sort files in SRC_STM32 --- ports/stm/Makefile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ports/stm/Makefile b/ports/stm/Makefile index a7b519ffcb..08cb36ddf2 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -154,43 +154,43 @@ CFLAGS += \ -DCFG_TUD_MIDI_TX_BUFSIZE=128 SRC_STM32 = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_,\ + hal.c \ hal_adc.c \ hal_adc_ex.c \ + hal_cortex.c \ hal_dac.c \ hal_dac_ex.c \ + hal_dma.c \ + hal_dma_ex.c \ + hal_exti.c \ + hal_flash.c \ + hal_flash_ex.c \ + hal_gpio.c \ hal_i2c.c \ hal_i2c_ex.c \ + hal_pwr.c \ + hal_pwr_ex.c \ hal_qspi.c \ + hal_rcc.c \ + hal_rcc_ex.c \ hal_rng.c \ hal_rtc.c \ hal_rtc_ex.c \ + hal_sd.c \ hal_spi.c \ hal_tim.c \ hal_tim_ex.c \ hal_uart.c \ hal_usart.c \ - hal_rcc.c \ - hal_rcc_ex.c \ - hal_flash.c \ - hal_flash_ex.c \ - hal_gpio.c \ - hal_dma_ex.c \ - hal_dma.c \ - hal_pwr.c \ - hal_pwr_ex.c \ - hal_cortex.c \ - hal.c \ - hal_exti.c \ - hal_sd.c \ - ll_gpio.c \ ll_adc.c \ - ll_i2c.c \ ll_dma.c \ + ll_exti.c \ + ll_gpio.c \ + ll_i2c.c \ + ll_rcc.c \ ll_sdmmc.c \ ll_usart.c \ - ll_rcc.c \ ll_utils.c \ - ll_exti.c \ ) # Need this to avoid UART linker problems. TODO: rewrite to use registered callbacks. From a580f0f1c4f2a221ddf3ff169eff79158bd8acf6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 21 Jun 2020 08:31:26 -0500 Subject: [PATCH 3/8] _pew: move to common-hal I noticed that this code was referring to samd-specific functionality, and isn't enabled except in one samd board (pewpew10). Move it. There is incomplte support for _pew in mimxrt10xx which then caused build errors; adding a #if guard to check for _pew being enabled fixes it. The _pew module is not likely to be important on mimxrt but I'll leave the choice to remove it to someone else. --- {shared-module => ports/atmel-samd/common-hal}/_pew/PewPew.c | 0 {shared-module => ports/atmel-samd/common-hal}/_pew/PewPew.h | 0 .../atmel-samd/common-hal}/_pew/__init__.c | 0 .../atmel-samd/common-hal}/_pew/__init__.h | 0 ports/atmel-samd/supervisor/port.c | 4 +++- ports/atmel-samd/timer_handler.c | 2 +- ports/mimxrt10xx/supervisor/port.c | 2 ++ py/circuitpy_defns.mk | 4 ++-- shared-bindings/_pew/PewPew.c | 2 +- shared-bindings/_pew/__init__.c | 2 +- 10 files changed, 10 insertions(+), 6 deletions(-) rename {shared-module => ports/atmel-samd/common-hal}/_pew/PewPew.c (100%) rename {shared-module => ports/atmel-samd/common-hal}/_pew/PewPew.h (100%) rename {shared-module => ports/atmel-samd/common-hal}/_pew/__init__.c (100%) rename {shared-module => ports/atmel-samd/common-hal}/_pew/__init__.h (100%) diff --git a/shared-module/_pew/PewPew.c b/ports/atmel-samd/common-hal/_pew/PewPew.c similarity index 100% rename from shared-module/_pew/PewPew.c rename to ports/atmel-samd/common-hal/_pew/PewPew.c diff --git a/shared-module/_pew/PewPew.h b/ports/atmel-samd/common-hal/_pew/PewPew.h similarity index 100% rename from shared-module/_pew/PewPew.h rename to ports/atmel-samd/common-hal/_pew/PewPew.h diff --git a/shared-module/_pew/__init__.c b/ports/atmel-samd/common-hal/_pew/__init__.c similarity index 100% rename from shared-module/_pew/__init__.c rename to ports/atmel-samd/common-hal/_pew/__init__.c diff --git a/shared-module/_pew/__init__.h b/ports/atmel-samd/common-hal/_pew/__init__.h similarity index 100% rename from shared-module/_pew/__init__.h rename to ports/atmel-samd/common-hal/_pew/__init__.h diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 2b3e9826f8..74c9849976 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -85,7 +85,9 @@ #if CIRCUITPY_GAMEPADSHIFT #include "shared-module/gamepadshift/__init__.h" #endif -#include "shared-module/_pew/PewPew.h" +#if CIRCUITPY_PEW +#include "common-hal/_pew/PewPew.h" +#endif extern volatile bool mp_msc_enabled; diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 34d819e162..16d65334e0 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -31,7 +31,7 @@ #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pulseio/PulseOut.h" -#include "shared-module/_pew/PewPew.h" +#include "common-hal/_pew/PewPew.h" #include "common-hal/frequencyio/FrequencyIn.h" extern void _PM_IRQ_HANDLER(void); diff --git a/ports/mimxrt10xx/supervisor/port.c b/ports/mimxrt10xx/supervisor/port.c index ed5824732d..0b53a79f07 100644 --- a/ports/mimxrt10xx/supervisor/port.c +++ b/ports/mimxrt10xx/supervisor/port.c @@ -53,7 +53,9 @@ #if CIRCUITPY_GAMEPADSHIFT #include "shared-module/gamepadshift/__init__.h" #endif +#if CIRCUITPY_PEW #include "shared-module/_pew/PewPew.h" +#endif #include "supervisor/shared/tick.h" #include "clocks.h" diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 67fbde6e4f..cdfb4c6b69 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -259,6 +259,8 @@ SRC_COMMON_HAL_ALL = \ _bleio/PacketBuffer.c \ _bleio/Service.c \ _bleio/UUID.c \ + _pew/__init__.c \ + _pew/PewPew.c \ analogio/AnalogIn.c \ analogio/AnalogOut.c \ analogio/__init__.c \ @@ -396,8 +398,6 @@ SRC_SHARED_MODULE_ALL = \ terminalio/__init__.c \ uheap/__init__.c \ ustack/__init__.c \ - _pew/__init__.c \ - _pew/PewPew.c \ _eve/__init__.c # All possible sources are listed here, and are filtered by SRC_PATTERNS. diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 82bf04a617..352ef38f27 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -31,7 +31,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" #include "PewPew.h" -#include "shared-module/_pew/PewPew.h" +#include "common-hal/_pew/PewPew.h" #include "supervisor/shared/translate.h" //| class PewPew: diff --git a/shared-bindings/_pew/__init__.c b/shared-bindings/_pew/__init__.c index 6e0070d8e2..498beaf1c9 100644 --- a/shared-bindings/_pew/__init__.c +++ b/shared-bindings/_pew/__init__.c @@ -27,7 +27,7 @@ #include "py/runtime.h" #include "py/mphal.h" #include "PewPew.h" -#include "shared-module/_pew/PewPew.h" +#include "common-hal/_pew/PewPew.h" STATIC mp_obj_t get_pressed(void) { pew_obj_t *pew = MP_STATE_VM(pew_singleton); From 8a760b065733fb27ad42f78d606beed025d8106d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 22 Jun 2020 10:27:37 -0500 Subject: [PATCH 4/8] stm: Pin.c: Compute GPIO_PORT_COUNT instead of specifying manually --- ports/stm/common-hal/microcontroller/Pin.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ports/stm/common-hal/microcontroller/Pin.c b/ports/stm/common-hal/microcontroller/Pin.c index e966f709f6..b0e3c7015f 100644 --- a/ports/stm/common-hal/microcontroller/Pin.c +++ b/ports/stm/common-hal/microcontroller/Pin.c @@ -37,23 +37,20 @@ bool neopixel_in_use; #endif #if defined(TFBGA216) - #define GPIO_PORT_COUNT 11 - GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, GPIOI, GPIOJ, GPIOK}; + GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, GPIOI, GPIOJ, GPIOK}; #elif defined(LQFP144) - #define GPIO_PORT_COUNT 7 - GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG}; + GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG}; #elif defined(LQFP100_f4) || (LQFP100_x7) - #define GPIO_PORT_COUNT 5 - GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE}; + GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE}; #elif defined(LQFP64) - #define GPIO_PORT_COUNT 4 - GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD}; + GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD}; #elif defined(UFQFPN48) - #define GPIO_PORT_COUNT 3 - GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC}; + GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC}; #endif +#define GPIO_PORT_COUNT (MP_ARRAY_SIZE(ports)) + STATIC uint16_t claimed_pins[GPIO_PORT_COUNT]; STATIC uint16_t never_reset_pins[GPIO_PORT_COUNT]; From 6638bc32c3c989c3bd4ffc761bd1462ed06828be Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 9 Jun 2020 14:06:54 -0500 Subject: [PATCH 5/8] samd: Makefile: Regularize whitespace --- ports/atmel-samd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index d0ab65e6b7..8eb24e8361 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -206,7 +206,7 @@ SRC_ASF += \ else ifeq ($(CHIP_FAMILY), samd51) SRC_ASF += \ - hal/src/hal_rand_sync.c \ + hal/src/hal_rand_sync.c \ hpl/core/hpl_core_m4.c \ hpl/mclk/hpl_mclk.c \ hpl/osc32kctrl/hpl_osc32kctrl.c \ From a770b5a919338b9df068bd0bca14edec9996bc31 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 16 Jun 2020 11:31:07 -0500 Subject: [PATCH 6/8] never_reset_pin: Move pin validity check before first use of pin number --- ports/atmel-samd/common-hal/microcontroller/Pin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.c b/ports/atmel-samd/common-hal/microcontroller/Pin.c index cf78673b20..3c214a9f41 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.c +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.c @@ -110,12 +110,12 @@ void never_reset_pin_number(uint8_t pin_number) { } void reset_pin_number(uint8_t pin_number) { - never_reset_pins[GPIO_PORT(pin_number)] &= ~(1 << GPIO_PIN(pin_number)); - if (pin_number >= PORT_BITS) { return; } + never_reset_pins[GPIO_PORT(pin_number)] &= ~(1 << GPIO_PIN(pin_number)); + #ifdef MICROPY_HW_NEOPIXEL if (pin_number == MICROPY_HW_NEOPIXEL->number) { neopixel_in_use = false; From a7b36f724f16a204f6d324e70e3e1429389249fe Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 21 Jun 2020 08:33:33 -0500 Subject: [PATCH 7/8] circuitpy_defns.mk: Sort several lists of source files and regularize whitespace in one spot --- py/circuitpy_defns.mk | 60 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index cdfb4c6b69..fb8f46bd87 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -249,7 +249,6 @@ endif # All possible sources are listed here, and are filtered by SRC_PATTERNS in SRC_COMMON_HAL SRC_COMMON_HAL_ALL = \ - _bleio/__init__.c \ _bleio/Adapter.c \ _bleio/Attribute.c \ _bleio/Characteristic.c \ @@ -259,18 +258,19 @@ SRC_COMMON_HAL_ALL = \ _bleio/PacketBuffer.c \ _bleio/Service.c \ _bleio/UUID.c \ - _pew/__init__.c \ + _bleio/__init__.c \ _pew/PewPew.c \ + _pew/__init__.c \ analogio/AnalogIn.c \ analogio/AnalogOut.c \ analogio/__init__.c \ - audiobusio/__init__.c \ audiobusio/I2SOut.c \ audiobusio/PDMIn.c \ - audiopwmio/__init__.c \ - audiopwmio/PWMAudioOut.c \ - audioio/__init__.c \ + audiobusio/__init__.c \ audioio/AudioOut.c \ + audioio/__init__.c \ + audiopwmio/PWMAudioOut.c \ + audiopwmio/__init__.c \ board/__init__.c \ busio/I2C.c \ busio/SPI.c \ @@ -281,8 +281,8 @@ SRC_COMMON_HAL_ALL = \ digitalio/DigitalInOut.c \ digitalio/__init__.c \ displayio/ParallelBus.c \ - frequencyio/__init__.c \ frequencyio/FrequencyIn.c \ + frequencyio/__init__.c \ i2cslave/I2CSlave.c \ i2cslave/__init__.c \ microcontroller/Pin.c \ @@ -292,23 +292,23 @@ SRC_COMMON_HAL_ALL = \ nvm/ByteArray.c \ nvm/__init__.c \ os/__init__.c \ - rgbmatrix/RGBMatrix.c \ - rgbmatrix/__init__.c \ + ps2io/Ps2.c \ + ps2io/__init__.c \ pulseio/PWMOut.c \ pulseio/PulseIn.c \ pulseio/PulseOut.c \ pulseio/__init__.c \ - ps2io/Ps2.c \ - ps2io/__init__.c \ + rgbmatrix/RGBMatrix.c \ + rgbmatrix/__init__.c \ rotaryio/IncrementalEncoder.c \ rotaryio/__init__.c \ rtc/RTC.c \ rtc/__init__.c \ supervisor/Runtime.c \ supervisor/__init__.c \ - watchdog/__init__.c \ watchdog/WatchDogMode.c \ watchdog/WatchDogTimer.c \ + watchdog/__init__.c \ SRC_COMMON_HAL = $(filter $(SRC_PATTERNS), $(SRC_COMMON_HAL_ALL)) @@ -320,13 +320,13 @@ $(filter $(SRC_PATTERNS), \ _bleio/Address.c \ _bleio/Attribute.c \ _bleio/ScanEntry.c \ + _eve/__init__.c \ digitalio/Direction.c \ digitalio/DriveMode.c \ digitalio/Pull.c \ fontio/Glyph.c \ - microcontroller/RunMode.c \ math/__init__.c \ - _eve/__init__.c \ + microcontroller/RunMode.c \ ) SRC_BINDINGS_ENUMS += \ @@ -337,29 +337,30 @@ SRC_SHARED_MODULE_ALL = \ _bleio/Attribute.c \ _bleio/ScanEntry.c \ _bleio/ScanResults.c \ + _eve/__init__.c \ _pixelbuf/PixelBuf.c \ _pixelbuf/__init__.c \ _stage/Layer.c \ _stage/Text.c \ _stage/__init__.c \ - audiopwmio/__init__.c \ - audioio/__init__.c \ - audiocore/__init__.c \ + aesio/__init__.c \ + aesio/aes.c \ audiocore/RawSample.c \ audiocore/WaveFile.c \ - audiomixer/__init__.c \ + audiocore/__init__.c \ + audioio/__init__.c \ audiomixer/Mixer.c \ audiomixer/MixerVoice.c \ - audiomp3/__init__.c \ + audiomixer/__init__.c \ audiomp3/MP3Decoder.c \ + audiomp3/__init__.c \ + audiopwmio/__init__.c \ bitbangio/I2C.c \ bitbangio/OneWire.c \ bitbangio/SPI.c \ bitbangio/__init__.c \ board/__init__.c \ busio/OneWire.c \ - aesio/__init__.c \ - aesio/aes.c \ displayio/Bitmap.c \ displayio/ColorConverter.c \ displayio/Display.c \ @@ -372,11 +373,6 @@ SRC_SHARED_MODULE_ALL = \ displayio/Shape.c \ displayio/TileGrid.c \ displayio/__init__.c \ - vectorio/Circle.c \ - vectorio/Rectangle.c \ - vectorio/Polygon.c \ - vectorio/VectorShape.c \ - vectorio/__init__.c \ fontio/BuiltinFont.c \ fontio/__init__.c \ framebufferio/FramebufferDisplay.c \ @@ -385,20 +381,24 @@ SRC_SHARED_MODULE_ALL = \ gamepad/__init__.c \ gamepadshift/GamePadShift.c \ gamepadshift/__init__.c \ + network/__init__.c \ os/__init__.c \ random/__init__.c \ - socket/__init__.c \ - network/__init__.c \ rgbmatrix/RGBMatrix.c \ rgbmatrix/__init__.c \ + socket/__init__.c \ storage/__init__.c \ struct/__init__.c \ - time/__init__.c \ terminalio/Terminal.c \ terminalio/__init__.c \ + time/__init__.c \ uheap/__init__.c \ ustack/__init__.c \ - _eve/__init__.c + vectorio/Circle.c \ + vectorio/Polygon.c \ + vectorio/Rectangle.c \ + vectorio/VectorShape.c \ + vectorio/__init__.c \ # All possible sources are listed here, and are filtered by SRC_PATTERNS. SRC_SHARED_MODULE = $(filter $(SRC_PATTERNS), $(SRC_SHARED_MODULE_ALL)) From d43449a6d613c5a6a386231745f6fca91b352b79 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 22 Jun 2020 10:17:44 -0500 Subject: [PATCH 8/8] sparkfun samd51 thing plus: Fix board.I2C() This had the SDA and SCL pins transposed, so nothing worked. --- .../boards/sparkfun_samd51_thing_plus/mpconfigboard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.h b/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.h index a5dee295bf..97a4465a19 100644 --- a/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.h +++ b/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.h @@ -18,8 +18,8 @@ #define BOARD_HAS_CRYSTAL 1 -#define DEFAULT_I2C_BUS_SCL (&pin_PA22) -#define DEFAULT_I2C_BUS_SDA (&pin_PA23) +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) #define DEFAULT_SPI_BUS_SCK (&pin_PB13) #define DEFAULT_SPI_BUS_MOSI (&pin_PB12)