diff options
Diffstat (limited to 'stmhal')
-rw-r--r-- | stmhal/gccollect.c | 5 | ||||
-rw-r--r-- | stmhal/mpconfigport.h | 8 | ||||
-rw-r--r-- | stmhal/pin.c | 13 | ||||
-rw-r--r-- | stmhal/pin.h | 80 | ||||
-rw-r--r-- | stmhal/pin_defs_stmhal.h | 96 | ||||
-rw-r--r-- | stmhal/pin_named_pins.c | 5 | ||||
-rw-r--r-- | stmhal/pybstdio.c | 5 | ||||
-rw-r--r-- | stmhal/pyexec.c | 5 | ||||
-rw-r--r-- | stmhal/readline.c | 5 |
9 files changed, 137 insertions, 85 deletions
diff --git a/stmhal/gccollect.c b/stmhal/gccollect.c index 79082e2f2e..64ac7baa7d 100644 --- a/stmhal/gccollect.c +++ b/stmhal/gccollect.c @@ -25,8 +25,7 @@ */ #include <stdio.h> - -#include <stm32f4xx_hal.h> +#include <stdint.h> #include "misc.h" #include "mpconfig.h" @@ -35,6 +34,8 @@ #include "gc.h" #include "gccollect.h" +#include HAL_H + machine_uint_t gc_helper_get_regs_and_sp(machine_uint_t *regs); // obsolete diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 28cd90bb01..7c1f582755 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -104,3 +104,11 @@ typedef const void *machine_const_ptr_t; // must be of pointer size // We need to provide a declaration/definition of alloca() #include <alloca.h> + +#define HAL_H <stm32f4xx_hal.h> +#define PIN_DEFS_PORT_H "pin_defs_stmhal.h" + +#define GPIO_read_pin(gpio, pin) (((gpio)->IDR >> (pin)) & 1) +#define GPIO_set_pin(gpio, pin_mask) (((gpio)->BSRRL) = (pin_mask)) +#define GPIO_clear_pin(gpio, pin_mask) (((gpio)->BSRRH) = (pin_mask)) + diff --git a/stmhal/pin.c b/stmhal/pin.c index 9806a8c49a..6ee5fa564e 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -28,9 +28,8 @@ #include <stdint.h> #include <string.h> -#include "stm32f4xx_hal.h" - #include "mpconfig.h" +#include HAL_H #include "nlr.h" #include "misc.h" #include "qstr.h" @@ -310,13 +309,13 @@ STATIC mp_obj_t pin_value(uint n_args, mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { // get pin - return MP_OBJ_NEW_SMALL_INT((self->gpio->IDR >> self->pin) & 1); + return MP_OBJ_NEW_SMALL_INT(GPIO_read_pin(self->gpio, self->pin)); } else { // set pin if (mp_obj_is_true(args[1])) { - self->gpio->BSRRL = self->pin_mask; + GPIO_set_pin(self->gpio, self->pin_mask); } else { - self->gpio->BSRRH = self->pin_mask; + GPIO_clear_pin(self->gpio, self->pin_mask); } return mp_const_none; } @@ -327,7 +326,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); /// Set the pin to a low logic level. STATIC mp_obj_t pin_low(mp_obj_t self_in) { pin_obj_t *self = self_in; - self->gpio->BSRRH = self->pin_mask; + GPIO_clear_pin(self->gpio, self->pin_mask);; return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low); @@ -336,7 +335,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low); /// Set the pin to a high logic level. STATIC mp_obj_t pin_high(mp_obj_t self_in) { pin_obj_t *self = self_in; - self->gpio->BSRRL = self->pin_mask; + GPIO_set_pin(self->gpio, self->pin_mask);; return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high); diff --git a/stmhal/pin.h b/stmhal/pin.h index d60bd22fd7..8b3b862773 100644 --- a/stmhal/pin.h +++ b/stmhal/pin.h @@ -24,63 +24,10 @@ * THE SOFTWARE. */ -enum { - PORT_A, - PORT_B, - PORT_C, - PORT_D, - PORT_E, - PORT_F, - PORT_G, - PORT_H, - PORT_I, - PORT_J, -}; +// This file requires pin_defs_xxx.h (which has port specific enums and +// defines, so we include it here. It should never be included directly -enum { - AF_FN_TIM, - AF_FN_I2C, - AF_FN_USART, - AF_FN_UART = AF_FN_USART, - AF_FN_SPI -}; - -enum { - AF_PIN_TYPE_TIM_CH1 = 0, - AF_PIN_TYPE_TIM_CH2, - AF_PIN_TYPE_TIM_CH3, - AF_PIN_TYPE_TIM_CH4, - AF_PIN_TYPE_TIM_CH1N, - AF_PIN_TYPE_TIM_CH2N, - AF_PIN_TYPE_TIM_CH3N, - AF_PIN_TYPE_TIM_CH1_ETR, - AF_PIN_TYPE_TIM_ETR, - AF_PIN_TYPE_TIM_BKIN, - - AF_PIN_TYPE_I2C_SDA = 0, - AF_PIN_TYPE_I2C_SCL, - - AF_PIN_TYPE_USART_TX = 0, - AF_PIN_TYPE_USART_RX, - AF_PIN_TYPE_USART_CTS, - AF_PIN_TYPE_USART_RTS, - AF_PIN_TYPE_USART_CK, - AF_PIN_TYPE_UART_TX = AF_PIN_TYPE_USART_TX, - AF_PIN_TYPE_UART_RX = AF_PIN_TYPE_USART_RX, - AF_PIN_TYPE_UART_CTS = AF_PIN_TYPE_USART_CTS, - AF_PIN_TYPE_UART_RTS = AF_PIN_TYPE_USART_RTS, - - AF_PIN_TYPE_SPI_MOSI = 0, - AF_PIN_TYPE_SPI_MISO, - AF_PIN_TYPE_SPI_SCK, - AF_PIN_TYPE_SPI_NSS, -}; - -enum { - PIN_ADC1 = (1 << 0), - PIN_ADC2 = (1 << 1), - PIN_ADC3 = (1 << 2), -}; +#include PIN_DEFS_PORT_H typedef struct { mp_obj_base_t base; @@ -91,24 +38,21 @@ typedef struct { union { void *reg; - TIM_TypeDef *TIM; - I2C_TypeDef *I2C; - USART_TypeDef *USART; - USART_TypeDef *UART; - SPI_TypeDef *SPI; + + PIN_DEFS_PORT_AF_UNION }; } pin_af_obj_t; typedef struct { mp_obj_base_t base; const char *name; - uint16_t port : 4; - uint16_t pin : 4; - uint16_t num_af : 4; - uint16_t adc_channel : 4; - uint16_t adc_num : 3; // 1 bit per ADC - uint16_t pin_mask; - GPIO_TypeDef *gpio; + uint32_t port : 4; + uint32_t pin : 5; // Some ARM processors use 32 bits/PORT + uint32_t num_af : 4; + uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT + uint32_t adc_num : 3; // 1 bit per ADC + uint32_t pin_mask; + pin_gpio_t *gpio; const pin_af_obj_t *af; } pin_obj_t; diff --git a/stmhal/pin_defs_stmhal.h b/stmhal/pin_defs_stmhal.h new file mode 100644 index 0000000000..2b6d9da0e7 --- /dev/null +++ b/stmhal/pin_defs_stmhal.h @@ -0,0 +1,96 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * + * 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. + */ + +// This file contains pin definitions that are specific to the stmhal port. +// This file should only ever be #included by pin.h and not directly. + +enum { + PORT_A, + PORT_B, + PORT_C, + PORT_D, + PORT_E, + PORT_F, + PORT_G, + PORT_H, + PORT_I, + PORT_J, +}; + +enum { + AF_FN_TIM, + AF_FN_I2C, + AF_FN_USART, + AF_FN_UART = AF_FN_USART, + AF_FN_SPI +}; + +enum { + AF_PIN_TYPE_TIM_CH1 = 0, + AF_PIN_TYPE_TIM_CH2, + AF_PIN_TYPE_TIM_CH3, + AF_PIN_TYPE_TIM_CH4, + AF_PIN_TYPE_TIM_CH1N, + AF_PIN_TYPE_TIM_CH2N, + AF_PIN_TYPE_TIM_CH3N, + AF_PIN_TYPE_TIM_CH1_ETR, + AF_PIN_TYPE_TIM_ETR, + AF_PIN_TYPE_TIM_BKIN, + + AF_PIN_TYPE_I2C_SDA = 0, + AF_PIN_TYPE_I2C_SCL, + + AF_PIN_TYPE_USART_TX = 0, + AF_PIN_TYPE_USART_RX, + AF_PIN_TYPE_USART_CTS, + AF_PIN_TYPE_USART_RTS, + AF_PIN_TYPE_USART_CK, + AF_PIN_TYPE_UART_TX = AF_PIN_TYPE_USART_TX, + AF_PIN_TYPE_UART_RX = AF_PIN_TYPE_USART_RX, + AF_PIN_TYPE_UART_CTS = AF_PIN_TYPE_USART_CTS, + AF_PIN_TYPE_UART_RTS = AF_PIN_TYPE_USART_RTS, + + AF_PIN_TYPE_SPI_MOSI = 0, + AF_PIN_TYPE_SPI_MISO, + AF_PIN_TYPE_SPI_SCK, + AF_PIN_TYPE_SPI_NSS, +}; + +enum { + PIN_ADC1 = (1 << 0), + PIN_ADC2 = (1 << 1), + PIN_ADC3 = (1 << 2), +}; + +#define PIN_DEFS_PORT_AF_UNION \ + TIM_TypeDef *TIM; \ + I2C_TypeDef *I2C; \ + USART_TypeDef *USART; \ + USART_TypeDef *UART; \ + SPI_TypeDef *SPI; + +typedef GPIO_TypeDef pin_gpio_t; + diff --git a/stmhal/pin_named_pins.c b/stmhal/pin_named_pins.c index 3a1794e1d9..137b6bef82 100644 --- a/stmhal/pin_named_pins.c +++ b/stmhal/pin_named_pins.c @@ -28,10 +28,11 @@ #include <stdint.h> #include <string.h> -#include "stm32f4xx_hal.h" - #include "misc.h" #include "mpconfig.h" + +#include HAL_H + #include "qstr.h" #include "obj.h" #include "runtime.h" diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c index 05ea06eb44..b6b5560be1 100644 --- a/stmhal/pybstdio.c +++ b/stmhal/pybstdio.c @@ -25,8 +25,7 @@ */ #include <stdio.h> - -#include <stm32f4xx_hal.h> +#include <stdint.h> #include "misc.h" #include "mpconfig.h" @@ -38,6 +37,8 @@ #include "usb.h" #include "uart.h" +#include HAL_H + // TODO make stdin, stdout and stderr writable objects so they can // be changed by Python code. diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c index 45928427e1..48be225af2 100644 --- a/stmhal/pyexec.c +++ b/stmhal/pyexec.c @@ -26,8 +26,7 @@ #include <stdlib.h> #include <stdio.h> - -#include <stm32f4xx_hal.h> +#include <stdint.h> #include "mpconfig.h" #include "nlr.h" @@ -50,6 +49,8 @@ #include "usb.h" #include "genhdr/py-version.h" +#include HAL_H + pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; STATIC bool repl_display_debugging_info = 0; diff --git a/stmhal/readline.c b/stmhal/readline.c index d40bd4219b..f75734396d 100644 --- a/stmhal/readline.c +++ b/stmhal/readline.c @@ -25,10 +25,9 @@ */ #include <stdio.h> +#include <stdint.h> #include <string.h> -#include <stm32f4xx_hal.h> - #include "misc.h" #include "mpconfig.h" #include "qstr.h" @@ -38,6 +37,8 @@ #include "readline.h" #include "usb.h" +#include HAL_H + #if 0 // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf printf |