Official STMicroelectronics Arduino Core STM32F4 HAL compatibility (#11006)

This commit is contained in:
Karl Andersson 2018-06-13 01:38:00 +02:00 committed by Scott Lahteine
parent 4dbec774b5
commit e0276d2f32
18 changed files with 176 additions and 138 deletions

View file

@ -54,6 +54,7 @@ static SPISettings spiConfig;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#if ENABLED(SOFTWARE_SPI) #if ENABLED(SOFTWARE_SPI)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Software SPI // Software SPI
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -95,14 +96,13 @@ void spiBegin() {
void spiInit(uint8_t spiRate) { void spiInit(uint8_t spiRate) {
uint8_t clock; uint8_t clock;
switch (spiRate) { switch (spiRate) {
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break; case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break;
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break; case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break;
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break; case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break; case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break; case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
default: default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
clock = SPI_CLOCK_DIV2; // Default from the SPI library
} }
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0); spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
SPI.begin(); SPI.begin();
@ -168,7 +168,6 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
/** Begin SPI transaction, set clock, bit order, data mode */ /** Begin SPI transaction, set clock, bit order, data mode */
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) { void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode); spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
} }

View file

@ -47,7 +47,7 @@
/** @addtogroup EEPROM_Emulation /** @addtogroup EEPROM_Emulation
* @{ * @{
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "eeprom_emul.h" #include "eeprom_emul.h"
@ -562,7 +562,7 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
return FlashStatus; return FlashStatus;
} }
#endif // STM32F4 #endif // STM32F4 || STM32F4xx
/** /**
* @} * @}

View file

@ -17,7 +17,7 @@
* *
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
/** /**
* Description: functions for I2C connected external EEPROM. * Description: functions for I2C connected external EEPROM.
@ -139,5 +139,5 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n) {
} }
#endif // ENABLED(EEPROM_SETTINGS) && DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM) #endif // ENABLED(EEPROM_SETTINGS) && DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -21,8 +21,7 @@
* *
*/ */
#if defined(STM32F4) || defined(STM32F4xx)
#ifdef STM32F4
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Includes // Includes
@ -81,17 +80,11 @@ void sei(void) { interrupts(); }
void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); } void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
uint8_t HAL_get_reset_source (void) { uint8_t HAL_get_reset_source (void) {
if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
return RST_WATCHDOG;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) return RST_SOFTWARE;
return RST_SOFTWARE; if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET) return RST_EXTERNAL;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET) return RST_POWER_ON;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
return RST_EXTERNAL;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
return RST_POWER_ON;
return 0; return 0;
} }
@ -137,4 +130,4 @@ uint16_t HAL_adc_get_result(void) {
return HAL_adc_result; return HAL_adc_result;
} }
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -21,8 +21,6 @@
* *
*/ */
#ifndef _HAL_STM32F4_H #ifndef _HAL_STM32F4_H
#define _HAL_STM32F4_H #define _HAL_STM32F4_H
@ -41,6 +39,10 @@
#include "Arduino.h" #include "Arduino.h"
#ifdef USBCON
#include <USBSerial.h>
#endif
#include "../math_32bit.h" #include "../math_32bit.h"
#include "../HAL_SPI.h" #include "../HAL_SPI.h"
#include "fastio_STM32F4.h" #include "fastio_STM32F4.h"
@ -48,7 +50,6 @@
#include "HAL_timers_STM32F4.h" #include "HAL_timers_STM32F4.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Defines // Defines
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -186,6 +187,7 @@ extern "C" {
*/ */
extern "C" char* _sbrk(int incr); extern "C" char* _sbrk(int incr);
/* /*
static int freeMemory() { static int freeMemory() {
volatile int top; volatile int top;
@ -193,6 +195,7 @@ static int freeMemory() {
return top; return top;
} }
*/ */
static int freeMemory() { static int freeMemory() {
volatile char top; volatile char top;
return &top - reinterpret_cast<char*>(_sbrk(0)); return &top - reinterpret_cast<char*>(_sbrk(0));

View file

@ -21,7 +21,7 @@
* *
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
@ -50,4 +50,4 @@ void libServo::move(const int value) {
} }
#endif // HAS_SERVOS #endif // HAS_SERVOS
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -30,7 +30,7 @@
* Adapted to the STM32F4 HAL * Adapted to the STM32F4 HAL
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Includes // Includes
@ -54,6 +54,7 @@ static SPISettings spiConfig;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#if ENABLED(SOFTWARE_SPI) #if ENABLED(SOFTWARE_SPI)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Software SPI // Software SPI
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -81,8 +82,7 @@ void spiBegin(void) {
#error SS_PIN not defined! #error SS_PIN not defined!
#endif #endif
SET_OUTPUT(SS_PIN); OUT_WRITE(SS_PIN, HIGH);
WRITE(SS_PIN, HIGH);
} }
/** Configure SPI for specified SPI speed */ /** Configure SPI for specified SPI speed */
@ -90,14 +90,13 @@ void spiInit(uint8_t spiRate) {
// Use datarates Marlin uses // Use datarates Marlin uses
uint32_t clock; uint32_t clock;
switch (spiRate) { switch (spiRate) {
case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000 case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000
case SPI_HALF_SPEED: clock = 5000000; break; case SPI_HALF_SPEED: clock = 5000000; break;
case SPI_QUARTER_SPEED: clock = 2500000; break; case SPI_QUARTER_SPEED: clock = 2500000; break;
case SPI_EIGHTH_SPEED: clock = 1250000; break; case SPI_EIGHTH_SPEED: clock = 1250000; break;
case SPI_SPEED_5: clock = 625000; break; case SPI_SPEED_5: clock = 625000; break;
case SPI_SPEED_6: clock = 300000; break; case SPI_SPEED_6: clock = 300000; break;
default: default: clock = 4000000; // Default from the SPI libarary
clock = 4000000; // Default from the SPI libarary
} }
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0); spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
SPI.begin(); SPI.begin();
@ -128,7 +127,13 @@ uint8_t spiRec(void) {
*/ */
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t* buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
#ifdef STM32GENERIC
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
#else
SPI.transfer((uint8_t*)buf, nbyte);
#endif
SPI.endTransaction(); SPI.endTransaction();
} }
@ -156,10 +161,16 @@ void spiSend(uint8_t b) {
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.transfer(token); SPI.transfer(token);
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
#ifdef STM32GENERIC
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
#else
SPI.transfer((uint8_t*)buf, (uint8_t*)0, 512);
#endif
SPI.endTransaction(); SPI.endTransaction();
} }
#endif // SOFTWARE_SPI #endif // SOFTWARE_SPI
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -20,7 +20,7 @@
* *
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Includes // Includes
@ -39,6 +39,8 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define NUM_HARDWARE_TIMERS 2 #define NUM_HARDWARE_TIMERS 2
#define STEP_TIMER_IRQ_ID TIM5_IRQn
#define TEMP_TIMER_IRQ_ID TIM7_IRQn
//#define PRESCALER 1 //#define PRESCALER 1
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -53,7 +55,7 @@
// Private Variables // Private Variables
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
tTimerConfig timerConfig[NUM_HARDWARE_TIMERS]; stm32f4_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Function prototypes // Function prototypes
@ -72,90 +74,86 @@ bool timers_initialised[NUM_HARDWARE_TIMERS] = {false};
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
if (!timers_initialised[timer_num]) { if (!timers_initialised[timer_num]) {
constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
temp_prescaler = TEMP_TIMER_PRESCALE - 1;
switch (timer_num) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:
//STEPPER TIMER TIM5 //use a 32bit timer // STEPPER TIMER TIM5 - use a 32bit timer
__HAL_RCC_TIM5_CLK_ENABLE(); #ifdef STM32GENERIC
timerConfig[0].timerdef.Instance = TIM5; __HAL_RCC_TIM5_CLK_ENABLE();
timerConfig[0].timerdef.Init.Prescaler = (STEPPER_TIMER_PRESCALE); TimerHandle[timer_num].handle.Instance = TIM5;
timerConfig[0].timerdef.Init.CounterMode = TIM_COUNTERMODE_UP; TimerHandle[timer_num].handle.Init.Prescaler = step_prescaler;
timerConfig[0].timerdef.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; TimerHandle[timer_num].handle.Init.CounterMode = TIM_COUNTERMODE_UP;
timerConfig[0].IRQ_Id = TIM5_IRQn; TimerHandle[timer_num].handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
timerConfig[0].callback = (uint32_t)TC5_Handler; TimerHandle[timer_num].callback = (uint32_t)TC5_Handler;
HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0); #else
break; TimerHandle[timer_num].timer = TIM5;
case TEMP_TIMER_NUM: TimerHandle[timer_num].irqHandle = TC5_Handler;
//TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM) TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
__HAL_RCC_TIM7_CLK_ENABLE(); #endif
timerConfig[1].timerdef.Instance = TIM7; HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 6, 0);
timerConfig[1].timerdef.Init.Prescaler = (TEMP_TIMER_PRESCALE); break;
timerConfig[1].timerdef.Init.CounterMode = TIM_COUNTERMODE_UP;
timerConfig[1].timerdef.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; case TEMP_TIMER_NUM:
timerConfig[1].IRQ_Id = TIM7_IRQn; // TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM)
timerConfig[1].callback = (uint32_t)TC7_Handler; #ifdef STM32GENERIC
HAL_NVIC_SetPriority(timerConfig[1].IRQ_Id, 2, 0); __HAL_RCC_TIM7_CLK_ENABLE();
break; TimerHandle[timer_num].handle.Instance = TIM7;
TimerHandle[timer_num].handle.Init.Prescaler = temp_prescaler;
TimerHandle[timer_num].handle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimerHandle[timer_num].handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
TimerHandle[timer_num].callback = (uint32_t)TC7_Handler;
#else
TimerHandle[timer_num].timer = TIM7;
TimerHandle[timer_num].irqHandle = TC7_Handler;
TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
#endif
HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0);
break;
} }
timers_initialised[timer_num] = true; timers_initialised[timer_num] = true;
} }
timerConfig[timer_num].timerdef.Init.Period = (((HAL_TIMER_RATE) / timerConfig[timer_num].timerdef.Init.Prescaler) / frequency) - 1; #ifdef STM32GENERIC
TimerHandle[timer_num].handle.Init.Period = (((HAL_TIMER_RATE) / TimerHandle[timer_num].handle.Init.Prescaler) / frequency) - 1;
if (HAL_TIM_Base_Init(&timerConfig[timer_num].timerdef) == HAL_OK) if (HAL_TIM_Base_Init(&TimerHandle[timer_num].handle) == HAL_OK)
HAL_TIM_Base_Start_IT(&timerConfig[timer_num].timerdef); HAL_TIM_Base_Start_IT(&TimerHandle[timer_num].handle);
#endif
} }
//forward the interrupt #ifdef STM32GENERIC
extern "C" void TIM5_IRQHandler() { extern "C" void TIM5_IRQHandler() {
((void(*)(void))timerConfig[0].callback)(); ((void(*)(void))TimerHandle[0].callback)();
} }
extern "C" void TIM7_IRQHandler() { extern "C" void TIM7_IRQHandler() {
((void(*)(void))timerConfig[1].callback)(); ((void(*)(void))TimerHandle[1].callback)();
} }
#endif
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
__HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, compare);
}
void HAL_timer_enable_interrupt(const uint8_t timer_num) { void HAL_timer_enable_interrupt(const uint8_t timer_num) {
HAL_NVIC_EnableIRQ(timerConfig[timer_num].IRQ_Id); switch (timer_num) {
case STEP_TIMER_NUM: HAL_NVIC_EnableIRQ(STEP_TIMER_IRQ_ID); break;
case TEMP_TIMER_NUM: HAL_NVIC_EnableIRQ(TEMP_TIMER_IRQ_ID); break;
}
} }
void HAL_timer_disable_interrupt(const uint8_t timer_num) { void HAL_timer_disable_interrupt(const uint8_t timer_num) {
HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id); switch (timer_num) {
case STEP_TIMER_NUM: HAL_NVIC_DisableIRQ(STEP_TIMER_IRQ_ID); break;
case TEMP_TIMER_NUM: HAL_NVIC_DisableIRQ(TEMP_TIMER_IRQ_ID); break;
}
// We NEED memory barriers to ensure Interrupts are actually disabled! // We NEED memory barriers to ensure Interrupts are actually disabled!
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
__DSB(); __DSB();
__ISB(); __ISB();
} }
hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
}
uint32_t HAL_timer_get_count(const uint8_t timer_num) {
return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
}
void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
}
void HAL_timer_isr_prologue(const uint8_t timer_num) {
if (__HAL_TIM_GET_FLAG(&timerConfig[timer_num].timerdef, TIM_FLAG_UPDATE) == SET) {
__HAL_TIM_CLEAR_FLAG(&timerConfig[timer_num].timerdef, TIM_FLAG_UPDATE);
}
}
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
if (NVIC->ISER[(uint32_t)((int32_t)timerConfig[timer_num].IRQ_Id) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)timerConfig[timer_num].IRQ_Id) & (uint32_t)0x1F))) { switch (timer_num) {
return true; case STEP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)STEP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)STEP_TIMER_IRQ_ID) & (uint32_t)0x1F));
} case TEMP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) & (uint32_t)0x1F));
else {
return false;
} }
return false;
} }
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -63,27 +63,38 @@
// TODO change this // TODO change this
#ifdef STM32GENERIC
extern void TC5_Handler();
extern void TC7_Handler();
#define HAL_STEP_TIMER_ISR void TC5_Handler()
#define HAL_TEMP_TIMER_ISR void TC7_Handler()
#else
extern void TC5_Handler(stimer_t *htim);
extern void TC7_Handler(stimer_t *htim);
#define HAL_STEP_TIMER_ISR void TC5_Handler(stimer_t *htim)
#define HAL_TEMP_TIMER_ISR void TC7_Handler(stimer_t *htim)
#endif
extern void TC5_Handler();
extern void TC7_Handler();
#define HAL_STEP_TIMER_ISR void TC5_Handler()
#define HAL_TEMP_TIMER_ISR void TC7_Handler()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Types // Types
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
typedef struct { #ifdef STM32GENERIC
TIM_HandleTypeDef timerdef; typedef struct {
IRQn_Type IRQ_Id; TIM_HandleTypeDef handle;
uint32_t callback; uint32_t callback;
} tTimerConfig; } tTimerConfig;
typedef tTimerConfig stm32f4_timer_t;
#else
typedef stimer_t stm32f4_timer_t;
#endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Public Variables // Public Variables
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
//extern const tTimerConfig timerConfig[]; extern stm32f4_timer_t TimerHandle[];
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Public functions // Public functions
@ -94,12 +105,35 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num);
void HAL_timer_disable_interrupt(const uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num);
bool HAL_timer_interrupt_enabled(const uint8_t timer_num); bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare); FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) {
hal_timer_t HAL_timer_get_compare(const uint8_t timer_num); return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle);
uint32_t HAL_timer_get_count(const uint8_t timer_num); }
void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks);
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
__HAL_TIM_SET_AUTORELOAD(&TimerHandle[timer_num].handle, compare);
if (HAL_timer_get_count(timer_num) >= compare)
TimerHandle[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt
}
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
return __HAL_TIM_GET_AUTORELOAD(&TimerHandle[timer_num].handle);
}
FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
if (HAL_timer_get_compare(timer_num) < mincmp)
HAL_timer_set_compare(timer_num, mincmp);
}
#ifdef STM32GENERIC
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
if (__HAL_TIM_GET_FLAG(&TimerHandle[timer_num].handle, TIM_FLAG_UPDATE) == SET)
__HAL_TIM_CLEAR_FLAG(&TimerHandle[timer_num].handle, TIM_FLAG_UPDATE);
}
#else
#define HAL_timer_isr_prologue(TIMER_NUM)
#endif
void HAL_timer_isr_prologue(const uint8_t timer_num);
#define HAL_timer_isr_epilogue(TIMER_NUM) #define HAL_timer_isr_epilogue(TIMER_NUM)
#endif // _HAL_TIMERS_STM32F4_H #endif // _HAL_TIMERS_STM32F4_H

View file

@ -21,7 +21,7 @@
* *
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
#include "../persistent_store_api.h" #include "../persistent_store_api.h"
@ -72,4 +72,4 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
} // HAL } // HAL
#endif // EEPROM_SETTINGS #endif // EEPROM_SETTINGS
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -20,7 +20,7 @@
* *
*/ */
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
@ -54,4 +54,4 @@
#endif // USE_WATCHDOG #endif // USE_WATCHDOG
#endif // STM32F4 #endif // STM32F4 || STM32F4xx

View file

@ -62,7 +62,7 @@
#define END_FLASH_ADDR 0x00080000 #define END_FLASH_ADDR 0x00080000
#endif #endif
#ifdef STM32F4 #if defined(STM32F4) || defined(STM32F4xx)
// For STM32F407VET // For STM32F407VET
// SRAM (0x20000000 - 0x20030000) (192kb) // SRAM (0x20000000 - 0x20030000) (192kb)
// FLASH (0x08000000 - 0x08080000) (512kb) // FLASH (0x08000000 - 0x08080000) (512kb)

View file

@ -13,7 +13,7 @@
#define HAL_PLATFORM HAL_LPC1768 #define HAL_PLATFORM HAL_LPC1768
#elif defined(__STM32F1__) || defined(TARGET_STM32F1) #elif defined(__STM32F1__) || defined(TARGET_STM32F1)
#define HAL_PLATFORM HAL_STM32F1 #define HAL_PLATFORM HAL_STM32F1
#elif defined(STM32F4) #elif defined(STM32F4) || defined(STM32F4xx)
#define HAL_PLATFORM HAL_STM32F4 #define HAL_PLATFORM HAL_STM32F4
#elif defined(STM32F7) #elif defined(STM32F7)
#define HAL_PLATFORM HAL_STM32F7 #define HAL_PLATFORM HAL_STM32F7

View file

@ -53,7 +53,7 @@
#include "../inc/MarlinConfig.h" #include "../inc/MarlinConfig.h"
#if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768) || defined(STM32F4)) #if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768) || defined(STM32F4) || defined(STM32F4xx))
//#include <Arduino.h> //#include <Arduino.h>
#include "servo.h" #include "servo.h"

View file

@ -74,7 +74,7 @@
#elif defined(TARGET_LPC1768) #elif defined(TARGET_LPC1768)
#include "HAL_LPC1768/LPC1768_Servo.h" #include "HAL_LPC1768/LPC1768_Servo.h"
#elif defined(STM32F4) #elif defined(STM32F4) || defined(STM32F4xx)
#include "HAL_STM32F4/HAL_Servo_STM32F4.h" #include "HAL_STM32F4/HAL_Servo_STM32F4.h"
#else #else
#include <stdint.h> #include <stdint.h>

View file

@ -181,7 +181,7 @@ void GcodeSuite::G28(const bool always_home_all) {
#endif #endif
return; return;
} }
// Wait for planner moves to finish! // Wait for planner moves to finish!
planner.synchronize(); planner.synchronize();

View file

@ -20,7 +20,7 @@
* *
*/ */
#if !defined(STM32F4) #if !defined(STM32F4) && !defined(STM32F4xx)
#error "Oops! Make sure you have an STM32F4 board selected from the 'Tools -> Boards' menu." #error "Oops! Make sure you have an STM32F4 board selected from the 'Tools -> Boards' menu."
#endif #endif

View file

@ -265,7 +265,7 @@ monitor_speed = 250000
platform = ststm32 platform = ststm32
framework = arduino framework = arduino
board = disco_f407vg board = disco_f407vg
build_flags = ${common.build_flags} -DUSE_STM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB build_flags = ${common.build_flags} -DUSE_STM32GENERIC -DSTM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
lib_ignore = Adafruit NeoPixel, c1921b4, TMC2130Stepper lib_ignore = Adafruit NeoPixel, c1921b4, TMC2130Stepper
src_filter = ${common.default_src_filter} src_filter = ${common.default_src_filter}