summaryrefslogtreecommitdiff
path: root/ports/stm/common-hal
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-03-17 18:26:13 -0400
committerLucian Copeland <hierophect@gmail.com>2020-03-26 18:01:17 -0400
commitc4db8b87e2c57ca94b8f76e4b07ca02641df714e (patch)
tree8f17d3010e415f56914b81d0bd54ae86ff711e08 /ports/stm/common-hal
parentbb3ed3a827f70582f9a19ceb359b169d1b50262a (diff)
Add F7 and H7 Support to the STM32 port
Restructures the STM port of Circuitpython to be more generic about the STM32 chip lines to support the F7 and H7 series of chips. Adds the new Packages directory to organize different chip layouts between lines. Makes general changes to the Makefile to condense board-level flags to the minimum and support the new chip series. Adds the new chip line to the Peripherals directory, along with new python tools used to generate peripheral text automatically in the tools/ directory.
Diffstat (limited to 'ports/stm/common-hal')
-rw-r--r--ports/stm/common-hal/analogio/AnalogOut.h2
-rw-r--r--ports/stm/common-hal/busio/I2C.c17
-rw-r--r--ports/stm/common-hal/busio/I2C.h13
-rw-r--r--ports/stm/common-hal/busio/OneWire.h6
-rw-r--r--ports/stm/common-hal/busio/SPI.c27
-rw-r--r--ports/stm/common-hal/busio/SPI.h17
-rw-r--r--ports/stm/common-hal/busio/UART.c33
-rw-r--r--ports/stm/common-hal/busio/UART.h11
-rw-r--r--ports/stm/common-hal/digitalio/DigitalInOut.c6
-rw-r--r--ports/stm/common-hal/digitalio/DigitalInOut.h6
-rw-r--r--ports/stm/common-hal/microcontroller/Pin.c11
-rw-r--r--ports/stm/common-hal/microcontroller/Pin.h8
-rw-r--r--ports/stm/common-hal/microcontroller/Processor.c14
-rw-r--r--ports/stm/common-hal/microcontroller/Processor.h6
-rw-r--r--ports/stm/common-hal/microcontroller/__init__.c136
-rw-r--r--ports/stm/common-hal/os/__init__.c2
-rw-r--r--ports/stm/common-hal/pulseio/PWMOut.h2
-rwxr-xr-xports/stm/common-hal/supervisor/Runtime.h6
18 files changed, 98 insertions, 225 deletions
diff --git a/ports/stm/common-hal/analogio/AnalogOut.h b/ports/stm/common-hal/analogio/AnalogOut.h
index 61591d0e6..46312b460 100644
--- a/ports/stm/common-hal/analogio/AnalogOut.h
+++ b/ports/stm/common-hal/analogio/AnalogOut.h
@@ -32,7 +32,7 @@
#include "py/obj.h"
#include "stm32f4xx_hal.h"
-#include "stm32f4/periph.h"
+#include "peripherals/periph.h"
typedef struct {
mp_obj_base_t base;
diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c
index 8e98b966d..4daefb58b 100644
--- a/ports/stm/common-hal/busio/I2C.c
+++ b/ports/stm/common-hal/busio/I2C.c
@@ -29,7 +29,6 @@
#include "shared-bindings/busio/I2C.h"
#include "py/mperrno.h"
#include "py/runtime.h"
-#include "stm32f4xx_hal.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "supervisor/shared/translate.h"
@@ -69,9 +68,9 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
if (mcu_i2c_sda_list[i].pin == sda) {
for (uint j = 0; j < scl_len; j++) {
if ((mcu_i2c_scl_list[j].pin == scl)
- && (mcu_i2c_scl_list[j].i2c_index == mcu_i2c_sda_list[i].i2c_index)) {
+ && (mcu_i2c_scl_list[j].periph_index == mcu_i2c_sda_list[i].periph_index)) {
//keep looking if the I2C is taken, could be another SCL that works
- if (reserved_i2c[mcu_i2c_scl_list[i].i2c_index - 1]) {
+ if (reserved_i2c[mcu_i2c_scl_list[i].periph_index - 1]) {
i2c_taken = true;
continue;
}
@@ -85,7 +84,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
//handle typedef selection, errors
if (self->sda != NULL && self->scl != NULL ) {
- I2Cx = mcu_i2c_banks[self->sda->i2c_index - 1];
+ I2Cx = mcu_i2c_banks[self->sda->periph_index - 1];
} else {
if (i2c_taken) {
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
@@ -111,8 +110,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
HAL_GPIO_Init(pin_port(scl->port), &GPIO_InitStruct);
//Note: due to I2C soft reboot issue, do not relocate clock init.
- i2c_clock_enable(1 << (self->sda->i2c_index - 1));
- reserved_i2c[self->sda->i2c_index - 1] = true;
+ i2c_clock_enable(1 << (self->sda->periph_index - 1));
+ reserved_i2c[self->sda->periph_index - 1] = true;
self->handle.Instance = I2Cx;
self->handle.Init.ClockSpeed = 100000;
@@ -152,9 +151,9 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
return;
}
- i2c_clock_disable(1 << (self->sda->i2c_index - 1));
- reserved_i2c[self->sda->i2c_index - 1] = false;
- never_reset_i2c[self->sda->i2c_index - 1] = false;
+ i2c_clock_disable(1 << (self->sda->periph_index - 1));
+ reserved_i2c[self->sda->periph_index - 1] = false;
+ never_reset_i2c[self->sda->periph_index - 1] = false;
reset_pin_number(self->sda->pin->port,self->sda->pin->number);
reset_pin_number(self->scl->pin->port,self->scl->pin->number);
diff --git a/ports/stm/common-hal/busio/I2C.h b/ports/stm/common-hal/busio/I2C.h
index b5c891a98..5ca2854eb 100644
--- a/ports/stm/common-hal/busio/I2C.h
+++ b/ports/stm/common-hal/busio/I2C.h
@@ -25,13 +25,12 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_I2C_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_I2C_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_I2C_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_I2C_H
#include "common-hal/microcontroller/Pin.h"
-#include "stm32f4xx_hal.h"
-#include "stm32f4/periph.h"
+#include "peripherals/periph.h"
#include "py/obj.h"
@@ -39,10 +38,10 @@ typedef struct {
mp_obj_base_t base;
I2C_HandleTypeDef handle;
bool has_lock;
- const mcu_i2c_scl_obj_t *scl;
- const mcu_i2c_sda_obj_t *sda;
+ const mcu_periph_obj_t *scl;
+ const mcu_periph_obj_t *sda;
} busio_i2c_obj_t;
void i2c_reset(void);
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_I2C_H
+#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_I2C_H
diff --git a/ports/stm/common-hal/busio/OneWire.h b/ports/stm/common-hal/busio/OneWire.h
index 6e8c82979..0099593f0 100644
--- a/ports/stm/common-hal/busio/OneWire.h
+++ b/ports/stm/common-hal/busio/OneWire.h
@@ -24,10 +24,10 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_ONEWIRE_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_ONEWIRE_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_ONEWIRE_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_ONEWIRE_H
// Use bitbangio.
#include "shared-module/busio/OneWire.h"
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_ONEWIRE_H
+#endif // MICROPY_INCLUDED_STM32F_COMMON_HAL_BUSIO_ONEWIRE_H
diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c
index 7e25e0a57..cf0015560 100644
--- a/ports/stm/common-hal/busio/SPI.c
+++ b/ports/stm/common-hal/busio/SPI.c
@@ -29,7 +29,6 @@
#include "shared-bindings/busio/SPI.h"
#include "py/mperrno.h"
#include "py/runtime.h"
-#include "stm32f4xx_hal.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "boards/board.h"
@@ -120,10 +119,10 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
//MISO
for (uint k = 0; k < miso_len; k++) {
if ((mcu_spi_miso_list[k].pin == miso) //everything needs the same index
- && (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[j].spi_index)
- && (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[k].spi_index)) {
+ && (mcu_spi_sck_list[i].periph_index == mcu_spi_mosi_list[j].periph_index)
+ && (mcu_spi_sck_list[i].periph_index == mcu_spi_miso_list[k].periph_index)) {
//keep looking if the SPI is taken, edge case
- if (reserved_spi[mcu_spi_sck_list[i].spi_index - 1]) {
+ if (reserved_spi[mcu_spi_sck_list[i].periph_index - 1]) {
spi_taken = true;
continue;
}
@@ -140,9 +139,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
} else if (miso != NULL) {
for (uint j = 0; j < miso_len; j++) {
if ((mcu_spi_miso_list[j].pin == miso) //only SCK and MISO need the same index
- && (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[j].spi_index)) {
+ && (mcu_spi_sck_list[i].periph_index == mcu_spi_miso_list[j].periph_index)) {
//keep looking if the SPI is taken, edge case
- if (reserved_spi[mcu_spi_sck_list[i].spi_index - 1]) {
+ if (reserved_spi[mcu_spi_sck_list[i].periph_index - 1]) {
spi_taken = true;
continue;
}
@@ -157,9 +156,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
} else if (mosi != NULL) {
for (uint j = 0; j < mosi_len; j++) {
if ((mcu_spi_mosi_list[j].pin == mosi) //only SCK and MOSI need the same index
- && (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[j].spi_index)) {
+ && (mcu_spi_sck_list[i].periph_index == mcu_spi_mosi_list[j].periph_index)) {
//keep looking if the SPI is taken, edge case
- if (reserved_spi[mcu_spi_sck_list[i].spi_index - 1]) {
+ if (reserved_spi[mcu_spi_sck_list[i].periph_index - 1]) {
spi_taken = true;
continue;
}
@@ -181,7 +180,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
if ( (self->sck != NULL && self->mosi != NULL && self->miso != NULL) ||
(self->sck != NULL && self->mosi != NULL && miso == NULL) ||
(self->sck != NULL && self->miso != NULL && mosi == NULL)) {
- SPIx = mcu_spi_banks[self->sck->spi_index - 1];
+ SPIx = mcu_spi_banks[self->sck->periph_index - 1];
} else {
if (spi_taken) {
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
@@ -217,8 +216,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
HAL_GPIO_Init(pin_port(miso->port), &GPIO_InitStruct);
}
- spi_clock_enable(1 << (self->sck->spi_index - 1));
- reserved_spi[self->sck->spi_index - 1] = true;
+ spi_clock_enable(1 << (self->sck->periph_index - 1));
+ reserved_spi[self->sck->periph_index - 1] = true;
self->handle.Instance = SPIx;
self->handle.Init.Mode = SPI_MODE_MASTER;
@@ -276,9 +275,9 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return;
}
- spi_clock_disable(1<<(self->sck->spi_index - 1));
- reserved_spi[self->sck->spi_index - 1] = false;
- never_reset_spi[self->sck->spi_index - 1] = false;
+ spi_clock_disable(1<<(self->sck->periph_index - 1));
+ reserved_spi[self->sck->periph_index - 1] = false;
+ never_reset_spi[self->sck->periph_index - 1] = false;
reset_pin_number(self->sck->pin->port,self->sck->pin->number);
if (self->mosi != NULL) {
diff --git a/ports/stm/common-hal/busio/SPI.h b/ports/stm/common-hal/busio/SPI.h
index 067d2fcb6..648318367 100644
--- a/ports/stm/common-hal/busio/SPI.h
+++ b/ports/stm/common-hal/busio/SPI.h
@@ -25,13 +25,12 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_SPI_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_SPI_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_SPI_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_SPI_H
#include "common-hal/microcontroller/Pin.h"
-#include "stm32f4xx_hal.h"
-#include "stm32f4/periph.h"
+#include "peripherals/periph.h"
#include "py/obj.h"
@@ -39,10 +38,10 @@ typedef struct {
mp_obj_base_t base;
SPI_HandleTypeDef handle;
bool has_lock;
- const mcu_spi_sck_obj_t *sck;
- const mcu_spi_mosi_obj_t *mosi;
- const mcu_spi_miso_obj_t *miso;
- const mcu_spi_nss_obj_t *nss;
+ const mcu_periph_obj_t *sck;
+ const mcu_periph_obj_t *mosi;
+ const mcu_periph_obj_t *miso;
+ const mcu_periph_obj_t *nss;
uint32_t baudrate;
uint16_t prescaler;
uint8_t polarity;
@@ -52,4 +51,4 @@ typedef struct {
void spi_reset(void);
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_SPI_H
+#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_SPI_H
diff --git a/ports/stm/common-hal/busio/UART.c b/ports/stm/common-hal/busio/UART.c
index 0b434fd02..df05a68cb 100644
--- a/ports/stm/common-hal/busio/UART.c
+++ b/ports/stm/common-hal/busio/UART.c
@@ -36,7 +36,6 @@
#include "supervisor/shared/translate.h"
#include "tick.h"
-#include "stm32f4xx_hal.h"
#define ALL_UARTS 0xFFFF
@@ -49,11 +48,11 @@ STATIC void uart_clock_disable(uint16_t mask);
STATIC void uart_assign_irq(busio_uart_obj_t* self, USART_TypeDef* USARTx);
STATIC USART_TypeDef * assign_uart_or_throw(busio_uart_obj_t* self, bool pin_eval,
- int uart_index, bool uart_taken) {
+ int periph_index, bool uart_taken) {
if (pin_eval) {
//assign a root pointer pointer for IRQ
- MP_STATE_PORT(cpy_uart_obj_all)[uart_index] = self;
- return mcu_uart_banks[uart_index];
+ MP_STATE_PORT(cpy_uart_obj_all)[periph_index] = self;
+ return mcu_uart_banks[periph_index];
} else {
if (uart_taken) {
mp_raise_ValueError(translate("Hardware in use, try alternative pins"));
@@ -84,7 +83,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uint8_t tx_len = MP_ARRAY_SIZE(mcu_uart_tx_list);
uint8_t rx_len = MP_ARRAY_SIZE(mcu_uart_rx_list);
bool uart_taken = false;
- uint8_t uart_index = 0; //origin 0 corrected
+ uint8_t periph_index = 0; //origin 0 corrected
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert == true)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
@@ -98,9 +97,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
//rx
for (uint j = 0; j < rx_len; j++) {
if (mcu_uart_rx_list[j].pin == rx
- && mcu_uart_rx_list[j].uart_index == mcu_uart_tx_list[i].uart_index) {
+ && mcu_uart_rx_list[j].periph_index == mcu_uart_tx_list[i].periph_index) {
//keep looking if the UART is taken, edge case
- if (reserved_uart[mcu_uart_tx_list[i].uart_index - 1]) {
+ if (reserved_uart[mcu_uart_tx_list[i].periph_index - 1]) {
uart_taken = true;
continue;
}
@@ -112,15 +111,15 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
}
}
- uart_index = self->tx->uart_index - 1;
+ periph_index = self->tx->periph_index - 1;
USARTx = assign_uart_or_throw(self, (self->tx != NULL && self->rx != NULL),
- uart_index, uart_taken);
+ periph_index, uart_taken);
} else if (tx == NULL) {
//If there is no tx, run only rx
for (uint i = 0; i < rx_len; i++) {
if (mcu_uart_rx_list[i].pin == rx) {
//keep looking if the UART is taken, edge case
- if (reserved_uart[mcu_uart_rx_list[i].uart_index - 1]) {
+ if (reserved_uart[mcu_uart_rx_list[i].periph_index - 1]) {
uart_taken = true;
continue;
}
@@ -129,15 +128,15 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
break;
}
}
- uart_index = self->rx->uart_index - 1;
+ periph_index = self->rx->periph_index - 1;
USARTx = assign_uart_or_throw(self, (self->rx != NULL),
- uart_index, uart_taken);
+ periph_index, uart_taken);
} else if (rx == NULL) {
//If there is no rx, run only tx
for (uint i = 0; i < tx_len; i++) {
if (mcu_uart_tx_list[i].pin == tx) {
//keep looking if the UART is taken, edge case
- if (reserved_uart[mcu_uart_tx_list[i].uart_index - 1]) {
+ if (reserved_uart[mcu_uart_tx_list[i].periph_index - 1]) {
uart_taken = true;
continue;
}
@@ -146,9 +145,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
break;
}
}
- uart_index = self->tx->uart_index - 1;
+ periph_index = self->tx->periph_index - 1;
USARTx = assign_uart_or_throw(self, (self->tx != NULL),
- uart_index, uart_taken);
+ periph_index, uart_taken);
} else {
//both pins cannot be empty
mp_raise_ValueError(translate("Supply at least one UART pin"));
@@ -185,8 +184,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
//reserve uart and enable the peripheral
- reserved_uart[uart_index] = true;
- uart_clock_enable(1 << (uart_index));
+ reserved_uart[periph_index] = true;
+ uart_clock_enable(1 << (periph_index));
uart_assign_irq(self, USARTx);
self->handle.Instance = USARTx;
diff --git a/ports/stm/common-hal/busio/UART.h b/ports/stm/common-hal/busio/UART.h
index cde5fadd0..5ac1d352c 100644
--- a/ports/stm/common-hal/busio/UART.h
+++ b/ports/stm/common-hal/busio/UART.h
@@ -24,12 +24,11 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_UART_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_UART_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_UART_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_UART_H
#include "common-hal/microcontroller/Pin.h"
-#include "stm32f4/periph.h"
-#include "stm32f4xx_hal.h"
+#include "peripherals/periph.h"
#include "py/obj.h"
#include "py/ringbuf.h"
@@ -45,8 +44,8 @@ typedef struct {
mp_obj_base_t base;
UART_HandleTypeDef handle;
IRQn_Type irq;
- const mcu_uart_tx_obj_t *tx;
- const mcu_uart_rx_obj_t *rx;
+ const mcu_periph_obj_t *tx;
+ const mcu_periph_obj_t *rx;
ringbuf_t rbuf;
uint8_t rx_char;
diff --git a/ports/stm/common-hal/digitalio/DigitalInOut.c b/ports/stm/common-hal/digitalio/DigitalInOut.c
index be2db4dac..40e13ca3b 100644
--- a/ports/stm/common-hal/digitalio/DigitalInOut.c
+++ b/ports/stm/common-hal/digitalio/DigitalInOut.c
@@ -29,8 +29,12 @@
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
-#include "stm32f4xx_hal.h"
+//TODO: rework this module to use HAL only
+#ifdef STM32H743xx
+#include "stm32h7xx_ll_gpio.h"
+#else
#include "stm32f4xx_ll_gpio.h"
+#endif
void common_hal_digitalio_digitalinout_never_reset(
digitalio_digitalinout_obj_t *self) {
diff --git a/ports/stm/common-hal/digitalio/DigitalInOut.h b/ports/stm/common-hal/digitalio/DigitalInOut.h
index 76aa2c855..e810ca3c1 100644
--- a/ports/stm/common-hal/digitalio/DigitalInOut.h
+++ b/ports/stm/common-hal/digitalio/DigitalInOut.h
@@ -25,8 +25,8 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_DIGITALIO_DIGITALINOUT_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_DIGITALIO_DIGITALINOUT_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_DIGITALIO_DIGITALINOUT_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_DIGITALIO_DIGITALINOUT_H
#include "common-hal/microcontroller/Pin.h"
@@ -35,4 +35,4 @@ typedef struct {
const mcu_pin_obj_t *pin;
} digitalio_digitalinout_obj_t;
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_DIGITALIO_DIGITALINOUT_H
+#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_DIGITALIO_DIGITALINOUT_H
diff --git a/ports/stm/common-hal/microcontroller/Pin.c b/ports/stm/common-hal/microcontroller/Pin.c
index 1d4d45b97..2c513f4aa 100644
--- a/ports/stm/common-hal/microcontroller/Pin.c
+++ b/ports/stm/common-hal/microcontroller/Pin.c
@@ -30,23 +30,22 @@
#include "supervisor/shared/rgb_led_status.h"
#include "py/mphal.h"
-#include "stm32f4/pins.h"
-#include "stm32f4xx_hal.h"
+#include "pins.h"
#ifdef MICROPY_HW_NEOPIXEL
bool neopixel_in_use;
#endif
-#if MCU_PACKAGE == 144
+#if defined(LQFP144)
#define GPIO_PORT_COUNT 7
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG};
-#elif MCU_PACKAGE == 100
+#elif defined(LQFP100_f4) || (LQFP100_x7)
#define GPIO_PORT_COUNT 5
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE};
-#elif MCU_PACKAGE == 64
+#elif defined(LQFP64)
#define GPIO_PORT_COUNT 3
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC};
-#elif MCU_PACKAGE == 48
+#elif defined(UFQFPN48)
#define GPIO_PORT_COUNT 3
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC};
#endif
diff --git a/ports/stm/common-hal/microcontroller/Pin.h b/ports/stm/common-hal/microcontroller/Pin.h
index c4c9be6a8..d69ddfb1d 100644
--- a/ports/stm/common-hal/microcontroller/Pin.h
+++ b/ports/stm/common-hal/microcontroller/Pin.h
@@ -24,12 +24,12 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM34F4_COMMON_HAL_MICROCONTROLLER_PIN_H
-#define MICROPY_INCLUDED_STM34F4_COMMON_HAL_MICROCONTROLLER_PIN_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_MICROCONTROLLER_PIN_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_MICROCONTROLLER_PIN_H
#include "py/mphal.h"
-#include "peripherals/stm32f4/pins.h"
+#include "peripherals/pins.h"
#ifdef MICROPY_HW_NEOPIXEL
extern bool neopixel_in_use;
@@ -49,4 +49,4 @@ void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number);
GPIO_TypeDef * pin_port(uint8_t pin_port);
uint16_t pin_mask(uint8_t pin_number);
-#endif // MICROPY_INCLUDED_STM34F4_COMMON_HAL_MICROCONTROLLER_PIN_H
+#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_MICROCONTROLLER_PIN_H
diff --git a/ports/stm/common-hal/microcontroller/Processor.c b/ports/stm/common-hal/microcontroller/Processor.c
index 324659cef..c8b07db3f 100644
--- a/ports/stm/common-hal/microcontroller/Processor.c
+++ b/ports/stm/common-hal/microcontroller/Processor.c
@@ -29,7 +29,7 @@
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
-#include "stm32f4xx_hal.h"
+#if defined(STM32F4)
#define STM32_UUID ((uint32_t *)0x1FFF7A10)
@@ -58,7 +58,10 @@ STATIC void set_adc_params(ADC_HandleTypeDef *AdcHandle) {
AdcHandle->Init.EOCSelection = ADC_EOC_SINGLE_CONV;
}
+#endif
+
float common_hal_mcu_processor_get_temperature(void) {
+ #if defined(STM32F4)
__HAL_RCC_ADC1_CLK_ENABLE();
//HAL Implementation
@@ -85,9 +88,13 @@ float common_hal_mcu_processor_get_temperature(void) {
//There's no F4 specific appnote for this but it works the same as the L1 in AN3964
float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 80.0;
return (((float)value * adc_refcor - *ADC_CAL1) / core_temp_avg_slope) + 30.0f;
+ #else
+ return false;
+ #endif
}
float common_hal_mcu_processor_get_voltage(void) {
+ #if defined(STM32F4)
__HAL_RCC_ADC1_CLK_ENABLE();
//HAL Implementation
@@ -114,6 +121,9 @@ float common_hal_mcu_processor_get_voltage(void) {
adc_refcor = ((float)(*VREFIN_CAL)) / ((float)value);
return adc_refcor * 3.3f;
+ #else
+ return false;
+ #endif
}
uint32_t common_hal_mcu_processor_get_frequency(void) {
@@ -121,7 +131,9 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
}
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
+ #if defined(STM32F4)
for (int i=0; i<3; i++) {
((uint32_t*) raw_id)[i] = STM32_UUID[i];
}
+ #endif
}
diff --git a/ports/stm/common-hal/microcontroller/Processor.h b/ports/stm/common-hal/microcontroller/Processor.h
index 311333e7d..1d22aa965 100644
--- a/ports/stm/common-hal/microcontroller/Processor.h
+++ b/ports/stm/common-hal/microcontroller/Processor.h
@@ -24,8 +24,8 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 12
@@ -36,4 +36,4 @@ typedef struct {
// Stores no state currently.
} mcu_processor_obj_t;
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
+#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
diff --git a/ports/stm/common-hal/microcontroller/__init__.c b/ports/stm/common-hal/microcontroller/__init__.c
index 0c680eb05..6f16c3ef2 100644
--- a/ports/stm/common-hal/microcontroller/__init__.c
+++ b/ports/stm/common-hal/microcontroller/__init__.c
@@ -39,8 +39,6 @@
#include "supervisor/filesystem.h"
#include "supervisor/shared/safe_mode.h"
-#include "stm32f4xx_hal.h"
-
//tested divisor value for busy loop in us delay
#define LOOP_TICKS 12
@@ -108,137 +106,3 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = {
.type = &mcu_processor_type,
},
};
-
-STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
-#if MCU_PACKAGE >= 100
- { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) },
- { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) },
- { MP_ROM_QSTR(MP_QSTR_PE04), MP_ROM_PTR(&pin_PE04) },
- { MP_ROM_QSTR(MP_QSTR_PE05), MP_ROM_PTR(&pin_PE05) },
- { MP_ROM_QSTR(MP_QSTR_PE06), MP_ROM_PTR(&pin_PE06) },
-#endif
- { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) },
-#if MCU_PACKAGE == 144
- { MP_ROM_QSTR(MP_QSTR_PF00), MP_ROM_PTR(&pin_PF00) },
- { MP_ROM_QSTR(MP_QSTR_PF01), MP_ROM_PTR(&pin_PF01) },
- { MP_ROM_QSTR(MP_QSTR_PF02), MP_ROM_PTR(&pin_PF02) },
- { MP_ROM_QSTR(MP_QSTR_PF03), MP_ROM_PTR(&pin_PF03) },
- { MP_ROM_QSTR(MP_QSTR_PF04), MP_ROM_PTR(&pin_PF04) },
- { MP_ROM_QSTR(MP_QSTR_PF05), MP_ROM_PTR(&pin_PF05) },
- { MP_ROM_QSTR(MP_QSTR_PF06), MP_ROM_PTR(&pin_PF06) },
- { MP_ROM_QSTR(MP_QSTR_PF07), MP_ROM_PTR(&pin_PF07) },
- { MP_ROM_QSTR(MP_QSTR_PF08), MP_ROM_PTR(&pin_PF08) },
- { MP_ROM_QSTR(MP_QSTR_PF09), MP_ROM_PTR(&pin_PF09) },
- { MP_ROM_QSTR(MP_QSTR_PF10), MP_ROM_PTR(&pin_PF10) },
-#endif
- { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_PC00) },
- { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) },
- { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) },
- { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) },
- { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_PA00) },
- { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) },
- { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) },
- { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) },
- { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) },
- { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) },
- { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) },
- { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) },
- { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) },
- { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) },
- { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) },
- { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) },
- { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) },
-#if MCU_PACKAGE == 144
- { MP_ROM_QSTR(MP_QSTR_PF11), MP_ROM_PTR(&pin_PF11) },
- { MP_ROM_QSTR(MP_QSTR_PF12), MP_ROM_PTR(&pin_PF12) },
- { MP_ROM_QSTR(MP_QSTR_PF13), MP_ROM_PTR(&pin_PF13) },
- { MP_ROM_QSTR(MP_QSTR_PF14), MP_ROM_PTR(&pin_PF14) },
- { MP_ROM_QSTR(MP_QSTR_PF15), MP_ROM_PTR(&pin_PF15) },
- { MP_ROM_QSTR(MP_QSTR_PG00), MP_ROM_PTR(&pin_PG00) },
- { MP_ROM_QSTR(MP_QSTR_PG01), MP_ROM_PTR(&pin_PG01) },
-#endif
-#if MCU_PACKAGE >= 100
- { MP_ROM_QSTR(MP_QSTR_PE07), MP_ROM_PTR(&pin_PE07) },
- { MP_ROM_QSTR(MP_QSTR_PE08), MP_ROM_PTR(&pin_PE08) },
- { MP_ROM_QSTR(MP_QSTR_PE09), MP_ROM_PTR(&pin_PE09) },
- { MP_ROM_QSTR(MP_QSTR_PE10), MP_ROM_PTR(&pin_PE10) },
- { MP_ROM_QSTR(MP_QSTR_PE11), MP_ROM_PTR(&pin_PE11) },
- { MP_ROM_QSTR(MP_QSTR_PE12), MP_ROM_PTR(&pin_PE12) },
- { MP_ROM_QSTR(MP_QSTR_PE13), MP_ROM_PTR(&pin_PE13) },
- { MP_ROM_QSTR(MP_QSTR_PE14), MP_ROM_PTR(&pin_PE14) },
- { MP_ROM_QSTR(MP_QSTR_PE15), MP_ROM_PTR(&pin_PE15) },
-#endif
- { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) },
-#if MCU_PACKAGE == 144 || defined STM32F405xx
- { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
-#endif
- { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) },
- { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) },
- { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) },
- { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) },
-#if MCU_PACKAGE >= 100
- { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) },
- { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) },
- { MP_ROM_QSTR(MP_QSTR_PD10), MP_ROM_PTR(&pin_PD10) },
- { MP_ROM_QSTR(MP_QSTR_PD11), MP_ROM_PTR(&pin_PD11) },
- { MP_ROM_QSTR(MP_QSTR_PD12), MP_ROM_PTR(&pin_PD12) },
- { MP_ROM_QSTR(MP_QSTR_PD13), MP_ROM_PTR(&pin_PD13) },
- { MP_ROM_QSTR(MP_QSTR_PD14), MP_ROM_PTR(&pin_PD14) },
- { MP_ROM_QSTR(MP_QSTR_PD15), MP_ROM_PTR(&pin_PD15) },
-#endif
-#if MCU_PACKAGE == 144
- { MP_ROM_QSTR(MP_QSTR_PG02), MP_ROM_PTR(&pin_PG02) },
- { MP_ROM_QSTR(MP_QSTR_PG03), MP_ROM_PTR(&pin_PG03) },
- { MP_ROM_QSTR(MP_QSTR_PG04), MP_ROM_PTR(&pin_PG04) },
- { MP_ROM_QSTR(MP_QSTR_PG05), MP_ROM_PTR(&pin_PG05) },
- { MP_ROM_QSTR(MP_QSTR_PG06), MP_ROM_PTR(&pin_PG06) },
- { MP_ROM_QSTR(MP_QSTR_PG07), MP_ROM_PTR(&pin_PG07) },
- { MP_ROM_QSTR(MP_QSTR_PG08), MP_ROM_PTR(&pin_PG08) },
-#endif
- { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) },
- { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) },
- { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_PC08) },
- { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_PC09) },
- { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) },
- { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) },
- { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) },
- { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) },
- { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) },
- { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) },
- { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) },
- { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) },
- { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) },
- { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) },
- { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) },
-#if MCU_PACKAGE >= 100
- { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_PD00) },
- { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) },
- { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_PD02) },
- { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_PD03) },
- { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_PD04) },
- { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) },
- { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) },
- { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) },
-#endif
-#if MCU_PACKAGE == 144
- { MP_ROM_QSTR(MP_QSTR_PG09), MP_ROM_PTR(&pin_PG09) },
- { MP_ROM_QSTR(MP_QSTR_PG10), MP_ROM_PTR(&pin_PG10) },
- { MP_ROM_QSTR(MP_QSTR_PG11), MP_ROM_PTR(&pin_PG11) },
- { MP_ROM_QSTR(MP_QSTR_PG12), MP_ROM_PTR(&pin_PG12) },
- { MP_ROM_QSTR(MP_QSTR_PG13), MP_ROM_PTR(&pin_PG13) },
- { MP_ROM_QSTR(MP_QSTR_PG14), MP_ROM_PTR(&pin_PG14) },
- { MP_ROM_QSTR(MP_QSTR_PG15), MP_ROM_PTR(&pin_PG15) },
-#endif
- { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) },
- { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) },
- { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) },
- { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) },
- { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) },
- { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) },
- { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) },
-#if MCU_PACKAGE >= 100
- { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_PE00) },
- { MP_ROM_QSTR(MP_QSTR_PE01), MP_ROM_PTR(&pin_PE01) },
-#endif
-};
-MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_globals_table);
diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c
index 0b3153286..1a1efef9f 100644
--- a/ports/stm/common-hal/os/__init__.c
+++ b/ports/stm/common-hal/os/__init__.c
@@ -33,7 +33,7 @@
#include "py/mperrno.h"
#include "py/runtime.h"
#include "stm32f4xx_hal.h"
-#include "stm32f4/periph.h"
+#include "peripherals/periph.h"
STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename,
diff --git a/ports/stm/common-hal/pulseio/PWMOut.h b/ports/stm/common-hal/pulseio/PWMOut.h
index 59fc04e5f..8519735c6 100644
--- a/ports/stm/common-hal/pulseio/PWMOut.h
+++ b/ports/stm/common-hal/pulseio/PWMOut.h
@@ -30,7 +30,7 @@
#include "common-hal/microcontroller/Pin.h"
#include "stm32f4xx_hal.h"
-#include "stm32f4/periph.h"
+#include "peripherals/periph.h"
#include "py/obj.h"
diff --git a/ports/stm/common-hal/supervisor/Runtime.h b/ports/stm/common-hal/supervisor/Runtime.h
index 9a798e056..a357eb0c7 100755
--- a/ports/stm/common-hal/supervisor/Runtime.h
+++ b/ports/stm/common-hal/supervisor/Runtime.h
@@ -24,8 +24,8 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_SUPERVISOR_RUNTIME_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_SUPERVISOR_RUNTIME_H
+#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_SUPERVISOR_RUNTIME_H
+#define MICROPY_INCLUDED_STM32_COMMON_HAL_SUPERVISOR_RUNTIME_H
#include "py/obj.h"
@@ -34,4 +34,4 @@ typedef struct {
// Stores no state currently.
} super_runtime_obj_t;
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_SUPERVISOR_RUNTIME_H
+#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_SUPERVISOR_RUNTIME_H