2019-01-19 19:24:00 -08:00
# ifndef STM32_H
# define STM32_H
2019-02-22 07:39:07 -08:00
# if defined(CORE_STM32) && !defined(ARDUINO_BLACK_F407VE)
2019-02-19 14:28:13 -08:00
# if defined(STM32F4)
//These should really be in the stm32GENERIC libs, but for somereason they only have timers 1-4
// #include <stm32_TIM_variant_11.h>
// #include "src/HardwareTimers/HardwareTimer.h"
// HardwareTimer Timer5(TIM5, chip_tim5, sizeof(chip_tim5) / sizeof(chip_tim5[0]));
// HardwareTimer Timer8(TIM8, chip_tim8, sizeof(chip_tim8) / sizeof(chip_tim8[0]));
# else
# include "HardwareTimer.h"
# endif
2019-01-19 19:24:00 -08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* General
*/
# define PORT_TYPE uint8_t
2019-01-22 15:04:54 -08:00
# define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()
2019-02-19 14:28:13 -08:00
2019-01-22 15:04:54 -08:00
# define USE_SERIAL3
2019-01-19 19:24:00 -08:00
void initBoard ( ) ;
2019-01-21 13:56:25 -08:00
uint16_t freeRam ( ) ;
2019-02-20 06:47:48 -08:00
// extern void oneMSIntervalIRQ(stimer_t *Timer);
2019-02-19 14:28:13 -08:00
extern void EmptyIRQCallback ( stimer_t * Timer , uint32_t channel ) ;
2019-01-25 23:34:20 -08:00
# if defined(USE_STM32GENERIC)
# define Serial Serial1
# endif
2019-02-20 06:47:48 -08:00
/*
2019-01-19 19:24:00 -08:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Schedules
*/
2019-02-21 13:44:06 -08:00
# define MAX_TIMER_PERIOD 65535 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS)
# define MAX_TIMER_PERIOD_SLOW 65535 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS)
# define uS_TO_TIMER_COMPARE(uS) (uS ) //Converts a given number of uS into the required number of timer ticks until that time has passed.
# define uS_TO_TIMER_COMPARE_SLOW(uS) (uS ) //Converts a given number of uS into the required number of timer ticks until that time has passed.
# define FUEL1_COUNTER (TIM3)->CNT
# define FUEL2_COUNTER (TIM3)->CNT
# define FUEL3_COUNTER (TIM3)->CNT
# define FUEL4_COUNTER (TIM3)->CNT
# define FUEL1_COMPARE (TIM3)->CCR1
# define FUEL2_COMPARE (TIM3)->CCR2
# define FUEL3_COMPARE (TIM3)->CCR3
# define FUEL4_COMPARE (TIM3)->CCR4
# define IGN1_COUNTER (TIM2)->CNT
# define IGN2_COUNTER (TIM2)->CNT
# define IGN3_COUNTER (TIM2)->CNT
# define IGN4_COUNTER (TIM2)->CNT
# define IGN1_COMPARE (TIM2)->CCR1
# define IGN2_COMPARE (TIM2)->CCR2
# define IGN3_COMPARE (TIM2)->CCR3
# define IGN4_COMPARE (TIM2)->CCR4
2019-01-19 19:57:16 -08:00
# ifndef SMALL_FLASH_MODE
# define FUEL5_COUNTER (TIM5)->CNT
# define FUEL6_COUNTER (TIM5)->CNT
# define FUEL7_COUNTER (TIM5)->CNT
# define FUEL8_COUNTER (TIM5)->CNT
# define FUEL5_COMPARE (TIM5)->CCR1
# define FUEL6_COMPARE (TIM5)->CCR2
# define FUEL7_COMPARE (TIM5)->CCR3
# define FUEL8_COMPARE (TIM5)->CCR4
# define IGN5_COUNTER (TIM4)->CNT
# define IGN6_COUNTER (TIM4)->CNT
# define IGN7_COUNTER (TIM4)->CNT
# define IGN8_COUNTER (TIM4)->CNT
# define IGN5_COMPARE (TIM4)->CCR1
# define IGN6_COMPARE (TIM4)->CCR2
# define IGN7_COMPARE (TIM4)->CCR3
# define IGN8_COMPARE (TIM4)->CCR4
2019-02-21 13:44:06 -08:00
# endif
2019-01-19 19:57:16 -08:00
//https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
2019-02-21 13:44:06 -08:00
# define FUEL1_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC1E
# define FUEL2_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC2E
# define FUEL3_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC3E
# define FUEL4_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC4E
# define FUEL1_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC1E
# define FUEL2_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC2E
# define FUEL3_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC3E
# define FUEL4_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC4E
# define IGN1_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC1E
# define IGN2_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC2E
# define IGN3_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC3E
# define IGN4_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC4E
# define IGN1_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC1E
# define IGN2_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC2E
# define IGN3_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC3E
# define IGN4_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC4E
2019-01-19 19:57:16 -08:00
# ifndef SMALL_FLASH_MODE
# define FUEL5_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC1E
# define FUEL6_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC2E
# define FUEL7_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC3E
# define FUEL8_TIMER_ENABLE() (TIM5)->CCER |= TIM_CCER_CC4E
# define FUEL5_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC1E
# define FUEL6_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC2E
# define FUEL7_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC3E
# define FUEL8_TIMER_DISABLE() (TIM5)->CCER &= ~TIM_CCER_CC4E
# define IGN5_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC1E
# define IGN6_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC2E
# define IGN7_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC3E
# define IGN8_TIMER_ENABLE() (TIM4)->CCER |= TIM_CCER_CC4E
# define IGN5_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC1E
# define IGN6_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC2E
# define IGN7_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC3E
# define IGN8_TIMER_DISABLE() (TIM4)->CCER &= ~TIM_CCER_CC4E
# endif
2019-02-21 13:44:06 -08:00
2019-01-19 19:57:16 -08:00
2019-01-19 19:24:00 -08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Auxilliaries
*/
2019-01-19 19:57:16 -08:00
# if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core
# define ENABLE_BOOST_TIMER() (TIM1)->CCER |= TIM_CCER_CC2E
# define DISABLE_BOOST_TIMER() (TIM1)->CCER &= ~TIM_CCER_CC2E
# define ENABLE_VVT_TIMER() (TIM1)->CCER |= TIM_CCER_CC3E
# define DISABLE_VVT_TIMER() (TIM1)->CCER &= ~TIM_CCER_CC3E
# define BOOST_TIMER_COMPARE (TIM1)->CCR2
# define BOOST_TIMER_COUNTER (TIM1)->CNT
# define VVT_TIMER_COMPARE (TIM1)->CCR3
# define VVT_TIMER_COUNTER (TIM1)->CNT
# else //libmaple core aka STM32DUINO
# define ENABLE_BOOST_TIMER() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC2E
# define DISABLE_BOOST_TIMER() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC2E
# define ENABLE_VVT_TIMER() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC3E
# define DISABLE_VVT_TIMER() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC3E
# define BOOST_TIMER_COMPARE (TIMER1->regs).gen->CCR2
# define BOOST_TIMER_COUNTER (TIMER1->regs).gen->CNT
# define VVT_TIMER_COMPARE (TIMER1->regs).gen->CCR3
# define VVT_TIMER_COUNTER (TIMER1->regs).gen->CNT
# endif
2019-01-19 19:24:00 -08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Idle
*/
2019-01-19 19:57:16 -08:00
# if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core
# define IDLE_COUNTER (TIM1)->CNT
# define IDLE_COMPARE (TIM1)->CCR4
# define IDLE_TIMER_ENABLE() (TIM1)->CCER |= TIM_CCER_CC4E
# define IDLE_TIMER_DISABLE() (TIM1)->CCER &= ~TIM_CCER_CC4E
# else //libmaple core aka STM32DUINO
# define IDLE_COUNTER (TIMER1->regs).gen->CNT
# define IDLE_COMPARE (TIMER1->regs).gen->CCR4
# define IDLE_TIMER_ENABLE() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC4E
# define IDLE_TIMER_DISABLE() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC4E
# endif
2019-01-19 19:24:00 -08:00
2019-01-25 23:34:20 -08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Timers
*/
2019-01-19 19:24:00 -08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* CAN / Second serial
*/
# endif //CORE_STM32
2019-02-19 14:28:13 -08:00
# endif //STM32_H