diff options
Diffstat (limited to 'stmhal')
45 files changed, 109 insertions, 91 deletions
diff --git a/stmhal/Makefile b/stmhal/Makefile index e27dd7b6ce..3cc98d7be8 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -41,7 +41,7 @@ INC += -I$(FATFS_DIR)/src INC += -I$(CC3K_DIR) CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT) +CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) CFLAGS += -Iboards/$(BOARD) @@ -53,7 +53,7 @@ else COPT += -Os -DNDEBUG endif -LDFLAGS = --nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref +LDFLAGS = -nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref LIBS = # uncomment this if you want libgcc diff --git a/stmhal/adc.c b/stmhal/adc.c index 4930310fd3..817b32ea89 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -80,7 +80,7 @@ typedef struct _pyb_obj_adc_t { ADC_HandleTypeDef handle; } pyb_obj_adc_t; -void adc_init_single(pyb_obj_adc_t *adc_obj) { +STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) { if (!IS_ADC_CHANNEL(adc_obj->channel)) { return; } @@ -114,7 +114,9 @@ void adc_init_single(pyb_obj_adc_t *adc_obj) { adcHandle->Init.EOCSelection = DISABLE; HAL_ADC_Init(adcHandle); +} +STATIC void adc_config_channel(pyb_obj_adc_t *adc_obj) { ADC_ChannelConfTypeDef sConfig; sConfig.Channel = adc_obj->channel; @@ -122,10 +124,10 @@ void adc_init_single(pyb_obj_adc_t *adc_obj) { sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; sConfig.Offset = 0; - HAL_ADC_ConfigChannel(adcHandle, &sConfig); + HAL_ADC_ConfigChannel(&adc_obj->handle, &sConfig); } -uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) { +STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) { uint32_t rawValue = 0; HAL_ADC_Start(adcHandle); @@ -193,13 +195,16 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ STATIC mp_obj_t adc_read(mp_obj_t self_in) { pyb_obj_adc_t *self = self_in; + adc_config_channel(self); uint32_t data = adc_read_channel(&self->handle); return mp_obj_new_int(data); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read); /// \method read_timed(buf, freq) -/// Read analog values into the given buffer at the given frequency. +/// Read analog values into the given buffer at the given frequency. Buffer +/// can be bytearray or array.array for example. If a buffer with 8-bit elements +/// is used, sample resolution will be reduced to 8 bits. /// /// Example: /// @@ -226,6 +231,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_ // This uses the timer in polling mode to do the sampling // We could use DMA, but then we can't convert the values correctly for the buffer + adc_config_channel(self); for (uint index = 0; index < bufinfo.len; index++) { // Wait for the timer to trigger while (__HAL_TIM_GET_FLAG(&TIM6_Handle, TIM_FLAG_UPDATE) == RESET) { diff --git a/stmhal/boards/HYDRABUS/mpconfigboard.h b/stmhal/boards/HYDRABUS/mpconfigboard.h index f87a14142e..db49434b5b 100644 --- a/stmhal/boards/HYDRABUS/mpconfigboard.h +++ b/stmhal/boards/HYDRABUS/mpconfigboard.h @@ -1,6 +1,7 @@ #define HYDRABUSV10 #define MICROPY_HW_BOARD_NAME "HydraBus1.0" +#define MICROPY_HW_MCU_NAME "STM32F4" #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_SDCARD (1) diff --git a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h index 0e40545253..2679aee576 100644 --- a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h +++ b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h @@ -1,6 +1,7 @@ #define NETDUINO_PLUS_2 #define MICROPY_HW_BOARD_NAME "NetduinoPlus2" +#define MICROPY_HW_MCU_NAME "STM32F405RG" #define MICROPY_HW_HAS_SWITCH (1) diff --git a/stmhal/boards/PYBV10/mpconfigboard.h b/stmhal/boards/PYBV10/mpconfigboard.h index 3def531232..4ae6954a7d 100644 --- a/stmhal/boards/PYBV10/mpconfigboard.h +++ b/stmhal/boards/PYBV10/mpconfigboard.h @@ -1,6 +1,7 @@ #define PYBV10 #define MICROPY_HW_BOARD_NAME "PYBv1.0" +#define MICROPY_HW_MCU_NAME "STM32F405RG" #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_SDCARD (1) diff --git a/stmhal/boards/PYBV3/mpconfigboard.h b/stmhal/boards/PYBV3/mpconfigboard.h index ac0d84ca29..43d860a0cc 100644 --- a/stmhal/boards/PYBV3/mpconfigboard.h +++ b/stmhal/boards/PYBV3/mpconfigboard.h @@ -1,6 +1,7 @@ #define PYBV3 #define MICROPY_HW_BOARD_NAME "PYBv3" +#define MICROPY_HW_MCU_NAME "STM32F405RG" #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_SDCARD (1) diff --git a/stmhal/boards/PYBV4/mpconfigboard.h b/stmhal/boards/PYBV4/mpconfigboard.h index 9fedb70136..a278dea9fb 100644 --- a/stmhal/boards/PYBV4/mpconfigboard.h +++ b/stmhal/boards/PYBV4/mpconfigboard.h @@ -1,6 +1,7 @@ #define PYBV4 #define MICROPY_HW_BOARD_NAME "PYBv4" +#define MICROPY_HW_MCU_NAME "STM32F405RG" #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_SDCARD (1) diff --git a/stmhal/boards/STM32F4DISC/mpconfigboard.h b/stmhal/boards/STM32F4DISC/mpconfigboard.h index e6780eacbd..10bbe45188 100644 --- a/stmhal/boards/STM32F4DISC/mpconfigboard.h +++ b/stmhal/boards/STM32F4DISC/mpconfigboard.h @@ -1,6 +1,7 @@ #define STM32F4DISC #define MICROPY_HW_BOARD_NAME "F4DISC" +#define MICROPY_HW_MCU_NAME "STM32F407" #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_SDCARD (0) diff --git a/stmhal/boards/stm32f4xx-prefix.c b/stmhal/boards/stm32f4xx-prefix.c index 4d2313075a..3bbb6bda0e 100644 --- a/stmhal/boards/stm32f4xx-prefix.c +++ b/stmhal/boards/stm32f4xx-prefix.c @@ -5,8 +5,8 @@ #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "pin.h" diff --git a/stmhal/bufhelper.c b/stmhal/bufhelper.c index dd72655520..1f823ea963 100644 --- a/stmhal/bufhelper.c +++ b/stmhal/bufhelper.c @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "bufhelper.h" diff --git a/stmhal/dac.c b/stmhal/dac.c index 81ce993a8c..725e14e906 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -237,7 +237,7 @@ STATIC const mp_arg_t pyb_dac_write_timed_args[] = { { MP_QSTR_freq, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DMA_NORMAL} }, }; -#define PYB_DAC_WRITE_TIMED_NUM_ARGS ARRAY_SIZE(pyb_dac_write_timed_args) +#define PYB_DAC_WRITE_TIMED_NUM_ARGS MP_ARRAY_SIZE(pyb_dac_write_timed_args) mp_obj_t pyb_dac_write_timed(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { pyb_dac_obj_t *self = args[0]; diff --git a/stmhal/diskio.c b/stmhal/diskio.c index cde5874946..35b9eab99f 100644 --- a/stmhal/diskio.c +++ b/stmhal/diskio.c @@ -32,8 +32,8 @@ #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "systick.h" diff --git a/stmhal/extint.c b/stmhal/extint.c index 24d51ffb8d..591246cdd1 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -296,7 +296,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = { { MP_QSTR_pull, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_callback, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -#define PYB_EXTINT_MAKE_NEW_NUM_ARGS ARRAY_SIZE(pyb_extint_make_new_args) +#define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args) STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // type_in == extint_obj_type diff --git a/stmhal/gccollect.c b/stmhal/gccollect.c index 64ac7baa7d..c71ed13a5e 100644 --- a/stmhal/gccollect.c +++ b/stmhal/gccollect.c @@ -27,14 +27,13 @@ #include <stdio.h> #include <stdint.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "gc.h" #include "gccollect.h" - -#include HAL_H +#include MICROPY_HAL_H machine_uint_t gc_helper_get_regs_and_sp(machine_uint_t *regs); diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 00501a57da..b6ab531293 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -220,7 +220,7 @@ STATIC const mp_arg_t pyb_i2c_init_args[] = { { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} }, { MP_QSTR_gencall, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; -#define PYB_I2C_INIT_NUM_ARGS ARRAY_SIZE(pyb_i2c_init_args) +#define PYB_I2C_INIT_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_init_args) STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // parse args @@ -271,7 +271,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1; // check i2c number - if (!(0 <= i2c_id && i2c_id < ARRAY_SIZE(pyb_i2c_obj) && pyb_i2c_obj[i2c_id].i2c != NULL)) { + if (!(0 <= i2c_id && i2c_id < MP_ARRAY_SIZE(pyb_i2c_obj) && pyb_i2c_obj[i2c_id].i2c != NULL)) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C bus %d does not exist", i2c_id + 1)); } @@ -363,7 +363,7 @@ STATIC const mp_arg_t pyb_i2c_send_args[] = { { MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_I2C_SEND_NUM_ARGS ARRAY_SIZE(pyb_i2c_send_args) +#define PYB_I2C_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_send_args) STATIC mp_obj_t pyb_i2c_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { pyb_i2c_obj_t *self = args[0]; @@ -414,7 +414,7 @@ STATIC const mp_arg_t pyb_i2c_recv_args[] = { { MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_I2C_RECV_NUM_ARGS ARRAY_SIZE(pyb_i2c_recv_args) +#define PYB_I2C_RECV_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_recv_args) STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { pyb_i2c_obj_t *self = args[0]; @@ -470,7 +470,7 @@ STATIC const mp_arg_t pyb_i2c_mem_read_args[] = { { MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_I2C_MEM_READ_NUM_ARGS ARRAY_SIZE(pyb_i2c_mem_read_args) +#define PYB_I2C_MEM_READ_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_mem_read_args) STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { pyb_i2c_obj_t *self = args[0]; diff --git a/stmhal/import.c b/stmhal/import.c index abc618bef0..88ddaefacf 100644 --- a/stmhal/import.c +++ b/stmhal/import.c @@ -27,8 +27,8 @@ #include <stdio.h> #include <stdint.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "lexer.h" #include "ff.h" diff --git a/stmhal/led.c b/stmhal/led.c index 8cef02425a..c1b298b179 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -61,7 +61,7 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = { #endif #endif }; -#define NUM_LEDS ARRAY_SIZE(pyb_led_obj) +#define NUM_LEDS MP_ARRAY_SIZE(pyb_led_obj) void led_init(void) { /* GPIO structure */ @@ -148,18 +148,9 @@ void led_toggle(pyb_led_t led) { } #endif + // toggle the output data register to toggle the LED state const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin; - GPIO_TypeDef *gpio = led_pin->gpio; - - // We don't know if we're turning the LED on or off, but we don't really - // care. Just invert the state. - if (gpio->ODR & led_pin->pin_mask) { - // pin is high, make it low - gpio->BSRRH = led_pin->pin_mask; - } else { - // pin is low, make it high - gpio->BSRRL = led_pin->pin_mask; - } + led_pin->gpio->ODR ^= led_pin->pin_mask; } int led_get_intensity(pyb_led_t led) { diff --git a/stmhal/lexerfatfs.c b/stmhal/lexerfatfs.c index 6a0e83fb13..c578b13af6 100644 --- a/stmhal/lexerfatfs.c +++ b/stmhal/lexerfatfs.c @@ -27,8 +27,8 @@ #include <stdint.h> #include <stdio.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "lexer.h" #include "lexerfatfs.h" diff --git a/stmhal/main.c b/stmhal/main.c index 9751dcac2e..0e260e18cd 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -29,10 +29,10 @@ #include "stm32f4xx_hal.h" +#include "mpconfig.h" #include "misc.h" #include "systick.h" #include "pendsv.h" -#include "mpconfig.h" #include "qstr.h" #include "misc.h" #include "nlr.h" @@ -40,6 +40,7 @@ #include "parse.h" #include "obj.h" #include "runtime.h" +#include "stackctrl.h" #include "gc.h" #include "gccollect.h" #include "pybstdio.h" @@ -85,7 +86,7 @@ void flash_error(int n) { led_state(PYB_LED_R2, 0); } -void __fatal_error(const char *msg) { +void NORETURN __fatal_error(const char *msg) { for (volatile uint delay = 0; delay < 10000000; delay++) { } led_state(1, 1); @@ -111,8 +112,7 @@ void nlr_jump_fail(void *val) { } #ifndef NDEBUG -void __attribute__((weak)) - __assert_func(const char *file, int line, const char *func, const char *expr) { +void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) { (void)func; printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line); __fatal_error(""); @@ -186,6 +186,10 @@ static const char fresh_readme_txt[] = int main(void) { // TODO disable JTAG + // Stack limit should be less than real stack size, so we + // had chance to recover from limit hit. + mp_stack_set_limit(&_ram_end - &_heap_end - 512); + /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec @@ -308,7 +312,7 @@ soft_reset: MP_OBJ_NEW_SMALL_INT(115200), }; pyb_uart_global_debug = pyb_uart_type.make_new((mp_obj_t)&pyb_uart_type, - ARRAY_SIZE(args), + MP_ARRAY_SIZE(args), 0, args); } #else diff --git a/stmhal/math.c b/stmhal/math.c index 637f447cf1..91ffb2503f 100644 --- a/stmhal/math.c +++ b/stmhal/math.c @@ -72,6 +72,7 @@ float __attribute__((pcs("aapcs"))) __aeabi_d2f(double x) { fx.m = (dx.m>>(52-23)); // right justify return fx.f; } + double __aeabi_dmul(double x , double y) { return 0.0; @@ -85,6 +86,18 @@ float sqrtf(float x) { return x; } +#ifndef NDEBUG +float copysignf(float x, float y) { + float_s_t fx={.f = x}; + float_s_t fy={.f = y}; + + // copy sign bit; + fx.s = fy.s; + + return fx.f; +} +#endif + // some compilers define log2f in terms of logf #ifdef log2f #undef log2f diff --git a/stmhal/modos.c b/stmhal/modos.c index 4a6949a844..e0df05ca6b 100644 --- a/stmhal/modos.c +++ b/stmhal/modos.c @@ -194,8 +194,8 @@ STATIC const mp_obj_dict_t os_module_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(os_module_globals_table), - .alloc = ARRAY_SIZE(os_module_globals_table), + .used = MP_ARRAY_SIZE(os_module_globals_table), + .alloc = MP_ARRAY_SIZE(os_module_globals_table), .table = (mp_map_elem_t*)os_module_globals_table, }, }; diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index 6879a2c1b7..9dcd0e76ca 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -426,8 +426,8 @@ STATIC const mp_obj_dict_t pyb_module_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(pyb_module_globals_table), - .alloc = ARRAY_SIZE(pyb_module_globals_table), + .used = MP_ARRAY_SIZE(pyb_module_globals_table), + .alloc = MP_ARRAY_SIZE(pyb_module_globals_table), .table = (mp_map_elem_t*)pyb_module_globals_table, }, }; diff --git a/stmhal/modstm.c b/stmhal/modstm.c index 520c8e51bd..1196ff82ff 100644 --- a/stmhal/modstm.c +++ b/stmhal/modstm.c @@ -131,8 +131,8 @@ STATIC const mp_obj_dict_t stm_module_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(stm_module_globals_table), - .alloc = ARRAY_SIZE(stm_module_globals_table), + .used = MP_ARRAY_SIZE(stm_module_globals_table), + .alloc = MP_ARRAY_SIZE(stm_module_globals_table), .table = (mp_map_elem_t*)stm_module_globals_table, }, }; diff --git a/stmhal/modtime.c b/stmhal/modtime.c index 4fbee31293..ea4e3210a6 100644 --- a/stmhal/modtime.c +++ b/stmhal/modtime.c @@ -122,8 +122,8 @@ STATIC const mp_obj_dict_t time_module_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(time_module_globals_table), - .alloc = ARRAY_SIZE(time_module_globals_table), + .used = MP_ARRAY_SIZE(time_module_globals_table), + .alloc = MP_ARRAY_SIZE(time_module_globals_table), .table = (mp_map_elem_t*)time_module_globals_table, }, }; diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 7c1f582755..28e654c8a6 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -44,6 +44,7 @@ */ #define MICROPY_ENABLE_LFN (1) #define MICROPY_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ +#define MICROPY_PY_BUILTINS_STR_UNICODE (0) #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_STDFILES (1) @@ -105,10 +106,5 @@ 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)) - +#define MICROPY_HAL_H "mphal.h" +#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h" diff --git a/stmhal/mphal.h b/stmhal/mphal.h new file mode 100644 index 0000000000..4e9a8b2bb8 --- /dev/null +++ b/stmhal/mphal.h @@ -0,0 +1,7 @@ +// We use the ST Cube HAL library for most hardware peripherals +#include <stm32f4xx_hal.h> + +// Basic GPIO functions +#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/pendsv.c b/stmhal/pendsv.c index f8e3b30072..a0eff7e5de 100644 --- a/stmhal/pendsv.c +++ b/stmhal/pendsv.c @@ -27,8 +27,8 @@ #include <stdlib.h> #include <stm32f4xx_hal.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "pendsv.h" diff --git a/stmhal/pin.c b/stmhal/pin.c index 6ee5fa564e..a9ebfa9766 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -29,12 +29,12 @@ #include <string.h> #include "mpconfig.h" -#include HAL_H #include "nlr.h" #include "misc.h" #include "qstr.h" #include "obj.h" #include "runtime.h" +#include MICROPY_HAL_H #include "pin.h" /// \moduleref pyb @@ -99,8 +99,8 @@ STATIC mp_obj_t pin_class_map_dict; STATIC bool pin_class_debug; void pin_init(void) { - pin_class_mapper = MP_OBJ_NULL; - pin_class_map_dict = MP_OBJ_NULL; + pin_class_mapper = mp_const_none; + pin_class_map_dict = mp_const_none; pin_class_debug = false; } @@ -119,7 +119,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) { return pin_obj; } - if (pin_class_mapper != MP_OBJ_NULL) { + if (pin_class_mapper != mp_const_none) { pin_obj = mp_call_function_1(pin_class_mapper, user_obj); if (pin_obj != mp_const_none) { if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) { @@ -138,7 +138,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) { // other lookup methods. } - if (pin_class_map_dict != MP_OBJ_NULL) { + if (pin_class_map_dict != mp_const_none) { mp_map_t *pin_map_map = mp_obj_dict_get_map(pin_class_map_dict); mp_map_elem_t *elem = mp_map_lookup(pin_map_map, user_obj, MP_MAP_LOOKUP); if (elem != NULL && elem->value != NULL) { diff --git a/stmhal/pin.h b/stmhal/pin.h index 8b3b862773..8513db109b 100644 --- a/stmhal/pin.h +++ b/stmhal/pin.h @@ -27,7 +27,7 @@ // 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 -#include PIN_DEFS_PORT_H +#include MICROPY_PIN_DEFS_PORT_H typedef struct { mp_obj_base_t base; diff --git a/stmhal/pin_named_pins.c b/stmhal/pin_named_pins.c index 137b6bef82..dbf03d1a0f 100644 --- a/stmhal/pin_named_pins.c +++ b/stmhal/pin_named_pins.c @@ -28,14 +28,12 @@ #include <stdint.h> #include <string.h> -#include "misc.h" #include "mpconfig.h" - -#include HAL_H - +#include "misc.h" #include "qstr.h" #include "obj.h" #include "runtime.h" +#include MICROPY_HAL_H #include "pin.h" STATIC void pin_named_pins_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { diff --git a/stmhal/printf.c b/stmhal/printf.c index 26c552039f..c4731aa88d 100644 --- a/stmhal/printf.c +++ b/stmhal/printf.c @@ -28,10 +28,10 @@ #include <string.h> #include <stdarg.h> +#include "mpconfig.h" #include "std.h" #include "misc.h" #include "systick.h" -#include "mpconfig.h" #include "qstr.h" #include "obj.h" #include "pfenv.h" diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c index b6b5560be1..5447a62202 100644 --- a/stmhal/pybstdio.c +++ b/stmhal/pybstdio.c @@ -27,18 +27,17 @@ #include <stdio.h> #include <stdint.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "misc.h" #include "obj.h" #include "stream.h" +#include MICROPY_HAL_H #include "pybstdio.h" #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 48be225af2..93f4d62a96 100644 --- a/stmhal/pyexec.c +++ b/stmhal/pyexec.c @@ -42,6 +42,7 @@ #include "repl.h" #include "gc.h" #include "gccollect.h" +#include MICROPY_HAL_H #include "systick.h" #include "pybstdio.h" #include "readline.h" @@ -49,8 +50,6 @@ #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; @@ -186,7 +185,7 @@ int pyexec_friendly_repl(void) { #endif friendly_repl_reset: - stdout_tx_str("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with STM32F405RG\r\n"); + stdout_tx_str("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n"); stdout_tx_str("Type \"help()\" for more information.\r\n"); // to test ctrl-C diff --git a/stmhal/readline.c b/stmhal/readline.c index f75734396d..0703dcf4ea 100644 --- a/stmhal/readline.c +++ b/stmhal/readline.c @@ -28,17 +28,16 @@ #include <stdint.h> #include <string.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "misc.h" #include "obj.h" +#include MICROPY_HAL_H #include "pybstdio.h" #include "readline.h" #include "usb.h" -#include HAL_H - #if 0 // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf printf diff --git a/stmhal/rng.c b/stmhal/rng.c index 69fcb9d6ff..ea636770c0 100644 --- a/stmhal/rng.c +++ b/stmhal/rng.c @@ -28,8 +28,8 @@ #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "rng.h" diff --git a/stmhal/rtc.c b/stmhal/rtc.c index 412816c396..8f0d007327 100644 --- a/stmhal/rtc.c +++ b/stmhal/rtc.c @@ -28,8 +28,8 @@ #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "runtime.h" diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index bd45af3a14..204dbe3b46 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -28,8 +28,8 @@ #include <stm32f4xx_hal.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "runtime.h" diff --git a/stmhal/spi.c b/stmhal/spi.c index 10ecf7ec8e..448b8696ea 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -188,7 +188,7 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = { {{&pyb_spi_type}, NULL}, #endif }; -#define PYB_NUM_SPI ARRAY_SIZE(pyb_spi_obj) +#define PYB_NUM_SPI MP_ARRAY_SIZE(pyb_spi_obj) STATIC void pyb_spi_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { pyb_spi_obj_t *self = self_in; @@ -242,7 +242,7 @@ STATIC const mp_arg_t pyb_spi_init_args[] = { { MP_QSTR_ti, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, { MP_QSTR_crc, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; -#define PYB_SPI_INIT_NUM_ARGS ARRAY_SIZE(pyb_spi_init_args) +#define PYB_SPI_INIT_NUM_ARGS MP_ARRAY_SIZE(pyb_spi_init_args) STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // parse args @@ -359,7 +359,7 @@ STATIC const mp_arg_t pyb_spi_send_args[] = { { MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_SPI_SEND_NUM_ARGS ARRAY_SIZE(pyb_spi_send_args) +#define PYB_SPI_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_spi_send_args) STATIC mp_obj_t pyb_spi_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide @@ -401,7 +401,7 @@ STATIC const mp_arg_t pyb_spi_recv_args[] = { { MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_SPI_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_recv_args) +#define PYB_SPI_RECV_NUM_ARGS MP_ARRAY_SIZE(pyb_spi_recv_args) STATIC mp_obj_t pyb_spi_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide @@ -449,7 +449,7 @@ STATIC const mp_arg_t pyb_spi_send_recv_args[] = { { MP_QSTR_recv, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_SPI_SEND_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_send_recv_args) +#define PYB_SPI_SEND_RECV_NUM_ARGS MP_ARRAY_SIZE(pyb_spi_send_recv_args) STATIC mp_obj_t pyb_spi_send_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide diff --git a/stmhal/stm32f4xx_hal_msp.c b/stmhal/stm32f4xx_hal_msp.c index 5816249e25..90baa41f82 100644 --- a/stmhal/stm32f4xx_hal_msp.c +++ b/stmhal/stm32f4xx_hal_msp.c @@ -66,8 +66,8 @@ #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "servo.h" diff --git a/stmhal/stm32f4xx_it.c b/stmhal/stm32f4xx_it.c index 17cdaf5fa2..5fa7f8289d 100644 --- a/stmhal/stm32f4xx_it.c +++ b/stmhal/stm32f4xx_it.c @@ -70,8 +70,8 @@ #include "stm32f4xx_it.h" #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "extint.h" diff --git a/stmhal/storage.c b/stmhal/storage.c index ba7e303e21..001d87afe0 100644 --- a/stmhal/storage.c +++ b/stmhal/storage.c @@ -28,9 +28,9 @@ #include <string.h> #include <stm32f4xx_hal.h> +#include "mpconfig.h" #include "misc.h" #include "systick.h" -#include "mpconfig.h" #include "qstr.h" #include "obj.h" #include "led.h" diff --git a/stmhal/systick.c b/stmhal/systick.c index 8a8d6403dc..196f1fbcae 100644 --- a/stmhal/systick.c +++ b/stmhal/systick.c @@ -25,6 +25,7 @@ */ #include <stm32f4xx_hal.h> +#include "mpconfig.h" #include "misc.h" #include "systick.h" diff --git a/stmhal/timer.c b/stmhal/timer.c index 0ba24754b2..ec0c4dec4c 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -105,7 +105,7 @@ static uint32_t tim3_counter = 0; // Used to do callbacks to Python code on interrupt STATIC pyb_timer_obj_t *pyb_timer_obj_all[14]; -#define PYB_TIMER_OBJ_ALL_NUM ARRAY_SIZE(pyb_timer_obj_all) +#define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(pyb_timer_obj_all) void timer_init0(void) { tim3_counter = 0; @@ -234,7 +234,7 @@ STATIC const mp_arg_t pyb_timer_init_args[] = { { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIM_COUNTERMODE_UP} }, { MP_QSTR_div, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIM_CLOCKDIVISION_DIV1} }, }; -#define PYB_TIMER_INIT_NUM_ARGS ARRAY_SIZE(pyb_timer_init_args) +#define PYB_TIMER_INIT_NUM_ARGS MP_ARRAY_SIZE(pyb_timer_init_args) STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // parse args diff --git a/stmhal/uart.c b/stmhal/uart.c index 5bbd9f299e..a85f7f9e3a 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -270,7 +270,7 @@ STATIC const mp_arg_t pyb_uart_init_args[] = { { MP_QSTR_stop, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_parity, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; -#define PYB_UART_INIT_NUM_ARGS ARRAY_SIZE(pyb_uart_init_args) +#define PYB_UART_INIT_NUM_ARGS MP_ARRAY_SIZE(pyb_uart_init_args) STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // parse args @@ -396,7 +396,7 @@ STATIC const mp_arg_t pyb_uart_send_args[] = { { MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_UART_SEND_NUM_ARGS ARRAY_SIZE(pyb_uart_send_args) +#define PYB_UART_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_uart_send_args) STATIC mp_obj_t pyb_uart_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide @@ -438,7 +438,7 @@ STATIC const mp_arg_t pyb_uart_recv_args[] = { { MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; -#define PYB_UART_RECV_NUM_ARGS ARRAY_SIZE(pyb_uart_recv_args) +#define PYB_UART_RECV_NUM_ARGS MP_ARRAY_SIZE(pyb_uart_recv_args) STATIC mp_obj_t pyb_uart_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c index 4ed9e3abe4..8a082eac95 100644 --- a/stmhal/usrsw.c +++ b/stmhal/usrsw.c @@ -28,8 +28,8 @@ #include "stm32f4xx_hal.h" -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "runtime.h" |