From 847d7d0c2883de67f72fb9d25bc87e9920b7df51 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sat, 26 Jan 2019 20:34:20 +1300 Subject: [PATCH] Clean compiling stm32F1 and F4 with stm32GENERIC --- platformio.ini | 14 ++++++++++++-- speeduino/auxiliaries.ino | 7 ------- speeduino/board_stm32.h | 12 ++++++++++-- speeduino/board_stm32.ino | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index cf6befb3..d51fb5ee 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,12 +30,22 @@ lib_deps = EEPROM, FlexCAN ;lib_deps = EEPROM [env:genericSTM32F103RB] -platform = ststm32@~4.5.0 +;platform = ststm32@~4.5.0 +platform = ststm32 framework = arduino ; framework-arduinoststm32 board = genericSTM32F103RB +lib_deps = EEPROM, HardwareTimer, Flash_STM32 +build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS -DUSE_STM32GENERIC -DMENU_USB_SERIAL + +[env:black_F407VE] +;platform = ststm32@~4.5.0 +platform = ststm32 +framework = arduino +; framework-arduinoststm32 +board = black_F407VE lib_deps = EEPROM -build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS +build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS -DUSE_STM32GENERIC -DMENU_USB_SERIAL [env:bluepill_f103c8] platform = ststm32 diff --git a/speeduino/auxiliaries.ino b/speeduino/auxiliaries.ino index 505a1c94..d16f9baa 100644 --- a/speeduino/auxiliaries.ino +++ b/speeduino/auxiliaries.ino @@ -82,13 +82,6 @@ void initialiseAuxPWM() currentStatus.boostDuty = 0; boostCounter = 0; - #if defined(CORE_STM32) //Need to be initialised last due to instant interrupt - Timer1.setMode(2, TIMER_OUTPUT_COMPARE); - Timer1.setMode(3, TIMER_OUTPUT_COMPARE); - if(boost_pwm_max_count > 0) { Timer1.attachInterrupt(2, boostInterrupt);} - if(vvt_pwm_max_count > 0) { Timer1.attachInterrupt(3, vvtInterrupt);} - Timer1.resume(); - #endif currentStatus.nitrous_status = NITROUS_OFF; diff --git a/speeduino/board_stm32.h b/speeduino/board_stm32.h index cf61fe99..81835bca 100644 --- a/speeduino/board_stm32.h +++ b/speeduino/board_stm32.h @@ -2,8 +2,6 @@ #define STM32_H #if defined(CORE_STM32) -#include "HardwareTimer.h" - /* *********************************************************************************************************** * General @@ -14,6 +12,10 @@ void initBoard(); uint16_t freeRam(); + #if defined(USE_STM32GENERIC) + #define Serial Serial1 + #endif + //Much of the below is not correct, but included to allow compilation //STM32F1/variants/.../board.cpp #if defined (STM32F4) @@ -278,6 +280,12 @@ #define IDLE_TIMER_DISABLE() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC4E #endif +/* +*********************************************************************************************************** +* Timers +*/ + + /* *********************************************************************************************************** * CAN / Second serial diff --git a/speeduino/board_stm32.ino b/speeduino/board_stm32.ino index 334f6d95..5749f106 100644 --- a/speeduino/board_stm32.ino +++ b/speeduino/board_stm32.ino @@ -4,6 +4,11 @@ #include "auxiliaries.h" #include "idle.h" #include "scheduler.h" +#include "HardwareTimer.h" +#if defined(STM32F4) + #include + HardwareTimer Timer8(TIM8, chip_tim8, sizeof(chip_tim8) / sizeof(chip_tim8[0])); +#endif void initBoard() { @@ -11,6 +16,7 @@ void initBoard() *********************************************************************************************************** * General */ + #define FLASH_LENGTH 8192 /* @@ -24,6 +30,7 @@ void initBoard() //This must happen at the end of the idle init Timer1.setMode(4, TIMER_OUTPUT_COMPARE); + //timer_set_mode(TIMER1, 4, TIMER_OUTPUT_COMPARE; if(idle_pwm_max_count > 0) { Timer1.attachInterrupt(4, idleInterrupt);} //on first flash the configPage4.iacAlgorithm is invalid Timer1.resume(); @@ -53,6 +60,13 @@ void initBoard() boost_pwm_max_count = 1000000L / (2 * configPage6.boostFreq * 2); //Converts the frequency in Hz to the number of ticks (at 2uS) it takes to complete 1 cycle. The x2 is there because the frequency is stored at half value (in a byte) to allow freqneucies up to 511Hz vvt_pwm_max_count = 1000000L / (2 * configPage6.vvtFreq * 2); //Converts the frequency in Hz to the number of ticks (at 2uS) it takes to complete 1 cycle + //Need to be initialised last due to instant interrupt + Timer1.setMode(2, TIMER_OUTPUT_COMPARE); + Timer1.setMode(3, TIMER_OUTPUT_COMPARE); + if(boost_pwm_max_count > 0) { Timer1.attachInterrupt(2, boostInterrupt);} + if(vvt_pwm_max_count > 0) { Timer1.attachInterrupt(3, vvtInterrupt);} + Timer1.resume(); + /* *********************************************************************************************************** * Schedules