STM32F4xx modifications for HAL_STM32 (#12080)
This commit is contained in:
parent
bf0c809ff2
commit
8b5e51c9aa
|
@ -67,7 +67,7 @@ uint8_t HAL_get_reset_source(void) {
|
|||
|
||||
void watchdog_reset() {
|
||||
WDT_Feed();
|
||||
#if PIN_EXISTS(LED)
|
||||
#if !defined(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
||||
TOGGLE(LED_PIN); // heart beat indicator
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
|||
TimerHandle[timer_num].timer = STEP_TIMER_DEV;
|
||||
TimerHandle[timer_num].irqHandle = Step_Handler;
|
||||
TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
|
||||
HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, 6, 0);
|
||||
HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0);
|
||||
break;
|
||||
|
||||
case TEMP_TIMER_NUM:
|
||||
|
@ -87,7 +87,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
|||
TimerHandle[timer_num].timer = TEMP_TIMER_DEV;
|
||||
TimerHandle[timer_num].irqHandle = Temp_Handler;
|
||||
TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
|
||||
HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, 2, 0);
|
||||
HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0);
|
||||
break;
|
||||
}
|
||||
timers_initialised[timer_num] = true;
|
||||
|
|
|
@ -34,40 +34,64 @@
|
|||
#define FORCE_INLINE __attribute__((always_inline)) inline
|
||||
|
||||
#define hal_timer_t uint32_t
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFF
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit
|
||||
|
||||
#ifdef STM32F0xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()) // frequency of timer peripherals
|
||||
#define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 16
|
||||
#define TEMP_TIMER 17
|
||||
#ifndef STEP_TIMER
|
||||
#define STEP_TIMER 16
|
||||
#endif
|
||||
|
||||
#ifndef TEMP_TIMER
|
||||
#define TEMP_TIMER 17
|
||||
#endif
|
||||
|
||||
#elif defined STM32F1xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
|
||||
#define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 4
|
||||
#define TEMP_TIMER 2
|
||||
#ifndef STEP_TIMER
|
||||
#define STEP_TIMER 4
|
||||
#endif
|
||||
|
||||
#ifndef TEMP_TIMER
|
||||
#define TEMP_TIMER 2
|
||||
#endif
|
||||
|
||||
#elif defined STM32F4xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
|
||||
#define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 4
|
||||
#define TEMP_TIMER 5
|
||||
#ifndef STEP_TIMER
|
||||
#define STEP_TIMER 5
|
||||
#endif
|
||||
|
||||
#ifndef TEMP_TIMER
|
||||
#define TEMP_TIMER 7
|
||||
#endif
|
||||
|
||||
#elif defined STM32F7xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()/2) // frequency of timer peripherals
|
||||
#define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 5
|
||||
#define TEMP_TIMER 7
|
||||
|
||||
#if MB(REMRAM_V1)
|
||||
#define STEP_TIMER 2
|
||||
#ifndef STEP_TIMER
|
||||
#define STEP_TIMER 5
|
||||
#endif
|
||||
|
||||
#ifndef TEMP_TIMER
|
||||
#define TEMP_TIMER 7
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef STEP_TIMER_IRQ_PRIO
|
||||
#define STEP_TIMER_IRQ_PRIO 1
|
||||
#endif
|
||||
|
||||
#ifndef TEMP_TIMER_IRQ_PRIO
|
||||
#define TEMP_TIMER_IRQ_PRIO 2
|
||||
#endif
|
||||
|
||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
|
||||
|
@ -110,9 +134,6 @@
|
|||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||
|
||||
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
|
||||
#define TEMP_ISR_ENABLED() HAL_timer_interrupt_enabled(TEMP_TIMER_NUM)
|
||||
|
||||
extern void Step_Handler(stimer_t *htim);
|
||||
extern void Temp_Handler(stimer_t *htim);
|
||||
#define HAL_STEP_TIMER_ISR void Step_Handler(stimer_t *htim)
|
||||
|
@ -153,11 +174,5 @@ 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);
|
||||
}
|
||||
|
||||
#define HAL_timer_isr_prologue(TIMER_NUM)
|
||||
#define HAL_timer_isr_epilogue(TIMER_NUM)
|
||||
|
|
|
@ -52,6 +52,12 @@ void setup_endstop_interrupts(void) {
|
|||
#if HAS_Z2_MIN
|
||||
attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z3_MAX
|
||||
attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z3_MIN
|
||||
attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z_MIN_PROBE_PIN
|
||||
attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
|
|
|
@ -28,20 +28,20 @@
|
|||
|
||||
#include "../shared/persistent_store_api.h"
|
||||
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM) && DISABLED(SPI_EEPROM) && DISABLED(I2C_EEPROM)
|
||||
#include <EEPROM.h>
|
||||
static bool eeprom_data_written = false;
|
||||
#endif
|
||||
|
||||
bool PersistentStore::access_start() {
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM) && DISABLED(SPI_EEPROM) && DISABLED(I2C_EEPROM)
|
||||
eeprom_buffer_fill();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PersistentStore::access_finish() {
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM) && DISABLED(SPI_EEPROM) && DISABLED(I2C_EEPROM)
|
||||
if (eeprom_data_written) {
|
||||
eeprom_buffer_flush();
|
||||
eeprom_data_written = false;
|
||||
|
@ -54,8 +54,20 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
|||
while (size--) {
|
||||
uint8_t v = *value;
|
||||
|
||||
// Save to either program flash or Backup SRAM
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
// Save to either external EEPROM, program flash or Backup SRAM
|
||||
#if ENABLED(SPI_EEPROM) || ENABLED(I2C_EEPROM)
|
||||
// EEPROM has only ~100,000 write cycles,
|
||||
// so only write bytes that have changed!
|
||||
uint8_t * const p = (uint8_t * const)pos;
|
||||
if (v != eeprom_read_byte(p)) {
|
||||
eeprom_write_byte(p, v);
|
||||
if (eeprom_read_byte(p) != v) {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
eeprom_buffered_write_byte(pos, v);
|
||||
#else
|
||||
*(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
|
||||
|
@ -65,7 +77,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
|||
pos++;
|
||||
value++;
|
||||
};
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM) && DISABLED(SPI_EEPROM) && DISABLED(I2C_EEPROM)
|
||||
eeprom_data_written = true;
|
||||
#endif
|
||||
|
||||
|
@ -74,9 +86,11 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
|||
|
||||
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing) {
|
||||
do {
|
||||
// Read from either program flash or Backup SRAM
|
||||
// Read from either external EEPROM, program flash or Backup SRAM
|
||||
const uint8_t c = (
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
#if ENABLED(SPI_EEPROM) || ENABLED(I2C_EEPROM)
|
||||
eeprom_read_byte((uint8_t*)pos)
|
||||
#elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
eeprom_buffered_read_byte(pos)
|
||||
#else
|
||||
(*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)))
|
||||
|
@ -92,7 +106,9 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
|
|||
}
|
||||
|
||||
size_t PersistentStore::capacity() {
|
||||
#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
#if ENABLED(SPI_EEPROM) || ENABLED(I2C_EEPROM)
|
||||
return E2END + 1;
|
||||
#elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
|
||||
return E2END + 1;
|
||||
#else
|
||||
return 4096; // 4kB
|
||||
|
|
|
@ -31,7 +31,14 @@
|
|||
|
||||
void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout
|
||||
|
||||
void watchdog_reset() { IWatchdog.reload(); }
|
||||
void watchdog_reset()
|
||||
{
|
||||
IWatchdog.reload();
|
||||
|
||||
#if PIN_EXISTS(LED)
|
||||
TOGGLE(LED_PIN); // heart beat indicator
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // USE_WATCHDOG
|
||||
#endif // ARDUINO_ARCH_STM32
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "eeprom_emul.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
/**
|
||||
* Description: functions for I2C connected external EEPROM.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* Adapted to the STM32F4 HAL
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
|
@ -91,7 +91,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
|||
TimerHandle[timer_num].irqHandle = TC5_Handler;
|
||||
TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
|
||||
#endif
|
||||
HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 6, 0);
|
||||
HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 1, 0);
|
||||
break;
|
||||
|
||||
case TEMP_TIMER_NUM:
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
#include "../shared/persistent_store_api.h"
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F4xx))
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
|
|
|
@ -124,3 +124,9 @@
|
|||
#define BTN_EN1 54 // BTN_EN1
|
||||
#define BTN_EN2 55 // BTN_EN2
|
||||
#define BTN_ENC 47 // BTN_ENC
|
||||
|
||||
//
|
||||
// Timers
|
||||
//
|
||||
|
||||
#define STEP_TIMER 2
|
||||
|
|
Loading…
Reference in a new issue