Added possibility to use another library for STM32
This commit is contained in:
parent
fb3c345f23
commit
6d3439060d
|
@ -162,59 +162,103 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd
|
|||
#define uS_TO_TIMER_COMPARE_SLOW(uS) ((uS * 15) >> 5)
|
||||
|
||||
#elif defined(CORE_STM32)
|
||||
#include "HardwareTimer.h"
|
||||
//Placeholders ONLY!
|
||||
//https://visualgdb.com/tutorials/arm/stm32/timers/hal/
|
||||
//https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F4/cores/maple/libmaple/timer.h#L51
|
||||
#define MAX_TIMER_PERIOD 131070 //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 >> 1) //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 >> 1) //Converts a given number of uS into the required number of timer ticks until that time has passed.
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
#include "HardwareTimer.h"
|
||||
#define FUEL1_COUNTER (TIM2)->CNT
|
||||
#define FUEL2_COUNTER (TIM2)->CNT
|
||||
#define FUEL3_COUNTER (TIM2)->CNT
|
||||
#define FUEL4_COUNTER (TIM2)->CNT
|
||||
#define FUEL5_COUNTER (TIM2)->CNT
|
||||
|
||||
#define FUEL1_COUNTER (TIM2)->CNT
|
||||
#define FUEL2_COUNTER (TIM2)->CNT
|
||||
#define FUEL3_COUNTER (TIM2)->CNT
|
||||
#define FUEL4_COUNTER (TIM2)->CNT
|
||||
#define FUEL5_COUNTER (TIM2)->CNT
|
||||
#define IGN1_COUNTER (TIM3)->CNT
|
||||
#define IGN2_COUNTER (TIM3)->CNT
|
||||
#define IGN3_COUNTER (TIM3)->CNT
|
||||
#define IGN4_COUNTER (TIM3)->CNT
|
||||
#define IGN5_COUNTER (TIM3)->CNT
|
||||
|
||||
#define IGN1_COUNTER (TIM3)->CNT
|
||||
#define IGN2_COUNTER (TIM3)->CNT
|
||||
#define IGN3_COUNTER (TIM3)->CNT
|
||||
#define IGN4_COUNTER (TIM3)->CNT
|
||||
#define IGN5_COUNTER (TIM3)->CNT
|
||||
#define FUEL1_COMPARE (TIM2)->CCR1
|
||||
#define FUEL2_COMPARE (TIM2)->CCR2
|
||||
#define FUEL3_COMPARE (TIM2)->CCR3
|
||||
#define FUEL4_COMPARE (TIM2)->CCR4
|
||||
|
||||
#define FUEL1_COMPARE (TIM2)->CCR1
|
||||
#define FUEL2_COMPARE (TIM2)->CCR2
|
||||
#define FUEL3_COMPARE (TIM2)->CCR3
|
||||
#define FUEL4_COMPARE (TIM2)->CCR4
|
||||
#define IGN1_COMPARE (TIM3)->CCR1
|
||||
#define IGN2_COMPARE (TIM3)->CCR2
|
||||
#define IGN3_COMPARE (TIM3)->CCR3
|
||||
#define IGN4_COMPARE (TIM3)->CCR4
|
||||
#define IGN5_COMPARE (TIM3)->CCR1
|
||||
|
||||
#define IGN1_COMPARE (TIM3)->CCR1
|
||||
#define IGN2_COMPARE (TIM3)->CCR2
|
||||
#define IGN3_COMPARE (TIM3)->CCR3
|
||||
#define IGN4_COMPARE (TIM3)->CCR4
|
||||
#define IGN5_COMPARE (TIM3)->CCR1
|
||||
//https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
#define FUEL1_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC1E
|
||||
#define FUEL2_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC2E
|
||||
#define FUEL3_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC3E
|
||||
#define FUEL4_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC4E
|
||||
|
||||
//https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
#define FUEL1_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC1E
|
||||
#define FUEL2_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC2E
|
||||
#define FUEL3_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC3E
|
||||
#define FUEL4_TIMER_ENABLE() (TIM2)->CCER |= TIM_CCER_CC4E
|
||||
#define IGN1_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC1E
|
||||
#define IGN2_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC2E
|
||||
#define IGN3_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC3E
|
||||
#define IGN4_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC4E
|
||||
#define IGN5_TIMER_ENABLE() (TIM1)->CCER |= TIM_CCER_CC1E
|
||||
|
||||
#define IGN1_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC1E
|
||||
#define IGN2_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC2E
|
||||
#define IGN3_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC3E
|
||||
#define IGN4_TIMER_ENABLE() (TIM3)->CCER |= TIM_CCER_CC4E
|
||||
#define IGN5_TIMER_ENABLE() (TIM1)->CCER |= TIM_CCER_CC1E
|
||||
#define FUEL1_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC1E
|
||||
#define FUEL2_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC2E
|
||||
#define FUEL3_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC3E
|
||||
#define FUEL4_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC4E
|
||||
|
||||
#define FUEL1_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC1E
|
||||
#define FUEL2_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC2E
|
||||
#define FUEL3_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC3E
|
||||
#define FUEL4_TIMER_DISABLE() (TIM2)->CCER &= ~TIM_CCER_CC4E
|
||||
#define IGN1_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC1E
|
||||
#define IGN2_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC2E
|
||||
#define IGN3_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC3E
|
||||
#define IGN4_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC4E
|
||||
#define IGN5_TIMER_DISABLE() (TIM1)->CCER &= ~TIM_CCER_CC1E
|
||||
#else
|
||||
#define FUEL1_COUNTER (TIMER2->regs).gen->CNT
|
||||
#define FUEL2_COUNTER (TIMER2->regs).gen->CNT
|
||||
#define FUEL3_COUNTER (TIMER2->regs).gen->CNT
|
||||
#define FUEL4_COUNTER (TIMER2->regs).gen->CNT
|
||||
#define FUEL5_COUNTER (TIMER1->regs).gen->CNT
|
||||
|
||||
#define IGN1_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC1E
|
||||
#define IGN2_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC2E
|
||||
#define IGN3_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC3E
|
||||
#define IGN4_TIMER_DISABLE() (TIM3)->CCER &= ~TIM_CCER_CC4E
|
||||
#define IGN5_TIMER_DISABLE() (TIM1)->CCER &= ~TIM_CCER_CC1E
|
||||
#define IGN1_COUNTER (TIMER3->regs).gen->CNT
|
||||
#define IGN2_COUNTER (TIMER3->regs).gen->CNT
|
||||
#define IGN3_COUNTER (TIMER3->regs).gen->CNT
|
||||
#define IGN4_COUNTER (TIMER3->regs).gen->CNT
|
||||
#define IGN5_COUNTER (TIMER1->regs).gen->CNT
|
||||
|
||||
#define FUEL1_COMPARE (TIMER2->regs).gen->CCR1
|
||||
#define FUEL2_COMPARE (TIMER2->regs).gen->CCR2
|
||||
#define FUEL3_COMPARE (TIMER2->regs).gen->CCR3
|
||||
#define FUEL4_COMPARE (TIMER2->regs).gen->CCR4
|
||||
|
||||
#define IGN1_COMPARE (TIMER3->regs).gen->CCR1
|
||||
#define IGN2_COMPARE (TIMER3->regs).gen->CCR2
|
||||
#define IGN3_COMPARE (TIMER3->regs).gen->CCR3
|
||||
#define IGN4_COMPARE (TIMER3->regs).gen->CCR4
|
||||
#define IGN5_COMPARE (TIMER1->regs).gen->CCR1
|
||||
|
||||
//https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
#define FUEL1_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC1E
|
||||
#define FUEL2_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC2E
|
||||
#define FUEL3_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC3E
|
||||
#define FUEL4_TIMER_ENABLE() (TIMER2->regs).gen->CCER |= TIMER_CCER_CC4E
|
||||
|
||||
#define IGN1_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC1E
|
||||
#define IGN2_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC2E
|
||||
#define IGN3_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC3E
|
||||
#define IGN4_TIMER_ENABLE() (TIMER3->regs).gen->CCER |= TIMER_CCER_CC4E
|
||||
#define IGN5_TIMER_ENABLE() (TIMER1->regs).gen->CCER |= TIMER_CCER_CC1E
|
||||
|
||||
#define FUEL1_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC1E
|
||||
#define FUEL2_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC2E
|
||||
#define FUEL3_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC3E
|
||||
#define FUEL4_TIMER_DISABLE() (TIMER2->regs).gen->CCER &= ~TIMER_CCER_CC4E
|
||||
|
||||
#define IGN1_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC1E
|
||||
#define IGN2_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC2E
|
||||
#define IGN3_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC3E
|
||||
#define IGN4_TIMER_DISABLE() (TIMER3->regs).gen->CCER &= ~TIMER_CCER_CC4E
|
||||
#define IGN5_TIMER_DISABLE() (TIMER1->regs).gen->CCER &= ~TIMER_CCER_CC1E
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void initialiseSchedulers();
|
||||
|
@ -360,4 +404,4 @@ static inline unsigned int popQueue(volatile Schedule *queue[])
|
|||
}
|
||||
|
||||
|
||||
#endif // SCHEDULER_H
|
||||
#endif // SCHEDULER_H
|
||||
|
|
|
@ -161,22 +161,42 @@ void initialiseSchedulers()
|
|||
NVIC_ENABLE_IRQ(IRQ_FTM1);
|
||||
|
||||
#elif defined(CORE_STM32)
|
||||
//see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
Timer1.setPrescaleFactor(((Timer1.getBaseFrequency() / 1000000) << 1) -1); //2us resolution
|
||||
Timer2.setPrescaleFactor(((Timer2.getBaseFrequency() / 1000000) << 1) -1); //2us resolution
|
||||
Timer3.setPrescaleFactor(((Timer3.getBaseFrequency() / 1000000) << 1) -1); //2us resolution
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
//see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
Timer1.setPrescaleFactor(((Timer1.getBaseFrequency() / 1000000) << 1) -1); //2us resolution
|
||||
Timer2.setPrescaleFactor(((Timer2.getBaseFrequency() / 1000000) << 1) -1); //2us resolution
|
||||
Timer3.setPrescaleFactor(((Timer3.getBaseFrequency() / 1000000) << 1) -1); //2us resolution
|
||||
|
||||
Timer2.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(2, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(3, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(4, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(2, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(3, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(4, TIMER_OUTPUT_COMPARE);
|
||||
|
||||
Timer3.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(2, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(3, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(4, TIMER_OUTPUT_COMPARE);
|
||||
Timer1.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(2, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(3, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(4, TIMER_OUTPUT_COMPARE);
|
||||
Timer1.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
|
||||
#else
|
||||
//see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
(TIMER1->regs).bas->PSC = (CYCLES_PER_MICROSECOND << 1) - 1; //2us resolution
|
||||
(TIMER2->regs).bas->PSC = (CYCLES_PER_MICROSECOND << 1) - 1; //2us resolution
|
||||
(TIMER3->regs).bas->PSC = (CYCLES_PER_MICROSECOND << 1) - 1; //2us resolution
|
||||
// Alternative 2us resolution:
|
||||
//TimerX.setPrescaleFactor(CYCLES_PER_MICROSECOND * 2U);
|
||||
|
||||
Timer2.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(TIMER_CH3, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(TIMER_CH4, TIMER_OUTPUT_COMPARE);
|
||||
|
||||
Timer3.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(TIMER_CH3, TIMER_OUTPUT_COMPARE);
|
||||
Timer3.setMode(TIMER_CH4, TIMER_OUTPUT_COMPARE);
|
||||
|
||||
#endif
|
||||
Timer2.attachInterrupt(1, fuelSchedule1Interrupt);
|
||||
Timer2.attachInterrupt(2, fuelSchedule2Interrupt);
|
||||
Timer2.attachInterrupt(3, fuelSchedule3Interrupt);
|
||||
|
@ -790,4 +810,4 @@ void ftm0_isr(void)
|
|||
else if(interrupt8) { FTM0_C7SC &= ~FTM_CSC_CHF; ignitionSchedule4Interrupt(); }
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#define FastCRC_tables
|
||||
#include "inttypes.h"
|
||||
|
||||
#if defined(__AVR__) || defined(STM32_MCU_SERIES) || defined(_VARIANT_ARDUINO_STM32_)
|
||||
#if defined(__AVR__) || defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32)
|
||||
#include <avr/pgmspace.h>
|
||||
#else
|
||||
#include <pgmspace.h>
|
||||
|
|
Loading…
Reference in New Issue