summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHierophect <hierophect@gmail.com>2019-11-20 15:31:55 -0500
committerHierophect <hierophect@gmail.com>2019-11-20 15:31:55 -0500
commitcf4a3237e74e844c8c3df50a4726a0fa52d29162 (patch)
tree4dd87a67e8b0e6b9e9d7fb66c9b51fd4b7c9cc3a
parent9764006f81b6d8a14421f78777259bc3fd0ef015 (diff)
parenteae201a6dd5c5f139fb8354d486b10c53904359e (diff)
Merge remote-tracking branch 'upstream/master' into stm32-meowbit-etc
-rw-r--r--.github/workflows/build.yml1
-rw-r--r--ports/atmel-samd/boards/robohatmm1_m0/board.c38
-rw-r--r--ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.h42
-rw-r--r--ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.mk29
-rw-r--r--ports/atmel-samd/boards/robohatmm1_m0/pins.c92
-rw-r--r--ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h10
-rw-r--r--ports/stm32f4/boards/feather_stm32f405_express/pins.c1
-rw-r--r--ports/stm32f4/boards/feather_stm32f405_express/stm32f4xx_hal_conf.h2
-rw-r--r--ports/stm32f4/boards/pyboard_v11/stm32f4xx_hal_conf.h2
-rw-r--r--ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_conf.h2
-rw-r--r--ports/stm32f4/common-hal/microcontroller/Pin.c35
-rw-r--r--ports/stm32f4/common-hal/microcontroller/Pin.h8
-rw-r--r--ports/stm32f4/common-hal/neopixel_write/__init__.c96
-rw-r--r--ports/stm32f4/common-hal/os/__init__.c35
-rw-r--r--ports/stm32f4/mpconfigport.mk1
-rw-r--r--ports/stm32f4/peripherals/stm32f4/periph.h6
-rw-r--r--tools/build_board_info.py1
17 files changed, 184 insertions, 217 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 404cd19a6..1d5793573 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -137,7 +137,6 @@ jobs:
- "pyportal"
- "pyportal_titano"
- "pyruler"
- - "robohatmm1_m0"
- "robohatmm1_m4"
- "sam32"
- "serpente"
diff --git a/ports/atmel-samd/boards/robohatmm1_m0/board.c b/ports/atmel-samd/boards/robohatmm1_m0/board.c
deleted file mode 100644
index c8e20206a..000000000
--- a/ports/atmel-samd/boards/robohatmm1_m0/board.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "boards/board.h"
-
-void board_init(void)
-{
-}
-
-bool board_requests_safe_mode(void) {
- return false;
-}
-
-void reset_board(void) {
-}
diff --git a/ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.h b/ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.h
deleted file mode 100644
index c6856c68f..000000000
--- a/ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#define MICROPY_HW_BOARD_NAME "Robo HAT MM1 M0"
-#define MICROPY_HW_MCU_NAME "samd21g18"
-
-#define MICROPY_HW_LED_STATUS (&pin_PB22)
-
-// Salae reads 12mhz which is the limit even though we set it to the safer 8mhz.
-#define SPI_FLASH_BAUDRATE (8000000)
-
-// On-board flash
-#define SPI_FLASH_MOSI_PIN &pin_PA12
-#define SPI_FLASH_MISO_PIN &pin_PA14
-#define SPI_FLASH_SCK_PIN &pin_PA13
-#define SPI_FLASH_CS_PIN &pin_PA15
-
-// These are pins not to reset.
-#define MICROPY_PORT_A ( 0 ) //PORT_PA06
-#define MICROPY_PORT_B ( 0 )
-#define MICROPY_PORT_C ( 0 )
-
-
-// If you change this, then make sure to update the linker scripts as well to
-// make sure you don't overwrite code.
-#define CIRCUITPY_INTERNAL_NVM_SIZE 256
-
-#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
-
-#define CALIBRATE_CRYSTALLESS 1
-
-#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
-#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
-
-#define DEFAULT_SPI_BUS_SCK (&pin_PB09)
-#define DEFAULT_SPI_BUS_MOSI (&pin_PB08)
-#define DEFAULT_SPI_BUS_MISO (&pin_PB11)
-
-//#define DEFAULT_UART_BUS_RX (&pin_PB03)
-//#define DEFAULT_UART_BUS_TX (&pin_PB02)
-
-// USB is always used internally so skip the pin objects for it.
-#define IGNORE_PIN_PA24 1
-#define IGNORE_PIN_PA25 1
-
diff --git a/ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.mk b/ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.mk
deleted file mode 100644
index e703fbfb9..000000000
--- a/ports/atmel-samd/boards/robohatmm1_m0/mpconfigboard.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-LD_FILE = boards/samd21x18-bootloader-external-flash-crystalless.ld
-USB_VID = 0x1209
-USB_PID = 0x4D43
-USB_PRODUCT = "Robo HAT MM1 M0"
-USB_MANUFACTURER = "Robotics Masters"
-
-CHIP_VARIANT = SAMD21G18A
-CHIP_FAMILY = samd21
-
-SPI_FLASH_FILESYSTEM = 1
-EXTERNAL_FLASH_DEVICE_COUNT = 1
-EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ"
-LONGINT_IMPL = MPZ
-
-# Non-Flash Edition
-#INTERNAL_FLASH_FILESYSTEM = 1
-#LONGINT_IMPL = NONE
-
-CIRCUITPY_DISPLAYIO = 0
-CIRCUITPY_FREQUENCYIO = 0
-
-CFLAGS_INLINE_LIMIT = 60
-SUPEROPT_GC = 0
-
-# Include these Python libraries in firmware.
-#FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice
-FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
-#FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_INA219
-#FROZEN_MPY_DIRS += $(TOP)/frozen/RoboticsMasters_CircuitPython_MPU9250
diff --git a/ports/atmel-samd/boards/robohatmm1_m0/pins.c b/ports/atmel-samd/boards/robohatmm1_m0/pins.c
deleted file mode 100644
index edaf0bc4c..000000000
--- a/ports/atmel-samd/boards/robohatmm1_m0/pins.c
+++ /dev/null
@@ -1,92 +0,0 @@
-#include "shared-bindings/board/__init__.h"
-// Version 2.4
-STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
- // SERVO Pins
- { MP_ROM_QSTR(MP_QSTR_SERVO1), MP_ROM_PTR(&pin_PA18) },
- { MP_ROM_QSTR(MP_QSTR_SERVO2), MP_ROM_PTR(&pin_PA19) },
- { MP_ROM_QSTR(MP_QSTR_SERVO3), MP_ROM_PTR(&pin_PA20) },
- { MP_ROM_QSTR(MP_QSTR_SERVO4), MP_ROM_PTR(&pin_PA21) },
- { MP_ROM_QSTR(MP_QSTR_SERVO5), MP_ROM_PTR(&pin_PA11) },
- { MP_ROM_QSTR(MP_QSTR_SERVO6), MP_ROM_PTR(&pin_PA10) },
- { MP_ROM_QSTR(MP_QSTR_SERVO7), MP_ROM_PTR(&pin_PA09) },
- { MP_ROM_QSTR(MP_QSTR_SERVO8), MP_ROM_PTR(&pin_PA08) },
-
- // RCC Pins
- { MP_ROM_QSTR(MP_QSTR_RCC1), MP_ROM_PTR(&pin_PA07) },
- { MP_ROM_QSTR(MP_QSTR_RCC2), MP_ROM_PTR(&pin_PA06) },
- { MP_ROM_QSTR(MP_QSTR_RCC3), MP_ROM_PTR(&pin_PA05) },
- { MP_ROM_QSTR(MP_QSTR_RCC4), MP_ROM_PTR(&pin_PA04) },
-
- // Special Function
- { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_PA02) },
- { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_PA02) },
- { MP_ROM_QSTR(MP_QSTR_POWER_OFF), MP_ROM_PTR(&pin_PA03) },
- { MP_ROM_QSTR(MP_QSTR_POWER_DISABLE), MP_ROM_PTR(&pin_PA03) },
- { MP_ROM_QSTR(MP_QSTR_POWER_ON), MP_ROM_PTR(&pin_PA27) },
- { MP_ROM_QSTR(MP_QSTR_POWER_ENABLE), MP_ROM_PTR(&pin_PA27) },
- { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA27) },
-
- { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB23) },
- { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PB22) },
- { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB02) },
- { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB03) },
-
- // GROVE on SERCOM0
- { MP_ROM_QSTR(MP_QSTR_GROVE_SCL), MP_ROM_PTR(&pin_PA09) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_SDA), MP_ROM_PTR(&pin_PA08) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_RX), MP_ROM_PTR(&pin_PA09) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_TX), MP_ROM_PTR(&pin_PA08) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_D1), MP_ROM_PTR(&pin_PA09) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_D0), MP_ROM_PTR(&pin_PA08) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_A1), MP_ROM_PTR(&pin_PA09) },
- { MP_ROM_QSTR(MP_QSTR_GROVE_A0), MP_ROM_PTR(&pin_PA08) },
-
- // UART on SERCOM0
- { MP_ROM_QSTR(MP_QSTR_UART_TX), MP_ROM_PTR(&pin_PA04) },
- { MP_ROM_QSTR(MP_QSTR_UART_RX), MP_ROM_PTR(&pin_PA05) },
- { MP_ROM_QSTR(MP_QSTR_UART_CTS), MP_ROM_PTR(&pin_PA06) },
- { MP_ROM_QSTR(MP_QSTR_UART_RTS), MP_ROM_PTR(&pin_PA07) },
-
- // UART on SERCOM1 (Raspberry Pi)
- { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_PA16) },
- { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_PA17) },
- { MP_ROM_QSTR(MP_QSTR_PI_RX), MP_ROM_PTR(&pin_PA16) },
- { MP_ROM_QSTR(MP_QSTR_PI_TX), MP_ROM_PTR(&pin_PA17) },
-
- // I2C on SERCOM1 (External Connector)
- { MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_PA00) },
- { MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_PA01) },
-
- // SPI Flash on SERCOM2
- { MP_ROM_QSTR(MP_QSTR_FLASH_SCK), MP_ROM_PTR(&pin_PA13) },
- { MP_ROM_QSTR(MP_QSTR_FLASH_MISO), MP_ROM_PTR(&pin_PA14) },
- { MP_ROM_QSTR(MP_QSTR_FLASH_MOSI), MP_ROM_PTR(&pin_PA12) },
- { MP_ROM_QSTR(MP_QSTR_FLASH_CS), MP_ROM_PTR(&pin_PA15) },
-
- // I2C on SERCOM3 (RPi & Internal)
- { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) },
- { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) },
- { MP_ROM_QSTR(MP_QSTR_PI_SDA), MP_ROM_PTR(&pin_PA22) },
- { MP_ROM_QSTR(MP_QSTR_PI_SCL), MP_ROM_PTR(&pin_PA23) },
-
- // SPI on SERCOM4
- { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB08) },
- { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB09) },
- { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PB10) },
- { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PB11) },
-
- // GPS on SERCOM5
- { MP_ROM_QSTR(MP_QSTR_GPS_TX), MP_ROM_PTR(&pin_PB02) },
- { MP_ROM_QSTR(MP_QSTR_GPS_RX), MP_ROM_PTR(&pin_PB03) },
-
- // Raspberry Pi
- { MP_ROM_QSTR(MP_QSTR_PI_GP25), MP_ROM_PTR(&pin_PA30) },
- { MP_ROM_QSTR(MP_QSTR_SWCLK), MP_ROM_PTR(&pin_PA30) },
- { MP_ROM_QSTR(MP_QSTR_PI_GP24), MP_ROM_PTR(&pin_PA31) },
- { MP_ROM_QSTR(MP_QSTR_SWDIO), MP_ROM_PTR(&pin_PA31) },
-
- { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
- { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
- //{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
-};
-MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);
diff --git a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h
index 67ddc885a..dc88f695a 100644
--- a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h
+++ b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h
@@ -35,11 +35,13 @@
#define AUTORESET_DELAY_MS 500
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
+#define MICROPY_HW_NEOPIXEL (&pin_PC00)
+
// On-board flash
-#define SPI_FLASH_MOSI_PIN &pin_PB05
-#define SPI_FLASH_MISO_PIN &pin_PB04
-#define SPI_FLASH_SCK_PIN &pin_PB03
-#define SPI_FLASH_CS_PIN &pin_PA15
+#define SPI_FLASH_MOSI_PIN (&pin_PB05)
+#define SPI_FLASH_MISO_PIN (&pin_PB04)
+#define SPI_FLASH_SCK_PIN (&pin_PB03)
+#define SPI_FLASH_CS_PIN (&pin_PA15)
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
diff --git a/ports/stm32f4/boards/feather_stm32f405_express/pins.c b/ports/stm32f4/boards/feather_stm32f405_express/pins.c
index 4aa1f362a..180fdd093 100644
--- a/ports/stm32f4/boards/feather_stm32f405_express/pins.c
+++ b/ports/stm32f4/boards/feather_stm32f405_express/pins.c
@@ -26,6 +26,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB11) },
+ { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PC00) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
diff --git a/ports/stm32f4/boards/feather_stm32f405_express/stm32f4xx_hal_conf.h b/ports/stm32f4/boards/feather_stm32f405_express/stm32f4xx_hal_conf.h
index 68a49b4ba..8031403a9 100644
--- a/ports/stm32f4/boards/feather_stm32f405_express/stm32f4xx_hal_conf.h
+++ b/ports/stm32f4/boards/feather_stm32f405_express/stm32f4xx_hal_conf.h
@@ -55,7 +55,7 @@
#define HAL_I2S_MODULE_ENABLED
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */
-/* #define HAL_RNG_MODULE_ENABLED */
+#define HAL_RNG_MODULE_ENABLED
/* #define HAL_RTC_MODULE_ENABLED */
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
diff --git a/ports/stm32f4/boards/pyboard_v11/stm32f4xx_hal_conf.h b/ports/stm32f4/boards/pyboard_v11/stm32f4xx_hal_conf.h
index 7a1a9428f..4dc18cb7f 100644
--- a/ports/stm32f4/boards/pyboard_v11/stm32f4xx_hal_conf.h
+++ b/ports/stm32f4/boards/pyboard_v11/stm32f4xx_hal_conf.h
@@ -55,7 +55,7 @@
#define HAL_I2S_MODULE_ENABLED
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */
-/* #define HAL_RNG_MODULE_ENABLED */
+#define HAL_RNG_MODULE_ENABLED
/* #define HAL_RTC_MODULE_ENABLED */
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_conf.h b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_conf.h
index b89240f98..f1b401348 100644
--- a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_conf.h
+++ b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_conf.h
@@ -55,7 +55,7 @@
#define HAL_I2S_MODULE_ENABLED
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */
-/* #define HAL_RNG_MODULE_ENABLED */
+#define HAL_RNG_MODULE_ENABLED
/* #define HAL_RTC_MODULE_ENABLED */
/* #define HAL_SAI_MODULE_ENABLED */
#define HAL_SD_MODULE_ENABLED
diff --git a/ports/stm32f4/common-hal/microcontroller/Pin.c b/ports/stm32f4/common-hal/microcontroller/Pin.c
index 7e737e21b..21290e03c 100644
--- a/ports/stm32f4/common-hal/microcontroller/Pin.c
+++ b/ports/stm32f4/common-hal/microcontroller/Pin.c
@@ -26,11 +26,17 @@
*/
#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-bindings/digitalio/DigitalInOut.h"
+#include "supervisor/shared/rgb_led_status.h"
#include "py/mphal.h"
#include "stm32f4/pins.h"
#include "stm32f4xx_hal.h"
+#ifdef MICROPY_HW_NEOPIXEL
+bool neopixel_in_use;
+#endif
+
#if MCU_PACKAGE == 144
#define GPIO_PORT_COUNT 7
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG};
@@ -53,6 +59,10 @@ void reset_all_pins(void) {
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++) {
HAL_GPIO_DeInit(ports[i], ~never_reset_pins[i]);
}
+
+ #ifdef MICROPY_HW_NEOPIXEL
+ neopixel_in_use = false;
+ #endif
}
// Mark pin as free and return it to a quiescent state.
@@ -60,13 +70,18 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
if (pin_port == 0x0F) {
return;
}
-
- // Clear claimed bit.
+ // Clear claimed bit & reset
claimed_pins[pin_port] &= ~(1<<pin_number);
- // Reset the pin
HAL_GPIO_DeInit(ports[pin_port], 1<<pin_number);
-}
+ #ifdef MICROPY_HW_NEOPIXEL
+ if (pin_port == MICROPY_HW_NEOPIXEL->port && pin_number == MICROPY_HW_NEOPIXEL->number) {
+ neopixel_in_use = false;
+ rgb_led_status_init();
+ return;
+ }
+ #endif
+}
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
never_reset_pins[pin_port] |= 1<<pin_number;
@@ -83,6 +98,12 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
void claim_pin(const mcu_pin_obj_t* pin) {
// Set bit in claimed_pins bitmask.
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) {
@@ -90,6 +111,12 @@ bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
}
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
+ #ifdef MICROPY_HW_NEOPIXEL
+ if (pin == MICROPY_HW_NEOPIXEL) {
+ return !neopixel_in_use;
+ }
+ #endif
+
return pin_number_is_free(pin->port, pin->number);
}
diff --git a/ports/stm32f4/common-hal/microcontroller/Pin.h b/ports/stm32f4/common-hal/microcontroller/Pin.h
index 0c3fb375f..c4c9be6a8 100644
--- a/ports/stm32f4/common-hal/microcontroller/Pin.h
+++ b/ports/stm32f4/common-hal/microcontroller/Pin.h
@@ -31,6 +31,14 @@
#include "peripherals/stm32f4/pins.h"
+#ifdef MICROPY_HW_NEOPIXEL
+extern bool neopixel_in_use;
+#endif
+#ifdef MICROPY_HW_APA102_MOSI
+extern bool apa102_sck_in_use;
+extern bool apa102_mosi_in_use;
+#endif
+
void reset_all_pins(void);
// reset_pin_number takes the pin number instead of the pointer so that objects don't
// need to store a full pointer.
diff --git a/ports/stm32f4/common-hal/neopixel_write/__init__.c b/ports/stm32f4/common-hal/neopixel_write/__init__.c
new file mode 100644
index 000000000..fd46825d0
--- /dev/null
+++ b/ports/stm32f4/common-hal/neopixel_write/__init__.c
@@ -0,0 +1,96 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/mphal.h"
+#include "shared-bindings/neopixel_write/__init__.h"
+
+#include "tick.h"
+#include "common-hal/microcontroller/Pin.h"
+#include "stm32f4xx_hal.h"
+#include "stm32f4xx_ll_gpio.h"
+
+uint64_t next_start_tick_ms = 0;
+uint32_t next_start_tick_us = 1000;
+
+//sysclock divisors
+#define MAGIC_800_INT 900000 // ~1.11 us -> 1.2 field
+#define MAGIC_800_T0H 2800000 // ~0.36 us -> 0.44 field
+#define MAGIC_800_T1H 1350000 // ~0.74 us -> 0.84 field
+
+void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels,
+ uint32_t numBytes) {
+ uint8_t *p = pixels, *end = p + numBytes, pix = *p++, mask = 0x80;
+ uint32_t start = 0;
+ uint32_t cyc = 0;
+
+ //assumes 800_000Hz frequency
+ //Theoretical values here are 800_000 -> 1.25us, 2500000->0.4us, 1250000->0.8us
+ //But they don't work, possibly due to bad optimization? Use tested magic values instead
+ uint32_t sys_freq = HAL_RCC_GetSysClockFreq();
+ uint32_t interval = sys_freq/MAGIC_800_INT;
+ uint32_t t0 = (sys_freq/MAGIC_800_T0H);
+ uint32_t t1 = (sys_freq/MAGIC_800_T1H);
+
+ // This must be called while interrupts are on in case we're waiting for a
+ // future ms tick.
+ wait_until(next_start_tick_ms, next_start_tick_us);
+
+ GPIO_TypeDef * p_port = pin_port(digitalinout->pin->port);
+ uint32_t p_mask = pin_mask(digitalinout->pin->number);
+
+ __disable_irq();
+ // Enable DWT in debug core. Useable when interrupts disabled, as opposed to Systick->VAL
+ //ITM->LAR = 0xC5ACCE55; //this should be required but isn't
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
+ DWT->CYCCNT = 0;
+
+ for(;;) {
+ start = DWT->CYCCNT;
+ LL_GPIO_SetOutputPin(p_port, p_mask);
+ cyc = (pix & mask) ? t1 : t0;
+ while(DWT->CYCCNT - start < cyc);
+ LL_GPIO_ResetOutputPin(p_port, p_mask);
+ if(!(mask >>= 1)) {
+ if(p >= end) break;
+ pix = *p++;
+ mask = 0x80;
+ }
+ while(DWT->CYCCNT - start < interval); //wait for interval to finish
+ }
+
+ // Enable interrupts again
+ __enable_irq();
+
+ // Update the next start.
+ current_tick(&next_start_tick_ms, &next_start_tick_us);
+ if (next_start_tick_us < 100) {
+ next_start_tick_ms += 1;
+ next_start_tick_us = 100 - next_start_tick_us;
+ } else {
+ next_start_tick_us -= 100;
+ }
+}
diff --git a/ports/stm32f4/common-hal/os/__init__.c b/ports/stm32f4/common-hal/os/__init__.c
index aa80a02f5..0b3153286 100644
--- a/ports/stm32f4/common-hal/os/__init__.c
+++ b/ports/stm32f4/common-hal/os/__init__.c
@@ -30,6 +30,11 @@
#include "py/objstr.h"
#include "py/objtuple.h"
+#include "py/mperrno.h"
+#include "py/runtime.h"
+#include "stm32f4xx_hal.h"
+#include "stm32f4/periph.h"
+
STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename,
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
@@ -56,11 +61,35 @@ mp_obj_t common_hal_os_uname(void) {
return (mp_obj_t)&os_uname_info_obj;
}
+#define RNG_TIMEOUT 5
+
bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
+ #if (HAS_TRNG)
+ //init the RNG
+ __HAL_RCC_RNG_CLK_ENABLE();
+ RNG_HandleTypeDef handle;
+ handle.Instance = RNG;
+ if (HAL_RNG_Init(&handle) != HAL_OK) mp_raise_ValueError(translate("RNG Init Error"));
- for (uint32_t i = 0; i < length; i++) {
- buffer[i] = 4; //read in my coffee dregs; the truest random number, chosen by Nrthalotep
- //todo: spurn the gods, replace with actual code.
+ //Assign bytes
+ for (uint i = 0; i < length; i++) {
+ uint32_t temp;
+ uint32_t start = HAL_GetTick();
+ //the HAL function has a timeout, but it isn't long enough, and isn't adjustable
+ while(!(__HAL_RNG_GET_FLAG(&handle,RNG_FLAG_DRDY)) && ((HAL_GetTick() - start) < RNG_TIMEOUT));
+ //
+ if (HAL_RNG_GenerateRandomNumber(&handle, &temp) != HAL_OK) {
+ mp_raise_ValueError(translate("Random number generation error"));
+ }
+ *buffer = (uint8_t)temp;
}
+
+ //shut down the peripheral
+ if (HAL_RNG_DeInit(&handle) != HAL_OK) mp_raise_ValueError(translate("RNG DeInit Error"));
+ __HAL_RCC_RNG_CLK_DISABLE();
+
return true;
+ #else
+ return false;
+ #endif
} \ No newline at end of file
diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk
index bce68f99f..928d53e67 100644
--- a/ports/stm32f4/mpconfigport.mk
+++ b/ports/stm32f4/mpconfigport.mk
@@ -26,6 +26,7 @@ CIRCUITPY_STORAGE = 1
CIRCUITPY_RANDOM = 1
CIRCUITPY_USB_HID = 1
CIRCUITPY_USB_MIDI = 1
+CIRCUITPY_NEOPIXEL_WRITE = 1
#ifeq ($(MCU_SUB_VARIANT), stm32f412zx)
#endif
diff --git a/ports/stm32f4/peripherals/stm32f4/periph.h b/ports/stm32f4/peripherals/stm32f4/periph.h
index 02304c626..ac98b8932 100644
--- a/ports/stm32f4/peripherals/stm32f4/periph.h
+++ b/ports/stm32f4/peripherals/stm32f4/periph.h
@@ -140,18 +140,21 @@ typedef struct {
//Starter Lines
-#ifdef STM32F411xE
+#ifdef STM32F401xE
#define HAS_DAC 0
+#define HAS_TRNG 0
#include "stm32f401xe/periph.h"
#endif
#ifdef STM32F411xE
#define HAS_DAC 0
+#define HAS_TRNG 0
#include "stm32f411xe/periph.h"
#endif
#ifdef STM32F412Zx
#define HAS_DAC 0
+#define HAS_TRNG 1
#include "stm32f412zx/periph.h"
#endif
@@ -159,6 +162,7 @@ typedef struct {
#ifdef STM32F405xx
#define HAS_DAC 1
+#define HAS_TRNG 1
#include "stm32f405xx/periph.h"
#endif
diff --git a/tools/build_board_info.py b/tools/build_board_info.py
index efa481a63..710cdb0c2 100644
--- a/tools/build_board_info.py
+++ b/tools/build_board_info.py
@@ -48,6 +48,7 @@ extension_by_board = {
aliases_by_board = {
"circuitplayground_express": ["circuitplayground_express_4h", "circuitplayground_express_digikey_pycon2019"],
+ "pybadge": ["edgebadge"],
"gemma_m0": ["gemma_m0_pycon2018"],
"pewpew10": ["pewpew13"]
}