From f70374bb0fb0afbddc2e569e33440e6941a10d33 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Thu, 24 Oct 2019 12:04:09 +0200 Subject: [PATCH 01/23] STM32 update to HardwareTimer 1.7.0 --- .travis.yml | 13 +- Marlin/src/HAL/HAL_ESP32/timers.h | 4 +- Marlin/src/HAL/HAL_SAMD51/timers.cpp | 2 +- Marlin/src/HAL/HAL_STM32/timers.cpp | 89 +++++--- Marlin/src/HAL/HAL_STM32/timers.h | 70 +++--- Marlin/src/HAL/HAL_STM32F1/timers.cpp | 4 +- Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h | 7 +- .../HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp | 117 ---------- .../src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h | 126 ----------- .../HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp | 131 ----------- .../src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h | 97 --------- Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp | 92 ++++++++ Marlin/src/HAL/HAL_STM32_F4_F7/timers.h | 136 +++++++++++- Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp | 4 +- Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp | 4 +- Marlin/src/module/stepper.cpp | 2 +- Marlin/src/module/temperature.cpp | 16 +- Marlin/src/module/temperature.h | 10 +- .../PlatformIO/scripts/black_stm32f407vet6.py | 29 --- .../PeripheralPins.c | 70 +++--- .../BIGTREE_GENERIC_STM32F407_5X/ldscript.ld | 3 - .../BIGTREE_GENERIC_STM32F407_5X/variant.h | 18 +- .../variants/MARLIN_F407VE/PeripheralPins.c | 204 ++++++++++-------- ...stm32f4xx_hal_conf.h => hal_conf_custom.h} | 109 ++++++---- .../variants/MARLIN_F407VE/ldscript.ld | 52 +++-- .../variants/MARLIN_F407VE/variant.cpp | 84 +++++++- .../variants/MARLIN_F407VE/variant.h | 150 ++++++++++++- platformio.ini | 96 +++++---- 28 files changed, 868 insertions(+), 871 deletions(-) delete mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp delete mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h delete mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp delete mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h create mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp delete mode 100644 buildroot/share/PlatformIO/scripts/black_stm32f407vet6.py rename buildroot/share/PlatformIO/variants/MARLIN_F407VE/{stm32f4xx_hal_conf.h => hal_conf_custom.h} (83%) diff --git a/.travis.yml b/.travis.yml index b747ffe331ea..da11e0a53e58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,17 +25,17 @@ env: - TEST_PLATFORM="sanguino_atmega1284p" - TEST_PLATFORM="sanguino_atmega644p" - # Broken Extended STM32 Environments - #- TEST_PLATFORM="ARMED" - #- TEST_PLATFORM="BIGTREE_BTT002" - #- TEST_PLATFORM="BIGTREE_SKR_PRO" - # Extended STM32 Environments - TEST_PLATFORM="STM32F103RC_bigtree" + - TEST_PLATFORM="STM32F103RC_bigtree_USB" + - TEST_PLATFORM="STM32F103RC_fysetc" - TEST_PLATFORM="jgaurora_a5s_a1" - TEST_PLATFORM="STM32F103VE_longer" - TEST_PLATFORM="STM32F407VE_black" + - TEST_PLATFORM="BIGTREE_BTT002" + - TEST_PLATFORM="BIGTREE_SKR_PRO" - TEST_PLATFORM="mks_robin" + - TEST_PLATFORM="ARMED" # Put lengthy tests last - TEST_PLATFORM="LPC1768" @@ -49,9 +49,6 @@ env: #- TEST_PLATFORM="mks_robin_mini" #- TEST_PLATFORM="mks_robin_nano" #- TEST_PLATFORM="SAMD51_grandcentral_m4" - #- TEST_PLATFORM="STM32F103RC_bigtree" - #- TEST_PLATFORM="STM32F103RC_bigtree_USB" - #- TEST_PLATFORM="STM32F103RC_fysetc" #- TEST_PLATFORM="STM32F4" #- TEST_PLATFORM="STM32F7" diff --git a/Marlin/src/HAL/HAL_ESP32/timers.h b/Marlin/src/HAL/HAL_ESP32/timers.h index 4b01f4ba7c45..98e43a4a8041 100644 --- a/Marlin/src/HAL/HAL_ESP32/timers.h +++ b/Marlin/src/HAL/HAL_ESP32/timers.h @@ -51,8 +51,8 @@ typedef uint64_t hal_timer_t; #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs // wrong would be 0.25 #else #define STEPPER_TIMER_PRESCALE 40 - #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer, 2MHz - #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs + #define STEPPER_TIMER_RATE ((HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE)) // frequency of stepper timer, 2MHz + #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs #endif #define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts diff --git a/Marlin/src/HAL/HAL_SAMD51/timers.cpp b/Marlin/src/HAL/HAL_SAMD51/timers.cpp index 63902c3c5e26..24340439669d 100644 --- a/Marlin/src/HAL/HAL_SAMD51/timers.cpp +++ b/Marlin/src/HAL/HAL_SAMD51/timers.cpp @@ -99,7 +99,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB); // Set compare value - tc->COUNT32.COUNT.reg = tc->COUNT32.CC[0].reg = HAL_TIMER_RATE / frequency; + tc->COUNT32.COUNT.reg = tc->COUNT32.CC[0].reg = (HAL_TIMER_RATE) / frequency; // And start timer tc->COUNT32.CTRLA.bit.ENABLE = true; diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index 51f84e657fa6..a152e6d763fa 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -32,62 +32,89 @@ #define NUM_HARDWARE_TIMERS 2 +#define __TIMER_DEV(X) TIM##X +#define _TIMER_DEV(X) __TIMER_DEV(X) +#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER) +#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER) + // ------------------------ // Private Variables // ------------------------ -stm32_timer_t TimerHandle[NUM_HARDWARE_TIMERS]; +HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL }; +bool timer_enabled[NUM_HARDWARE_TIMERS] = { false }; // ------------------------ // Public functions // ------------------------ -bool timers_initialized[NUM_HARDWARE_TIMERS] = { false }; - +// frequency is in Hertz void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { + static_assert(TIM_IRQ_PRIO > 0 && TIM_IRQ_PRIO < 15, "Default timer interrupt priority is too low to allow proper prioritization of interrupts."); - if (!timers_initialized[timer_num]) { - uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1, - temp_prescaler = TEMP_TIMER_PRESCALE - 1; + if (!HAL_timer_initialized(timer_num)) { switch (timer_num) { - case STEP_TIMER_NUM: - // STEPPER TIMER - use a 32bit timer if possible - 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, STEP_TIMER_IRQ_PRIO, 0); + case STEP_TIMER_NUM: // STEPPER TIMER - use a 32bit timer if possible + timer_instance[timer_num] = new HardwareTimer(STEP_TIMER_DEV); + /* Set the prescaler to the final desired value. + * This will change the effective ISR callback frequency but when + * HAL_timer_start(timer_num=0) is called in the core for the first time + * the real frequency isn't important as long as, after boot, the ISR + * gets called with the correct prescaler and count register. So here + * we set the prescaler to the correct, final value and ignore the frequency + * asked. We will call back the ISR in 1 second to start at full speed. + * + * The proper fix, however, would be a correct initialization OR a + * HAL_timer_change(const uint8_t timer_num, const uint32_t frequency) + * which changes the prescaler when an IRQ frequency change is needed + * (for example when steppers are turned on) + */ + timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); //the -1 is done internally + timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE) /* /frequency */), TICK_FORMAT); + timer_instance[timer_num]->attachInterrupt(Step_Handler); // Called on rollover + + // IRQ priority is left unchanged for SoftSerial compatibility break; - - case TEMP_TIMER_NUM: - // TEMP TIMER - any available 16bit Timer - 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, TEMP_TIMER_IRQ_PRIO, 0); + case TEMP_TIMER_NUM: // TEMP TIMER - any available 16bit timer + timer_instance[timer_num] = new HardwareTimer(TEMP_TIMER_DEV); + // The prescale factor is computed automatically for HERTZ_FORMAT + timer_instance[timer_num]->setOverflow(frequency, HERTZ_FORMAT); + timer_instance[timer_num]->attachInterrupt(Temp_Handler); break; } - timers_initialized[timer_num] = true; } } void HAL_timer_enable_interrupt(const uint8_t timer_num) { - const IRQn_Type IRQ_Id = IRQn_Type(getTimerIrq(TimerHandle[timer_num].timer)); - HAL_NVIC_EnableIRQ(IRQ_Id); + if (HAL_timer_initialized(timer_num) && !timer_enabled[timer_num]) { + timer_enabled[timer_num] = true; + timer_instance[timer_num]->resume(); // Resume the timer to start receiving the interrupt + + // HardwareTimer::resume() reinits the timer, resetting the priority. Set again. + if (timer_num == TEMP_TIMER_NUM) + HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TIM_IRQ_PRIO + 1, 0); //default+1 + } } void HAL_timer_disable_interrupt(const uint8_t timer_num) { - const IRQn_Type IRQ_Id = IRQn_Type(getTimerIrq(TimerHandle[timer_num].timer)); - HAL_NVIC_DisableIRQ(IRQ_Id); - - // We NEED memory barriers to ensure Interrupts are actually disabled! - // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) - __DSB(); - __ISB(); + if (HAL_timer_interrupt_enabled(timer_num)) { + // Pause the timer instead of detaching the interrupt through detachInterrupt() + timer_instance[timer_num]->pause(); + timer_enabled[timer_num] = false; + } } bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { - const uint32_t IRQ_Id = getTimerIrq(TimerHandle[timer_num].timer); - return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F); + return HAL_timer_initialized(timer_num) && timer_enabled[timer_num]; +} + +// Only for use within the HAL +TIM_TypeDef * HAL_timer_device(const uint8_t timer_num) { + switch (timer_num) { + case STEP_TIMER_NUM: return STEP_TIMER_DEV; + case TEMP_TIMER_NUM: return TEMP_TIMER_DEV; + } + return nullptr; } #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/HAL_STM32/timers.h b/Marlin/src/HAL/HAL_STM32/timers.h index aefe880b4e63..66ccf2bb749c 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.h +++ b/Marlin/src/HAL/HAL_STM32/timers.h @@ -66,46 +66,26 @@ #endif #ifndef TEMP_TIMER - #define TEMP_TIMER 7 + #define TEMP_TIMER 14 #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 #define TEMP_TIMER_NUM 1 // index of timer to use for temperature #define PULSE_TIMER_NUM STEP_TIMER_NUM -#define TEMP_TIMER_RATE 72000 // 72 Khz -#define TEMP_TIMER_PRESCALE ((HAL_TIMER_RATE)/(TEMP_TIMER_RATE)) -#define TEMP_TIMER_FREQUENCY 1000 +#define TEMP_TIMER_FREQUENCY 1000 //Temperature::isr() is expected to be called at around 1kHz +//TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp #define STEPPER_TIMER_RATE 2000000 // 2 Mhz -#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE)) +#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE) / (STEPPER_TIMER_RATE)) #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs #define PULSE_TIMER_RATE STEPPER_TIMER_RATE #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US -#define __TIMER_DEV(X) TIM##X -#define _TIMER_DEV(X) __TIMER_DEV(X) -#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER) -#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER) - -#define __TIMER_CALLBACK(X) TIM##X##_IRQHandler -#define _TIMER_CALLBACK(X) __TIMER_CALLBACK(X) - -#define STEP_TIMER_CALLBACK _TIMER_CALLBACK(STEP_TIMER) -#define TEMP_TIMER_CALLBACK _TIMER_CALLBACK(TEMP_TIMER) - #define __TIMER_IRQ_NAME(X) TIM##X##_IRQn #define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X) @@ -119,22 +99,16 @@ #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(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) -#define HAL_TEMP_TIMER_ISR() void Temp_Handler(stimer_t *htim) - -// ------------------------ -// Types -// ------------------------ - -typedef stimer_t stm32_timer_t; +extern void Step_Handler(HardwareTimer *htim); +extern void Temp_Handler(HardwareTimer *htim); +#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim) +#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim) // ------------------------ // Public Variables // ------------------------ -extern stm32_timer_t TimerHandle[]; +extern HardwareTimer *timer_instance[]; // ------------------------ // Public functions @@ -145,18 +119,26 @@ void HAL_timer_enable_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); -FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) { - return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle); -} +//TIM_TypeDef * HAL_timer_device(const uint8_t timer_num); no need to be public for now. not public = not used externally -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 because these are used in performance-critical situations +FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) { + return timer_instance[timer_num] != NULL; +} +FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { + return HAL_timer_initialized(timer_num) ? timer_instance[timer_num]->getCount() : 0; } -FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) { - return __HAL_TIM_GET_AUTORELOAD(&TimerHandle[timer_num].handle); +// NOTE: Method name may be misleading. +// STM32 has an Auto-Reload Register (ARR) as opposed to a "compare" register +FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t overflow) { + if (HAL_timer_initialized(timer_num)) { + timer_instance[timer_num]->setOverflow(overflow + 1, TICK_FORMAT); // Value decremented by setOverflow() + // wiki: "force all registers (Autoreload, prescaler, compare) to be taken into account" + // So, if the new overflow value is less than the count it will trigger a rollover interrupt. + if (overflow < timer_instance[timer_num]->getCount()) // Added 'if' here because reports say it won't boot without it + timer_instance[timer_num]->refresh(); + } } #define HAL_timer_isr_prologue(TIMER_NUM) diff --git a/Marlin/src/HAL/HAL_STM32F1/timers.cpp b/Marlin/src/HAL/HAL_STM32F1/timers.cpp index a1f5f1e45367..6f55fc609c74 100644 --- a/Marlin/src/HAL/HAL_STM32F1/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/timers.cpp @@ -82,7 +82,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { timer_set_prescaler(STEP_TIMER_DEV, (uint16_t)(STEPPER_TIMER_PRESCALE - 1)); timer_set_reload(STEP_TIMER_DEV, 0xFFFF); timer_oc_set_mode(STEP_TIMER_DEV, STEP_TIMER_CHAN, TIMER_OC_MODE_FROZEN, TIMER_OC_NO_PRELOAD); // no output pin change - timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE / frequency))); + timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE) / frequency)); timer_no_ARR_preload_ARPE(STEP_TIMER_DEV); // Need to be sure no preload on ARR register timer_attach_interrupt(STEP_TIMER_DEV, STEP_TIMER_CHAN, stepTC_Handler); nvic_irq_set_priority(irq_num, STEP_TIMER_IRQ_PRIO); @@ -95,7 +95,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { timer_set_count(TEMP_TIMER_DEV, 0); timer_set_prescaler(TEMP_TIMER_DEV, (uint16_t)(TEMP_TIMER_PRESCALE - 1)); timer_set_reload(TEMP_TIMER_DEV, 0xFFFF); - timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), ((F_CPU / TEMP_TIMER_PRESCALE) / frequency))); + timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (F_CPU) / (TEMP_TIMER_PRESCALE) / frequency)); timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler); nvic_irq_set_priority(irq_num, TEMP_TIMER_IRQ_PRIO); timer_generate_update(TEMP_TIMER_DEV); diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h index d4ca01e02264..d7e07f7716cb 100644 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h @@ -24,16 +24,15 @@ #define CPU_32_BIT +#include "../../inc/MarlinConfigPre.h" + #include "../shared/Marduino.h" #include "../shared/math_32bit.h" #include "../shared/HAL_SPI.h" #include "fastio.h" -#include "watchdog.h" - #include "timers.h" - -#include "../../inc/MarlinConfigPre.h" +#include "watchdog.h" #include diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp deleted file mode 100644 index 32219962ee75..000000000000 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#if defined(STM32GENERIC) && defined(STM32F4) - -#include "../HAL.h" -#include "timers.h" - -// ------------------------ -// Local defines -// ------------------------ - -#define NUM_HARDWARE_TIMERS 2 -#define STEP_TIMER_IRQ_ID TIM5_IRQn -#define TEMP_TIMER_IRQ_ID TIM7_IRQn - -// ------------------------ -// Private Variables -// ------------------------ - -stm32_timer_t TimerHandle[NUM_HARDWARE_TIMERS]; - -// ------------------------ -// Public functions -// ------------------------ - -bool timers_initialized[NUM_HARDWARE_TIMERS] = {false}; - -void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { - - if (!timers_initialized[timer_num]) { - constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1, - temp_prescaler = TEMP_TIMER_PRESCALE - 1; - switch (timer_num) { - case STEP_TIMER_NUM: - // STEPPER TIMER TIM5 - use a 32bit timer - __HAL_RCC_TIM5_CLK_ENABLE(); - TimerHandle[timer_num].handle.Instance = TIM5; - TimerHandle[timer_num].handle.Init.Prescaler = step_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)TC5_Handler; - HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 1, 0); - break; - - case TEMP_TIMER_NUM: - // TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM) - __HAL_RCC_TIM7_CLK_ENABLE(); - 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; - HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0); - break; - } - timers_initialized[timer_num] = true; - } - - TimerHandle[timer_num].handle.Init.Period = (((HAL_TIMER_RATE) / TimerHandle[timer_num].handle.Init.Prescaler) / frequency) - 1; - if (HAL_TIM_Base_Init(&TimerHandle[timer_num].handle) == HAL_OK) - HAL_TIM_Base_Start_IT(&TimerHandle[timer_num].handle); -} - -extern "C" void TIM5_IRQHandler() { - ((void(*)())TimerHandle[0].callback)(); -} -extern "C" void TIM7_IRQHandler() { - ((void(*)())TimerHandle[1].callback)(); -} - -void HAL_timer_enable_interrupt(const uint8_t timer_num) { - 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) { - 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! - // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) - __DSB(); - __ISB(); -} - -bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { - switch (timer_num) { - 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)); - } - return false; -} - -#endif // STM32GENERIC && STM32F4 diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h deleted file mode 100644 index 726207fbcfc6..000000000000 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2017 Victor Perez - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include - -// ------------------------ -// Defines -// ------------------------ - -#define FORCE_INLINE __attribute__((always_inline)) inline - -#define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked? -#define HAL_TIMER_TYPE_MAX 0xFFFF - -#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals - -#define STEP_TIMER_NUM 0 // index of timer to use for stepper -#define TEMP_TIMER_NUM 1 // index of timer to use for temperature -#define PULSE_TIMER_NUM STEP_TIMER_NUM - -#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz -#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency - -#define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz -#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer -#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs - -#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer -#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE -#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US - -#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) -#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) -#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) - -#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) -#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) - -// 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 - - -// ------------------------ -// Types -// ------------------------ - -#ifdef STM32GENERIC - typedef struct { - TIM_HandleTypeDef handle; - uint32_t callback; - } tTimerConfig; - typedef tTimerConfig stm32_timer_t; -#else - typedef stimer_t stm32_timer_t; -#endif - -// ------------------------ -// Public Variables -// ------------------------ - -extern stm32_timer_t TimerHandle[]; - -// ------------------------ -// Public functions -// ------------------------ - -void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); -void HAL_timer_enable_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); - -FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) { - return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle); -} - -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); -} - -#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 - -#define HAL_timer_isr_epilogue(TIMER_NUM) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp deleted file mode 100644 index 5a3b32ef5bce..000000000000 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#if defined(STM32GENERIC) && defined(STM32F7) - -#include "../HAL.h" -#include "timers.h" - -// ------------------------ -// Local defines -// ------------------------ - -#define NUM_HARDWARE_TIMERS 2 - -//#define PRESCALER 1 - -// ------------------------ -// Private Variables -// ------------------------ - -tTimerConfig timerConfig[NUM_HARDWARE_TIMERS]; - -// ------------------------ -// Public functions -// ------------------------ - -bool timers_initialized[NUM_HARDWARE_TIMERS] = { false }; - -void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { - - if (!timers_initialized[timer_num]) { - switch (timer_num) { - case STEP_TIMER_NUM: - //STEPPER TIMER TIM5 //use a 32bit timer - __HAL_RCC_TIM5_CLK_ENABLE(); - timerConfig[0].timerdef.Instance = TIM5; - timerConfig[0].timerdef.Init.Prescaler = (STEPPER_TIMER_PRESCALE); - timerConfig[0].timerdef.Init.CounterMode = TIM_COUNTERMODE_UP; - timerConfig[0].timerdef.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - timerConfig[0].IRQ_Id = TIM5_IRQn; - timerConfig[0].callback = (uint32_t)TC5_Handler; - HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0); - #if PIN_EXISTS(STEPPER_ENABLE) - OUT_WRITE(STEPPER_ENABLE_PIN, HIGH); - #endif - break; - case TEMP_TIMER_NUM: - //TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM) - __HAL_RCC_TIM7_CLK_ENABLE(); - timerConfig[1].timerdef.Instance = TIM7; - timerConfig[1].timerdef.Init.Prescaler = (TEMP_TIMER_PRESCALE); - timerConfig[1].timerdef.Init.CounterMode = TIM_COUNTERMODE_UP; - timerConfig[1].timerdef.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - timerConfig[1].IRQ_Id = TIM7_IRQn; - timerConfig[1].callback = (uint32_t)TC7_Handler; - HAL_NVIC_SetPriority(timerConfig[1].IRQ_Id, 2, 0); - break; - } - timers_initialized[timer_num] = true; - } - - timerConfig[timer_num].timerdef.Init.Period = (((HAL_TIMER_RATE) / timerConfig[timer_num].timerdef.Init.Prescaler) / frequency) - 1; - - if (HAL_TIM_Base_Init(&timerConfig[timer_num].timerdef) == HAL_OK) - HAL_TIM_Base_Start_IT(&timerConfig[timer_num].timerdef); -} - -//forward the interrupt -extern "C" void TIM5_IRQHandler() { - ((void(*)())timerConfig[0].callback)(); -} -extern "C" void TIM7_IRQHandler() { - ((void(*)())timerConfig[1].callback)(); -} - -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) { - HAL_NVIC_EnableIRQ(timerConfig[timer_num].IRQ_Id); -} - -void HAL_timer_disable_interrupt(const uint8_t timer_num) { - HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id); - - // We NEED memory barriers to ensure Interrupts are actually disabled! - // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) - __DSB(); - __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_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) { - const uint32_t IRQ_Id = uint32_t(timerConfig[timer_num].IRQ_Id); - return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F); -} - -#endif // STM32GENERIC && STM32F7 diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h deleted file mode 100644 index 38ecde30bb94..000000000000 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2017 Victor Perez - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include - -// ------------------------ -// Defines -// ------------------------ - -#define FORCE_INLINE __attribute__((always_inline)) inline - -#define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked? -#define HAL_TIMER_TYPE_MAX 0xFFFF - -#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals - -#define STEP_TIMER_NUM 0 // index of timer to use for stepper -#define TEMP_TIMER_NUM 1 // index of timer to use for temperature -#define PULSE_TIMER_NUM STEP_TIMER_NUM - -#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency -#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz - -#define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz -#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer -#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs - -#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer -#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE -#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US - -#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) -#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) - -#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) - -// TODO change this - -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 -// ------------------------ - -typedef struct { - TIM_HandleTypeDef timerdef; - IRQn_Type IRQ_Id; - uint32_t callback; -} tTimerConfig; - -// ------------------------ -// Public Variables -// ------------------------ - -//extern const tTimerConfig timerConfig[]; - -// ------------------------ -// Public functions -// ------------------------ - -void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); -void HAL_timer_enable_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); - -void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare); -hal_timer_t HAL_timer_get_compare(const uint8_t timer_num); -uint32_t HAL_timer_get_count(const uint8_t timer_num); -void HAL_timer_isr_prologue(const uint8_t timer_num); -#define HAL_timer_isr_epilogue(TIMER_NUM) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp new file mode 100644 index 000000000000..ab06cf3b206c --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp @@ -0,0 +1,92 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) + +#include "HAL.h" + +#include "timers.h" + +// ------------------------ +// Local defines +// ------------------------ + +#define NUM_HARDWARE_TIMERS 2 + +// ------------------------ +// Private Variables +// ------------------------ + +HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL }; +bool timer_enabled[NUM_HARDWARE_TIMERS] = { false }; + +// ------------------------ +// Public functions +// ------------------------ + +// 'frequency' is in Hertz +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { + if (!HAL_timer_initialized(timer_num)) { + // According to documentation the prescale factor is computed automatically if setOverflow is in HERTZ_FORMAT + switch (timer_num) { + case STEP_TIMER_NUM: + // STEPPER TIMER - use a 32bit timer if possible + timer_instance[timer_num] = new HardwareTimer(STEP_TIMER_DEV); + timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); + timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE) / frequency), TICK_FORMAT); + timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); + timer_instance[timer_num]->attachInterrupt(Step_Handler); // Called on update interruption (rollover) + timer_instance[timer_num]->resume(); + break; + case TEMP_TIMER_NUM: + // TEMP TIMER - any available 16bit Timer + timer_instance[timer_num] = new HardwareTimer(TEMP_TIMER_DEV); + timer_instance[timer_num]->setMode(1, TIMER_OUTPUT_COMPARE); + timer_instance[timer_num]->setOverflow(frequency, HERTZ_FORMAT); + timer_instance[timer_num]->attachInterrupt(Temp_Handler); + timer_instance[timer_num]->resume(); + break; + } + } +} + +void HAL_timer_enable_interrupt(const uint8_t timer_num) { + if (HAL_timer_initialized(timer_num) && !timer_enabled[timer_num]) { + // Resume the timer to start receiving the interrupt + timer_instance[timer_num]->resume(); + timer_enabled[timer_num] = true; + } +} + +void HAL_timer_disable_interrupt(const uint8_t timer_num) { + if (HAL_timer_interrupt_enabled(timer_num)) { + // Pause the timer instead of detaching the interrupt through detachInterrupt() + timer_instance[timer_num]->pause(); + timer_enabled[timer_num] = false; + } +} + +bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { + return HAL_timer_initialized(timer_num) && timer_enabled[timer_num]; +} + +#endif // STM32GENERIC && (STM32F4 || STM32F7) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h index cf33205bddab..55371126e4c7 100644 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h @@ -21,8 +21,136 @@ */ #pragma once -#ifdef STM32F4 - #include "STM32F4/timers.h" -#else - #include "STM32F7/timers.h" +#include +#include "../../inc/MarlinConfig.h" + +// ------------------------ +// Defines +// ------------------------ + +#define FORCE_INLINE __attribute__((always_inline)) inline + +#define hal_timer_t uint32_t +#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit + +#ifdef STM32F0xx + + #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals + + #ifndef STEP_TIMER + #define STEP_TIMER 16 + #endif + + #ifndef TEMP_TIMER + #define TEMP_TIMER 17 + #endif + +#elif defined(STM32F1xx) + + #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals + + #ifndef STEP_TIMER + #define STEP_TIMER 4 + #endif + + #ifndef TEMP_TIMER + #define TEMP_TIMER 2 + #endif + +#elif defined(STM32F4xx) || defined(STM32F7xx) + + #define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals + + #ifndef STEP_TIMER + #define STEP_TIMER 5 + #endif + + #ifndef TEMP_TIMER + #define TEMP_TIMER 7 + #endif + #endif + +#define STEP_TIMER_NUM 0 // index of timer to use for stepper +#define TEMP_TIMER_NUM 1 // index of timer to use for temperature +#define PULSE_TIMER_NUM STEP_TIMER_NUM + +#define TEMP_TIMER_RATE 72000 // 72 Khz +#define TEMP_TIMER_PRESCALE ((HAL_TIMER_RATE)/(TEMP_TIMER_RATE)) +#define TEMP_TIMER_FREQUENCY 1000 + +#define STEPPER_TIMER_RATE 2000000 // 2 Mhz +#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE)) +#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs + +#define PULSE_TIMER_RATE STEPPER_TIMER_RATE +#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE +#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US + +#define __TIMER_DEV(X) TIM##X +#define _TIMER_DEV(X) __TIMER_DEV(X) +#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER) +#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER) + +#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) +#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) +#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) + +#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) +#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) + +extern void Step_Handler(HardwareTimer *htim); +extern void Temp_Handler(HardwareTimer *htim); +#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim) +#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim) + +// ------------------------ +// Public Variables +// ------------------------ + +extern HardwareTimer *timer_instance[]; + +// ------------------------ +// Public functions +// ------------------------ + +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); +void HAL_timer_enable_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); + +//made FORCE_INLINE because it's used from FORCE_INLINE (performance critical) methods +FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) { + return timer_instance[timer_num] != NULL; +} +FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) { + return HAL_timer_initialized(timer_num) ? timer_instance[timer_num]->getCount() : 0; +} + +FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) { + if (HAL_timer_initialized(timer_num)) { + #ifdef HW_TIMERS + timer_instance[timer_num]->setOverflow(compare, TICK_FORMAT); + const uint32_t cnt = timer_instance[timer_num]->getCount(TICK_FORMAT); + if (cnt >= compare) timer_instance[timer_num]->refresh(); + #else + __HAL_TIM_SET_AUTORELOAD(&timer_instance[timer_num].handle, compare); + if (HAL_timer_get_count(timer_num) >= compare) + timer_instance[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt + #endif + } +} + +FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) { + if (!HAL_timer_initialized(timer_num)) return 0; + return ( + #ifdef HW_TIMERS + timer_instance[timer_num]->getOverflow(TICK_FORMAT) + #else + __HAL_TIM_GET_AUTORELOAD(&timer_instance[timer_num].handle) + #endif + ); +} + +#define HAL_timer_isr_prologue(TIMER_NUM) +#define HAL_timer_isr_epilogue(TIMER_NUM) diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp index 1ae4bcf4f027..e4ccf33a4bb0 100644 --- a/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp +++ b/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp @@ -53,7 +53,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { FTM0_SC = 0x00; // Set this to zero before changing the modulus FTM0_CNT = 0x0000; // Reset the count to zero FTM0_MOD = 0xFFFF; // max modulus = 65535 - FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value + FTM0_C0V = (FTM0_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8 FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA; break; @@ -62,7 +62,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { FTM1_SC = 0x00; // Set this to zero before changing the modulus FTM1_CNT = 0x0000; // Reset the count to zero FTM1_MOD = 0xFFFF; // max modulus = 65535 - FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535 + FTM1_C0V = (FTM1_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value 65535 FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4 FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA; break; diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp index 6ee61182080b..6bbc16dcb55e 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp +++ b/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp @@ -54,7 +54,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { FTM0_SC = 0x00; // Set this to zero before changing the modulus FTM0_CNT = 0x0000; // Reset the count to zero FTM0_MOD = 0xFFFF; // max modulus = 65535 - FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value + FTM0_C0V = (FTM0_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8 FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA; break; @@ -63,7 +63,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { FTM1_SC = 0x00; // Set this to zero before changing the modulus FTM1_CNT = 0x0000; // Reset the count to zero FTM1_MOD = 0xFFFF; // max modulus = 65535 - FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535 + FTM1_C0V = (FTM1_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value 65535 FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4 FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA; break; diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 19060b9b23a9..f59b7a42a39b 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1537,7 +1537,7 @@ void Stepper::stepper_pulse_phase_isr() { uint32_t Stepper::stepper_block_phase_isr() { // If no queued movements, just wait 1ms for the next move - uint32_t interval = (STEPPER_TIMER_RATE / 1000); + uint32_t interval = (STEPPER_TIMER_RATE) / 1000; // If there is a current block if (current_block) { diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 601e83ebd0e4..e46b4cf29700 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1308,7 +1308,7 @@ void Temperature::manage_heater() { } // maximum adc value .. take into account the over sampling - const int adc_max = (THERMISTOR_ADC_RESOLUTION * OVERSAMPLENR) - 1, + const int adc_max = _BV(THERMISTOR_ADC_RESOLUTION) * OVERSAMPLENR - 1, adc_raw = constrain(raw, 1, adc_max - 1); // constrain to prevent divide-by-zero const float adc_inverse = (adc_max - adc_raw) - 0.5f, @@ -2313,7 +2313,7 @@ void Temperature::readings_ready() { HAL_TEMP_TIMER_ISR() { HAL_timer_isr_prologue(TEMP_TIMER_NUM); - Temperature::isr(); + Temperature::tick(); HAL_timer_isr_epilogue(TEMP_TIMER_NUM); } @@ -2343,11 +2343,21 @@ class SoftPWM { #endif }; -void Temperature::isr() { +/** + * Handle various ~1KHz tasks associated with temperature + * - Heater PWM (~1KHz with scaler) + * - LCD Button polling (~500Hz) + * - Start / Read one ADC sensor + * - Advance Babysteps + * - Endstop polling + * - Planner clean buffer + */ +void Temperature::tick() { static int8_t temp_count = -1; static ADCSensorState adc_sensor_state = StartupDelay; static uint8_t pwm_count = _BV(SOFT_PWM_SCALE); + // avoid multiple loads of pwm_count uint8_t pwm_count_tmp = pwm_count; diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index c294325d9bdf..ab95d9d3879a 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -217,9 +217,9 @@ typedef struct { int16_t raw_min, raw_max; } raw_range_t; typedef struct { int16_t mintemp, maxtemp; } celsius_range_t; typedef struct { int16_t raw_min, raw_max, mintemp, maxtemp; } temp_range_t; -#define THERMISTOR_ADC_RESOLUTION 1024 // 10-bit ADC .. shame to waste 12-bits of resolution on 32-bit -#define THERMISTOR_ABS_ZERO_C -273.15f // bbbbrrrrr cold ! -#define THERMISTOR_RESISTANCE_NOMINAL_C 25.0f // mmmmm comfortable +#define THERMISTOR_ADC_RESOLUTION 10 // 10-bit ADC .. shame to waste 12-bits of resolution on 32-bit +#define THERMISTOR_ABS_ZERO_C -273.15f // bbbbrrrrr cold ! +#define THERMISTOR_RESISTANCE_NOMINAL_C 25.0f // mmmmm comfortable #if HAS_USER_THERMISTORS @@ -268,8 +268,6 @@ class Temperature { public: - static volatile bool in_temp_isr; - #if HOTENDS #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) #define HOTEND_TEMPS (HOTENDS + 1) @@ -513,7 +511,7 @@ class Temperature { * Called from the Temperature ISR */ static void readings_ready(); - static void isr(); + static void tick(); /** * Call periodically to manage heaters diff --git a/buildroot/share/PlatformIO/scripts/black_stm32f407vet6.py b/buildroot/share/PlatformIO/scripts/black_stm32f407vet6.py deleted file mode 100644 index cc43893d09fa..000000000000 --- a/buildroot/share/PlatformIO/scripts/black_stm32f407vet6.py +++ /dev/null @@ -1,29 +0,0 @@ -import os,shutil -from SCons.Script import DefaultEnvironment -from platformio import util - -env = DefaultEnvironment() -platform = env.PioPlatform() -board = env.BoardConfig() - -FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32") -CMSIS_DIR = os.path.join(FRAMEWORK_DIR, "CMSIS", "CMSIS") -assert os.path.isdir(FRAMEWORK_DIR) -assert os.path.isdir(CMSIS_DIR) -assert os.path.isdir("buildroot/share/PlatformIO/variants") - -mcu_type = board.get("build.mcu")[:-2] -variant = board.get("build.variant") -series = mcu_type[:7].upper() + "xx" -variant_dir = os.path.join(FRAMEWORK_DIR, "variants", variant) - -source_dir = os.path.join("buildroot/share/PlatformIO/variants", variant) -assert os.path.isdir(source_dir) - -if not os.path.isdir(variant_dir): - os.mkdir(variant_dir) - -for file_name in os.listdir(source_dir): - full_file_name = os.path.join(source_dir, file_name) - if os.path.isfile(full_file_name): - shutil.copy(full_file_name, variant_dir) diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c index 28504fc1056a..2e3a5b8a8a8e 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c +++ b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c @@ -41,56 +41,56 @@ #ifdef HAL_ADC_MODULE_ENABLED const PinMap PinMap_ADC[] = { - {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 + {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 E0_DIR //{PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 //{PA_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 - {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 + {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 BLTOUCH_2 //{PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 //{PA_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 - {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 BLTOUCH_4 //{PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 //{PA_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 - {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 E1_EN //{PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 //{PA_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 - {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 TF_SS //{PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 - {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 TF_SCLK //{PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 - {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 TF_MISO //{PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 - {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 LED //{PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 - {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 HEATER2 //{PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 - {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 HEATER0 //{PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 + {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 Z_EN //{PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 //{PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC3_IN10 - {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 + {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 EXP_14 //{PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 //{PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_IN11 - {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 + {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 Z_DIR //{PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 //{PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC3_IN12 - {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 + {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 E0_EN //{PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 //{PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC3_IN13 - {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 + {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 EXP_8 //{PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 - {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 + {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 EXP_7 //{PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 #if STM32F4X_PIN_NUM >= 144 //144 pins mcu, 114 gpio, 24 ADC - {PF_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 - {PF_4, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14 - {PF_5, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 - {PF_6, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 - {PF_7, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5 - {PF_8, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6 - {PF_9, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7 - {PF_10, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 + {PF_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 TH_0 + {PF_4, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14 TH_1 + {PF_5, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 TH_2 + {PF_6, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 TH_3 + {PF_7, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5 EXP_13 + {PF_8, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6 EXP_3 + {PF_9, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7 EXP_6 + {PF_10, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 EXP_5 #endif {NC, NP, 0} }; @@ -189,7 +189,7 @@ const PinMap PinMap_PWM[] = { {PC_6, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 {PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 {PC_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 - {PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 + {PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 FAN0 {PC_8, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 //{PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 //{PC_9, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 @@ -197,8 +197,8 @@ const PinMap PinMap_PWM[] = { {PD_13, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 {PD_14, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 {PD_15, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 - {PE_5, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 - {PE_6, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 + {PE_5, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 FAN1 + {PE_6, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 FAN2 {PE_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N {PE_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 {PE_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N @@ -236,9 +236,7 @@ const PinMap PinMap_UART_TX[] = { #endif {NC, NP, 0} }; -#endif -#ifdef HAL_UART_MODULE_ENABLED const PinMap PinMap_UART_RX[] = { {PA_1, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, {PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, @@ -256,9 +254,7 @@ const PinMap PinMap_UART_RX[] = { #endif {NC, NP, 0} }; -#endif -#ifdef HAL_UART_MODULE_ENABLED const PinMap PinMap_UART_RTS[] = { {PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PA_12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, @@ -271,9 +267,7 @@ const PinMap PinMap_UART_RTS[] = { #endif {NC, NP, 0} }; -#endif -#ifdef HAL_UART_MODULE_ENABLED const PinMap PinMap_UART_CTS[] = { {PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PA_11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, @@ -300,9 +294,7 @@ const PinMap PinMap_SPI_MOSI[] = { {PC_12, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; -#endif -#ifdef HAL_SPI_MODULE_ENABLED const PinMap PinMap_SPI_MISO[] = { {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, @@ -312,9 +304,7 @@ const PinMap PinMap_SPI_MISO[] = { {PC_11, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; -#endif -#ifdef HAL_SPI_MODULE_ENABLED const PinMap PinMap_SPI_SCLK[] = { {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, @@ -324,9 +314,7 @@ const PinMap PinMap_SPI_SCLK[] = { {PC_10, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; -#endif -#ifdef HAL_SPI_MODULE_ENABLED const PinMap PinMap_SPI_SSEL[] = { {PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PA_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, @@ -349,9 +337,7 @@ const PinMap PinMap_CAN_RD[] = { {PD_0, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, {NC, NP, 0} }; -#endif -#ifdef HAL_CAN_MODULE_ENABLED const PinMap PinMap_CAN_TD[] = { {PA_12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, {PB_6, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, @@ -408,9 +394,7 @@ const PinMap PinMap_USB_OTG_FS[] = { {PA_12, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP {NC, NP, 0} }; -#endif -#ifdef HAL_PCD_MODULE_ENABLED const PinMap PinMap_USB_OTG_HS[] = { #ifdef USE_USB_HS_IN_FS {PA_4, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_SOF diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/ldscript.ld b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/ldscript.ld index f92e3eeaa68b..0c060d175180 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/ldscript.ld +++ b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/ldscript.ld @@ -192,7 +192,6 @@ SECTIONS . = ALIGN(4); } >RAM - /* Remove information from the standard libraries */ /DISCARD/ : { @@ -203,5 +202,3 @@ SECTIONS .ARM.attributes 0 : { *(.ARM.attributes) } } - - diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h index 9b62bb6775eb..e138ab8e131e 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h +++ b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h @@ -222,9 +222,15 @@ extern "C" { //#define DACC_RESOLUTION 12 // PWM resolution -#define PWM_RESOLUTION 8 -#define PWM_FREQUENCY 20000 -#define PWM_MAX_DUTY_CYCLE 255 +/* + * BEWARE: + * Changing this value from the default (1000) will affect the PWM output value of analogWrite (to a PWM pin) + * Since the pin is toggled on capture, if you change the frequency of the timer you have to adapt the compare value (analogWrite thinks you did) + */ +//#define PWM_FREQUENCY 20000 +//The bottom values are the default and don't need to be redefined +//#define PWM_RESOLUTION 8 +//#define PWM_MAX_DUTY_CYCLE 255 // Below SPI and I2C definitions already done in the core // Could be redefined here if differs from the default one @@ -261,7 +267,11 @@ extern "C" { #define PIN_SERIAL_TX PA9 /* Extra HAL modules */ -#define HAL_PCD_MODULE_ENABLED +#ifndef HAL_PCD_MODULE_ENABLED + #define HAL_PCD_MODULE_ENABLED //Since STM32 v3.10700.191028 this is automatically added if any type of USB is enabled (as in Arduino IDE) +#endif + +#define HAL_DAC_MODULE_ENABLED #ifdef __cplusplus } // extern "C" diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/PeripheralPins.c b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/PeripheralPins.c index f76cc14bf912..6b6cfdbcb0b8 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/PeripheralPins.c +++ b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/PeripheralPins.c @@ -3,8 +3,10 @@ * Copyright (c) 2019, STMicroelectronics * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. @@ -28,8 +30,8 @@ ******************************************************************************* * Automatically generated from STM32F407Z(E-G)Tx.xml */ -#include -#include +#include "Arduino.h" +#include "PeripheralPins.h" /* ===== * Note: Commented lines are alternative possibilities which are not used per default. @@ -40,58 +42,58 @@ //*** ADC *** #ifdef HAL_ADC_MODULE_ENABLED -const PinMap PinMap_ADC[] = { +WEAK const PinMap PinMap_ADC[] = { {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 - // {PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 - // {PA_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 + //{PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 + //{PA_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 - // {PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 - // {PA_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 - // {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + //{PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 + //{PA_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 + //{PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 {PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 - // {PA_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 - // {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 - // {PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 + //{PA_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 + //{PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + //{PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 {PA_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 - // {PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 - // {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + //{PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 + //{PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 {PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 #if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) - // {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 - // {PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 - // {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 - // {PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 - // {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + //{PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + //{PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 + //{PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + //{PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 + //{PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 #endif {PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 - // {PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - // {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - // {PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 + //{PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 + //{PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 + //{PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 {PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC3_IN10 {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 - // {PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 - // {PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_IN11 - // {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 + //{PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 + //{PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_IN11 + //{PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 {PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 - // {PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC3_IN12 - // {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 - // {PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 + //{PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC3_IN12 + //{PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 + //{PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 {PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC3_IN13 - // {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 + //{PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 {PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 - // {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 + //{PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 {PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 #if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) - // {PF_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 - // {PF_4, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14 - // {PF_5, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 + //{PF_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 + //{PF_4, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14 + //{PF_5, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 {PF_6, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 {PF_7, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5 {PF_8, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6 - // {PF_9, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7 - // {PF_10, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 + //{PF_9, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7 + //{PF_10, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 #endif {NC, NP, 0} }; @@ -100,7 +102,7 @@ const PinMap PinMap_ADC[] = { //*** DAC *** #ifdef HAL_DAC_MODULE_ENABLED -const PinMap PinMap_DAC[] = { +WEAK const PinMap PinMap_DAC[] = { {PA_4, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 {PA_5, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 {NC, NP, 0} @@ -110,7 +112,7 @@ const PinMap PinMap_DAC[] = { //*** I2C *** #ifdef HAL_I2C_MODULE_ENABLED -const PinMap PinMap_I2C_SDA[] = { +WEAK const PinMap PinMap_I2C_SDA[] = { {PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, {PB_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, {PB_11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, @@ -123,7 +125,7 @@ const PinMap PinMap_I2C_SDA[] = { #endif #ifdef HAL_I2C_MODULE_ENABLED -const PinMap PinMap_I2C_SCL[] = { +WEAK const PinMap PinMap_I2C_SCL[] = { {PA_8, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, {PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, {PB_8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, @@ -138,61 +140,61 @@ const PinMap PinMap_I2C_SCL[] = { //*** PWM *** #ifdef HAL_TIM_MODULE_ENABLED -const PinMap PinMap_PWM[] = { +WEAK const PinMap PinMap_PWM[] = { {PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 - // {PA_0, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1 + //{PA_0, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1 {PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 - // {PA_1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2 + //{PA_1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2 {PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 - // {PA_2, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3 - // {PA_2, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 + //{PA_2, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3 + //{PA_2, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 {PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 - // {PA_3, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4 - // {PA_3, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 + //{PA_3, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4 + //{PA_3, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 {PA_5, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 - // {PA_5, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N + //{PA_5, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N {PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 - // {PA_6, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 - // {PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N + //{PA_6, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 + //{PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N {PA_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 - // {PA_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N - // {PA_7, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 + //{PA_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N + //{PA_7, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 {PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 {PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 {PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 {PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 - // {PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 - // {PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N + //{PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 + //{PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 - // {PB_0, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N - // {PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + //{PB_0, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N + //{PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 - // {PB_1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N - // {PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 + //{PB_1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N + //{PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 {PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 {PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 {PB_6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 {PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 - {PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 + //{PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 {PB_8, TIM10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 - {PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 + //{PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 {PB_9, TIM11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 {PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N - {PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N - {PB_14, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N + //{PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N + //{PB_14, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N {PB_14, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 1, 0)}, // TIM12_CH1 - {PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PB_15, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N + //{PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + //{PB_15, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N {PB_15, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 2, 0)}, // TIM12_CH2 - {PC_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + //{PC_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 {PC_6, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 - {PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 + //{PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 {PC_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 {PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 - {PC_8, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 - {PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 + //{PC_8, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 + //{PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 {PC_9, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 {PD_12, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 {PD_13, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 @@ -220,47 +222,47 @@ const PinMap PinMap_PWM[] = { //*** SERIAL *** #ifdef HAL_UART_MODULE_ENABLED -const PinMap PinMap_UART_TX[] = { +WEAK const PinMap PinMap_UART_TX[] = { {PA_0, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, {PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, {PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, {PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, {PC_6, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - // {PC_10, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + //{PC_10, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, {PC_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, {PC_12, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)}, {PD_5, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PD_8, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, #if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) - // {PG_14, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + //{PG_14, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, #endif {NC, NP, 0} }; #endif #ifdef HAL_UART_MODULE_ENABLED -const PinMap PinMap_UART_RX[] = { +WEAK const PinMap PinMap_UART_RX[] = { {PA_1, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, {PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, {PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, {PB_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, {PC_7, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - // {PC_11, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + //{PC_11, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, {PC_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, {PD_2, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)}, {PD_6, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PD_9, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, #if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) - // {PG_9, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + //{PG_9, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, #endif {NC, NP, 0} }; #endif #ifdef HAL_UART_MODULE_ENABLED -const PinMap PinMap_UART_RTS[] = { +WEAK const PinMap PinMap_UART_RTS[] = { {PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PA_12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, {PB_14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, @@ -275,7 +277,7 @@ const PinMap PinMap_UART_RTS[] = { #endif #ifdef HAL_UART_MODULE_ENABLED -const PinMap PinMap_UART_CTS[] = { +WEAK const PinMap PinMap_UART_CTS[] = { {PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, {PA_11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, {PB_13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, @@ -292,9 +294,9 @@ const PinMap PinMap_UART_CTS[] = { //*** SPI *** #ifdef HAL_SPI_MODULE_ENABLED -const PinMap PinMap_SPI_MOSI[] = { +WEAK const PinMap PinMap_SPI_MOSI[] = { {PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, + //{PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_5, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_3, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, @@ -304,9 +306,9 @@ const PinMap PinMap_SPI_MOSI[] = { #endif #ifdef HAL_SPI_MODULE_ENABLED -const PinMap PinMap_SPI_MISO[] = { +WEAK const PinMap PinMap_SPI_MISO[] = { {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, + //{PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_2, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, @@ -316,9 +318,9 @@ const PinMap PinMap_SPI_MISO[] = { #endif #ifdef HAL_SPI_MODULE_ENABLED -const PinMap PinMap_SPI_SCLK[] = { +WEAK const PinMap PinMap_SPI_SCLK[] = { {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, + //{PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_3, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {PB_10, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, @@ -328,10 +330,10 @@ const PinMap PinMap_SPI_SCLK[] = { #endif #ifdef HAL_SPI_MODULE_ENABLED -const PinMap PinMap_SPI_SSEL[] = { +WEAK const PinMap PinMap_SPI_SSEL[] = { {PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PA_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, - {PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, + //{PA_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, + //{PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PA_15, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {PB_9, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, @@ -342,7 +344,7 @@ const PinMap PinMap_SPI_SSEL[] = { //*** CAN *** #ifdef HAL_CAN_MODULE_ENABLED -const PinMap PinMap_CAN_RD[] = { +WEAK const PinMap PinMap_CAN_RD[] = { {PA_11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, {PB_5, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, {PB_8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, @@ -353,7 +355,7 @@ const PinMap PinMap_CAN_RD[] = { #endif #ifdef HAL_CAN_MODULE_ENABLED -const PinMap PinMap_CAN_TD[] = { +WEAK const PinMap PinMap_CAN_TD[] = { {PA_12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, {PB_6, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, {PB_9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, @@ -366,7 +368,7 @@ const PinMap PinMap_CAN_TD[] = { //*** ETHERNET *** #ifdef HAL_ETH_MODULE_ENABLED -const PinMap PinMap_Ethernet[] = { +WEAK const PinMap PinMap_Ethernet[] = { {PA_0, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_CRS {PA_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_REF_CLK|ETH_RX_CLK {PA_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_MDIO @@ -401,10 +403,10 @@ const PinMap PinMap_Ethernet[] = { //*** USB *** #ifdef HAL_PCD_MODULE_ENABLED -const PinMap PinMap_USB_OTG_FS[] = { - // {PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF - // {PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS - // {PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID +WEAK const PinMap PinMap_USB_OTG_FS[] = { + //{PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF + //{PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS + //{PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID {PA_11, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DM {PA_12, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP {NC, NP, 0} @@ -412,7 +414,7 @@ const PinMap PinMap_USB_OTG_FS[] = { #endif #ifdef HAL_PCD_MODULE_ENABLED -const PinMap PinMap_USB_OTG_HS[] = { +WEAK const PinMap PinMap_USB_OTG_HS[] = { #ifdef USE_USB_HS_IN_FS {PA_4, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_SOF {PB_12, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_ID @@ -436,3 +438,21 @@ const PinMap PinMap_USB_OTG_HS[] = { {NC, NP, 0} }; #endif + +//*** SD *** + +#ifdef HAL_SD_MODULE_ENABLED +WEAK const PinMap PinMap_SD[] = { + //{PB_8, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D4 + //{PB_9, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D5 + //{PC_6, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D6 + //{PC_7, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D7 + {PC_8, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D0 + {PC_9, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D1 + {PC_10, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D2 + {PC_11, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D3 + {PC_12, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_SDIO)}, // SDIO_CK + {PD_2, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_SDIO)}, // SDIO_CMD + {NC, NP, 0} +}; +#endif diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/stm32f4xx_hal_conf.h b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/hal_conf_custom.h similarity index 83% rename from buildroot/share/PlatformIO/variants/MARLIN_F407VE/stm32f4xx_hal_conf.h rename to buildroot/share/PlatformIO/variants/MARLIN_F407VE/hal_conf_custom.h index 50d59af3bf4a..92e9fecb4d63 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/stm32f4xx_hal_conf.h +++ b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/hal_conf_custom.h @@ -17,8 +17,8 @@ */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_HAL_CONF_H -#define __STM32F4xx_HAL_CONF_H +#ifndef __STM32F4xx_HAL_CONF_CUSTOM +#define __STM32F4xx_HAL_CONF_CUSTOM #ifdef __cplusplus extern "C" { @@ -73,7 +73,9 @@ extern "C" { /* #define HAL_SMARTCARD_MODULE_ENABLED */ /* #define HAL_WWDG_MODULE_ENABLED */ #define HAL_CORTEX_MODULE_ENABLED -#define HAL_PCD_MODULE_ENABLED +#ifndef HAL_PCD_MODULE_ENABLED + #define HAL_PCD_MODULE_ENABLED //Since STM32 v3.10700.191028 this is automatically added if any type of USB is enabled (as in Arduino IDE) +#endif /* #define HAL_HCD_MODULE_ENABLED */ /* #define HAL_FMPI2C_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ @@ -82,69 +84,81 @@ extern "C" { /* #define HAL_MMC_MODULE_ENABLED */ /* ########################## HSE/HSI Values adaptation ##################### */ - /** +/** * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. * This value is used by the RCC HAL module to compute the system frequency * (when HSE is used as system clock source, directly or through the PLL). */ #ifndef HSE_VALUE -#define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ +#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #ifndef HSE_STARTUP_TIMEOUT -#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ +#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ - /** +/** * @brief Internal High Speed oscillator (HSI) value. * This value is used by the RCC HAL module to compute the system frequency * (when HSI is used as system clock source, directly or through the PLL). */ #ifndef HSI_VALUE -#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz */ #endif /* HSI_VALUE */ - /** +/** * @brief Internal Low Speed oscillator (LSI) value. */ #ifndef LSI_VALUE -#define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ +#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz */ #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations -in voltage and temperature.*/ - /** +in voltage and temperature. */ +/** * @brief External Low Speed oscillator (LSE) value. */ #ifndef LSE_VALUE -#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */ +#define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */ #endif /* LSE_VALUE */ #ifndef LSE_STARTUP_TIMEOUT -#define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ +#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ #endif /* LSE_STARTUP_TIMEOUT */ - /** +/** * @brief External clock source for I2S peripheral * This value is used by the I2S HAL module to compute the I2S clock source * frequency, this source is inserted directly through I2S_CKIN pad. */ #ifndef EXTERNAL_CLOCK_VALUE -#define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000U) /*!< Value of the External audio frequency in Hz*/ +#define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the External oscillator in Hz*/ #endif /* EXTERNAL_CLOCK_VALUE */ /* Tip: To avoid modifying this file each time you need to use different HSE, === you can define the HSE value in your toolchain compiler preprocessor. */ /* ########################### System Configuration ######################### */ - /** +/** * @brief This is the HAL system configuration section */ -#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */ +#if !defined (VDD_VALUE) +#define VDD_VALUE 3300U /*!< Value of VDD in mv */ +#endif +#if !defined (TICK_INT_PRIORITY) +#define TICK_INT_PRIORITY 0x00U /*!< tick interrupt priority */ +#endif +#if !defined (USE_RTOS) #define USE_RTOS 0U +#endif +#if !defined (PREFETCH_ENABLE) #define PREFETCH_ENABLE 1U +#endif +#if !defined (INSTRUCTION_CACHE_ENABLE) #define INSTRUCTION_CACHE_ENABLE 1U +#endif +#if !defined (DATA_CACHE_ENABLE) #define DATA_CACHE_ENABLE 1U +#endif #define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ #define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ @@ -186,7 +200,7 @@ in voltage and temperature.*/ #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ /* ########################## Assert Selection ############################## */ - /** +/** * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ @@ -215,32 +229,32 @@ in voltage and temperature.*/ /* DP83848_PHY_ADDRESS Address*/ #define DP83848_PHY_ADDRESS 0x01U /* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ -#define PHY_RESET_DELAY ((uint32_t)0x000000FFU) +#define PHY_RESET_DELAY 0x000000FFU /* PHY Configuration delay */ -#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) +#define PHY_CONFIG_DELAY 0x00000FFFU -#define PHY_READ_TO ((uint32_t)0x0000FFFFU) -#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) +#define PHY_READ_TO 0x0000FFFFU +#define PHY_WRITE_TO 0x0000FFFFU /* Section 3: Common PHY Registers */ -#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ -#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ +#define PHY_BCR ((uint16_t)0x0000) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x0001) /*!< Transceiver Basic Status Register */ -#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ -#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ -#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ -#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ -#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ -#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ -#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ -#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ -#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ -#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ -#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ -#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ -#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ /* Section 4: Extended PHY Registers */ #define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ @@ -251,14 +265,15 @@ in voltage and temperature.*/ /* ################## SPI peripheral configuration ########################## */ /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver -* Activated: CRC code is present inside driver -* Deactivated: CRC code cleaned from driver -*/ - + * Activated: CRC code is present inside driver + * Deactivated: CRC code cleaned from driver + */ +#ifndef USE_SPI_CRC #define USE_SPI_CRC 0U +#endif /* Includes ------------------------------------------------------------------*/ - /** +/** * @brief Include module's header file */ @@ -456,9 +471,9 @@ in voltage and temperature.*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT - /** +/** * @brief The assert_param macro is used for function's parameters check. - * @param expr: If expr is false, it calls assert_failed function + * @param expr If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. @@ -475,7 +490,7 @@ void assert_failed(uint8_t *file, uint32_t line); } #endif -#endif /* __STM32F4xx_HAL_CONF_H */ +#endif /* __STM32F4xx_HAL_CONF_CUSTOM_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/ldscript.ld b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/ldscript.ld index cdbbfcdcd187..efe2db5cd472 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/ldscript.ld +++ b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/ldscript.ld @@ -1,10 +1,11 @@ /* ***************************************************************************** ** -** File : LinkerScript.ld + +** File : lscript.ld ** -** Abstract : Linker script for STM32F407VETx Device with -** 512KByte FLASH, 128KByte RAM +** Abstract : Linker script for STM32F407(VZ)(EG)Tx Device with +** 512/1024KByte FLASH, 128KByte RAM ** ** Set heap size, stack size and stack location according ** to application requirements. @@ -17,13 +18,32 @@ ** Distribution: The file is distributed as is, without any warranty ** of any kind. ** -** (c)Copyright Ac6. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Ac6 permit registered System Workbench for MCU users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the System Workbench for MCU toolchain. +***************************************************************************** +** @attention +** +**

© COPYRIGHT(c) 2014 Ac6

+** +** Redistribution and use in source and binary forms, with or without modification, +** are permitted provided that the following conditions are met: +** 1. Redistributions of source code must retain the above copyright notice, +** this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright notice, +** this list of conditions and the following disclaimer in the documentation +** and/or other materials provided with the distribution. +** 3. Neither the name of Ac6 nor the names of its contributors +** may be used to endorse or promote products derived from this software +** without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ***************************************************************************** */ @@ -32,7 +52,7 @@ ENTRY(Reset_Handler) /* Highest address of the user mode stack */ -_estack = 0x20020000; /* end of RAM */ +_estack = 0x20000000 + LD_MAX_DATA_SIZE; /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ @@ -40,9 +60,9 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K +FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET } /* Define output sections */ @@ -57,7 +77,7 @@ SECTIONS } >FLASH /* The program code and other data goes into FLASH */ - .text ALIGN(8): + .text ALIGN(4): { . = ALIGN(4); *(.text) /* .text sections (code) */ @@ -164,12 +184,12 @@ SECTIONS /* User_heap_stack section, used to check that there is enough RAM left */ ._user_heap_stack : { - . = ALIGN(8); + . = ALIGN(4); PROVIDE ( end = . ); PROVIDE ( _end = . ); . = . + _Min_Heap_Size; . = . + _Min_Stack_Size; - . = ALIGN(8); + . = ALIGN(4); } >RAM /* Remove information from the standard libraries */ diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.cpp b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.cpp index 66190c629df9..e78718c8a64a 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.cpp +++ b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.cpp @@ -28,12 +28,13 @@ ******************************************************************************* */ -#include "variant.h" +#include "pins_arduino.h" #ifdef __cplusplus extern "C" { #endif +#if defined(ARDUINO_BLACK_F407VE) || defined(ARDUINO_BLACK_F407VG) // Pin number // This array allows to wrap Arduino pin number(Dx or x) // to STM32 PinName (PX_n) @@ -93,23 +94,98 @@ const PinName digitalPin[] = { PB_13, PB_14, PB_4, }; +#endif // ARDUINO_BLACK_F407VE || ARDUINO_BLACK_F407VG + +#if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) +const PinName digitalPin[] = { + // Left Side + //Ext //Int + //GND //5V + //GND //3V3 + PB_12, PB_13, + PB_14, PB_15, + PD_8, PD_9, + PD_10, PD_11, + PD_12, PD_13, + PD_14, PD_15, + PG_2, PG_3, + PG_4, PG_5, + PG_6, PG_7, + PG_8, PC_6, + PC_7, PC_8, + PC_9, PA_8, + PA_9, PA_10, + PA_11, PA_12, // PA_11: USB_DM, PA_12: USB_DP + PA_13, PA_14, + PA_15, PC_10, + PC_11, PC_12, + PD_0, PD_1, + PD_2, PD_3, + PD_4, PD_5, + PD_6, PD_7, + PG_9, PG_10, + PG_11, PG_12, + PG_13, PG_14, + PG_15, PB_3, + PB_4, PB_5, + PB_6, PB_7, + PB_8, PB_9, + + // Right Side + //Int //Ext + //3V3 //3V3 + //BOOT1 //BOOT0 + //GND //GND + //VREF+ //GND + PB_10, PB_11, + PE_14, PE_15, + PE_12, PE_13, + PE_10, PE_11, + PE_8, PE_9, + PG_1, PE_7, + PF_15, PG_0, + PF_13, PF_14, + PF_11, PF_12, + PB_2, // PB1 PB2 Inverted to allow contiguous analog pins + PB_1, + PC_5, PB_0, + PA_7, PC_4, + PA_5, PA_6, + PA_3, PA_4, + PA_1, PA_2, + PC_3, PA_0, // PA_0(WK_UP): BUT K_UP) + PC_1, PC_2, + /*PF_10,*/PC_0, // PF_10: Moved to allow contiguous analog pins + PF_8, /*PF_9,*/ // PF_9: Moved to allow contiguous analog pins + PF_6, PF_7, + PF_10, PF_9, // PF_10: LED D2, PF_9: LED D1 (active low) + PF_4, PF_5, + PF_2, PF_3, + PF_0, PF_1, + PE_6, PC_13, + PE_4, PE_5, // PE_4: BUT K0, PE_5: BUT K1 + PE_2, PE_3, + PE_0, PE_1, +}; +#endif // ARDUINO_BLACK_F407ZE || ARDUINO_BLACK_F407ZG #ifdef __cplusplus } #endif -// ------------------------ +// ---------------------------------------------------------------------------- #ifdef __cplusplus extern "C" { #endif - /** +/** * @brief System Clock Configuration * @param None * @retval None */ -WEAK void SystemClock_Config() { +WEAK void SystemClock_Config(void) +{ RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.h b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.h index c0a29322f3ec..4e7e299f1c86 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.h +++ b/buildroot/share/PlatformIO/variants/MARLIN_F407VE/variant.h @@ -27,12 +27,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ -#pragma once +#ifndef _VARIANT_ARDUINO_STM32_ +#define _VARIANT_ARDUINO_STM32_ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ -#include #ifdef __cplusplus extern "C" { @@ -41,7 +41,7 @@ extern "C" { /*---------------------------------------------------------------------------- * Pins *----------------------------------------------------------------------------*/ -extern const PinName digitalPin[]; +#if defined(ARDUINO_BLACK_F407VE) || defined(ARDUINO_BLACK_F407VG) // Right Side #define PE1 0 #define PE0 1 @@ -133,9 +133,9 @@ extern const PinName digitalPin[]; //#define DACC_RESOLUTION 12 // PWM resolution -#define PWM_RESOLUTION 8 -#define PWM_FREQUENCY 20000 -#define PWM_MAX_DUTY_CYCLE 255 +//#define PWM_RESOLUTION 8 +//#define PWM_FREQUENCY 20000 +//#define PWM_MAX_DUTY_CYCLE 255 // On-board LED pin number #define LED_D2 PA6 @@ -144,6 +144,138 @@ extern const PinName digitalPin[]; // Board specific button #define BTN_K_UP PA0 +#endif // ARDUINO_BLACK_F407VE || ARDUINO_BLACK_F407VG + +#if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) +// Left Side +#define PB12 0 +#define PB13 1 +#define PB14 2 +#define PB15 3 +#define PD8 4 +#define PD9 5 +#define PD10 6 +#define PD11 7 +#define PD12 8 +#define PD13 9 +#define PD14 10 +#define PD15 11 +#define PG2 12 +#define PG3 13 +#define PG4 14 +#define PG5 15 +#define PG6 16 +#define PG7 17 +#define PG8 18 +#define PC6 19 +#define PC7 20 +#define PC8 21 +#define PC9 22 +#define PA8 23 +#define PA9 24 +#define PA10 25 +#define PA11 26 // USB_DM +#define PA12 27 // USB_DP +#define PA13 28 +#define PA14 29 +#define PA15 30 +#define PC10 31 +#define PC11 32 +#define PC12 33 +#define PD0 34 +#define PD1 35 +#define PD2 36 +#define PD3 37 +#define PD4 38 +#define PD5 39 +#define PD6 40 +#define PD7 41 +#define PG9 42 +#define PG10 43 +#define PG11 44 +#define PG12 45 +#define PG13 46 +#define PG14 47 +#define PG15 48 +#define PB3 49 +#define PB4 50 +#define PB5 51 +#define PB6 52 +#define PB7 53 +#define PB8 54 +#define PB9 55 + +// Right Side +#define PB10 56 +#define PB11 57 +#define PE14 58 +#define PE15 59 +#define PE12 60 +#define PE13 61 +#define PE10 62 +#define PE11 63 +#define PE8 64 +#define PE9 65 +#define PG1 66 +#define PE7 67 +#define PF15 68 +#define PG0 69 +#define PF13 70 +#define PF14 71 +#define PF11 72 +#define PF12 73 +#define PB2 74 +#define PB1 75 // A0 +#define PC5 76 // A1 +#define PB0 77 // A2 +#define PA7 78 // A3 +#define PC4 79 // A4 +#define PA5 80 // A5 +#define PA6 81 // A6 +#define PA3 82 // A7 +#define PA4 83 // A8 +#define PA1 84 // A9 +#define PA2 85 // A10 +#define PC3 86 // A11 +#define PA0 87 // A12/PA_0(WK_UP): BUT K_UP) +#define PC1 88 // A13 +#define PC2 89 // A14 +#define PC0 90 // A15 +#define PF8 91 // A16 +#define PF6 92 // A17 +#define PF7 93 // A18 +#define PF9 94 // LED D1 (active low) +#define PF10 95 // LED D2 (active low) +#define PF4 96 +#define PF5 97 +#define PF2 98 +#define PF3 99 +#define PF0 100 +#define PF1 101 +#define PE6 102 +#define PC13 103 +#define PE4 104 // BUT K0 +#define PE5 105 // BUT K1 +#define PE2 106 +#define PE3 107 +#define PE0 108 +#define PE1 109 + +// This must be a literal +#define NUM_DIGITAL_PINS 110 +// This must be a literal with a value less than or equal to MAX_ANALOG_INPUTS +#define NUM_ANALOG_INPUTS 19 +#define NUM_ANALOG_FIRST 75 + +// On-board LED pin number +#define LED_D2 PF10 +#define LED_D1 PF9 + +// Board specific button +#define BTN_WK_UP PA0 + +#endif // ARDUINO_BLACK_F407ZE || ARDUINO_BLACK_F407ZG + #define LED_BUILTIN LED_D2 #define LED_GREEN LED_D2 @@ -187,6 +319,10 @@ extern const PinName digitalPin[]; #define PIN_SERIAL_RX PA10 #define PIN_SERIAL_TX PA9 +/* Extra HAL modules */ +#define HAL_DAC_MODULE_ENABLED +#define HAL_SD_MODULE_ENABLED + #ifdef __cplusplus } // extern "C" #endif @@ -213,3 +349,5 @@ extern const PinName digitalPin[]; #define SERIAL_PORT_MONITOR Serial #define SERIAL_PORT_HARDWARE Serial1 #endif + +#endif /* _VARIANT_ARDUINO_STM32_ */ diff --git a/platformio.ini b/platformio.ini index ca08ee3ac771..e31023e01303 100644 --- a/platformio.ini +++ b/platformio.ini @@ -254,7 +254,7 @@ monitor_speed = 250000 # STM32F103RE # [env:STM32F103RE] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103RE build_flags = !python Marlin/src/HAL/HAL_STM32F1/build_flags.py @@ -272,7 +272,7 @@ upload_protocol = stlink # STM32F103RC_fysetc # [env:STM32F103RC_fysetc] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103RC #board_build.core = maple @@ -295,7 +295,7 @@ upload_protocol = serial # BigTree SKR Mini V1.1 / SKR mini E3 / SKR E3 DIP (STM32F103RCT6 ARM Cortex-M3) # [env:STM32F103RC_bigtree] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103RC platform_packages = tool-stm32duino @@ -309,7 +309,7 @@ src_filter = ${common.default_src_filter} + monitor_speed = 115200 [env:STM32F103RC_bigtree_USB] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103RC platform_packages = tool-stm32duino @@ -352,10 +352,10 @@ monitor_speed = 250000 # ARMED (STM32) # [env:ARMED] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = armed_v1 -build_flags = ${common.build_flags} -DUSBCON -DUSBD_VID=0x0483 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="ARMED_V1"' -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC -O2 -ffreestanding -fsigned-char -fno-move-loop-invariants -fno-strict-aliasing -std=gnu11 -std=gnu++11 +build_flags = ${common.build_flags} -DUSBCON -DUSBD_VID=0x0483 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="ARMED_V1"' -DUSBD_USE_CDC -O2 -ffreestanding -fsigned-char -fno-move-loop-invariants -fno-strict-aliasing -std=gnu11 -std=gnu++11 lib_deps = ${common.lib_deps} lib_ignore = Adafruit NeoPixel src_filter = ${common.default_src_filter} + @@ -365,7 +365,7 @@ monitor_speed = 250000 # Longer 3D board in Alfawise U20 (STM32F103VET6) # [env:STM32F103VE_longer] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103VE monitor_speed = 250000 @@ -382,7 +382,7 @@ lib_ignore = Adafruit NeoPixel, LiquidTWI2, SPI # MKS Robin (STM32F103ZET6) # [env:mks_robin] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103ZE extra_scripts = buildroot/share/PlatformIO/scripts/mks_robin.py @@ -397,7 +397,7 @@ lib_ignore = Adafruit NeoPixel, SPI # MKS ROBIN LITE/LITE2 (STM32F103RCT6) # [env:mks_robin_lite] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103RC extra_scripts = buildroot/share/PlatformIO/scripts/mks_robin_lite.py @@ -412,7 +412,7 @@ lib_ignore = Adafruit NeoPixel, SPI # MKS Robin Mini (STM32F103VET6) # [env:mks_robin_mini] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103VE extra_scripts = buildroot/share/PlatformIO/scripts/mks_robin_mini.py @@ -427,7 +427,7 @@ lib_ignore = Adafruit NeoPixel, SPI # MKS Robin Nano (STM32F103VET6) # [env:mks_robin_nano] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103VE extra_scripts = buildroot/share/PlatformIO/scripts/mks_robin_nano.py @@ -442,7 +442,7 @@ lib_ignore = Adafruit NeoPixel, SPI # JGAurora A5S A1 (STM32F103ZET6) # [env:jgaurora_a5s_a1] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103ZE extra_scripts = buildroot/share/PlatformIO/scripts/jgaurora_a5s_a1_with_bootloader.py @@ -460,58 +460,62 @@ monitor_speed = 250000 # Shield - https://github.com/jmz52/Hardware # [env:STM32F407VE_black] -platform = ststm32@5.4.3 -framework = arduino -board = blackSTM32F407VET6 -extra_scripts = pre:buildroot/share/PlatformIO/scripts/black_stm32f407vet6.py -build_flags = ${common.build_flags} - -DSTM32F4 -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"BLACK_F407VE\" -lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel, TMCStepper, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster -src_filter = ${common.default_src_filter} + -monitor_speed = 250000 +platform = ststm32@>=5.7.0 +framework = arduino +platform_packages = framework-arduinoststm32@>=3.10700.191028 +board = blackSTM32F407VET6 +extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py +build_flags = ${common.build_flags} + -DTARGET_STM32F4 -DARDUINO_BLACK_F407VE + -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"BLACK_F407VE\" +lib_deps = ${common.lib_deps} +lib_ignore = Adafruit NeoPixel, TMCStepper, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster +src_filter = ${common.default_src_filter} + +monitor_speed = 250000 # # Bigtreetech SKR Pro (STM32F407ZGT6 ARM Cortex-M4) # [env:BIGTREE_SKR_PRO] -platform = ststm32@5.6.0 -framework = arduino -board = BigTree_SKR_Pro -extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py -build_flags = ${common.build_flags} +platform = ststm32@>=5.7.0 +framework = arduino +platform_packages = framework-arduinoststm32@>=3.10700.191028 +board = BigTree_SKR_Pro +extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py +build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407ZG\" - -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 -DHAVE_HWSERIAL6 -DSS_TIMER=4 -lib_deps = + -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 + -DHAVE_HWSERIAL6 -DSS_TIMER=4 -DFORCE_BAUD_RATE=19200 +lib_deps = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip - LiquidCrystal@1.3.4 + LiquidCrystal TMCStepper@>=0.5.2,<1.0.0 Adafruit NeoPixel LiquidTWI2=https://github.com/lincomatic/LiquidTWI2/archive/master.zip Arduino-L6470=https://github.com/ameyer/Arduino-L6470/archive/dev.zip SoftwareSerialM=https://github.com/sjasonsmith/SoftwareSerialM/archive/SKR_PRO.zip -src_filter = ${common.default_src_filter} + -monitor_speed = 250000 +src_filter = ${common.default_src_filter} + +monitor_speed = 250000 # # BIGTREE_SKR_BTT002 (STM32F407VET6 ARM Cortex-M4) # [env:BIGTREE_BTT002] -platform = ststm32@5.6.0 -framework = arduino -board = BigTree_Btt002 -extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py -build_flags = ${common.build_flags} +platform = ststm32@>=5.7.0 +framework = arduino +platform_packages = framework-arduinoststm32@>=3.10700.191028 +board = BigTree_Btt002 +extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py +build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407VE\" -DTARGET_STM32F4 -DSTM32F407_5VX -DVECT_TAB_OFFSET=0x8000 - -DHAVE_HWSERIAL2 + -DHAVE_HWSERIAL2 -DPIN_SERIAL2_RX=PD_6 -DPIN_SERIAL2_TX=PD_5 -DHAVE_HWSERIAL3 - -DPIN_SERIAL2_RX=PD_6 - -DPIN_SERIAL2_TX=PD_5 -lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster -src_filter = ${common.default_src_filter} + -monitor_speed = 250000 + -DFORCE_BAUD_RATE=19200 +lib_deps = ${common.lib_deps} +lib_ignore = Adafruit NeoPixel, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster +src_filter = ${common.default_src_filter} + +monitor_speed = 250000 # # Teensy 3.1 / 3.2 (ARM Cortex-M4) @@ -531,7 +535,7 @@ monitor_speed = 250000 # Malyan M200 (STM32F103CB) # [env:STM32F103CB_malyan] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = malyanM200 build_flags = !python Marlin/src/HAL/HAL_STM32F1/build_flags.py -DMCU_STM32F103CB -D __STM32F1__=1 -std=c++1y -D MOTHERBOARD="BOARD_MALYAN_M200" -DSERIAL_USB -ffunction-sections -fdata-sections -Wl,--gc-sections @@ -543,7 +547,7 @@ lib_ignore = Adafruit NeoPixel, LiquidCrystal, LiquidTWI2, TMCStepper, U8glib-H # Chitu boards like Tronxy X5s (STM32F103ZET6) # [env:chitu_f103] -platform = ststm32@5.6.0 +platform = ststm32@>=5.7.0 framework = arduino board = genericSTM32F103ZE extra_scripts = buildroot/share/PlatformIO/scripts/chitu_crypt.py From 0a57b7999dab2ca3f6e8aa59600c2a3e4e72f722 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Tue, 5 Nov 2019 17:09:44 +0100 Subject: [PATCH 02/23] Removed unused variable and assert --- buildroot/share/PlatformIO/scripts/generic_create_variant.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/generic_create_variant.py b/buildroot/share/PlatformIO/scripts/generic_create_variant.py index cc43893d09fa..0b82c69f5a3f 100644 --- a/buildroot/share/PlatformIO/scripts/generic_create_variant.py +++ b/buildroot/share/PlatformIO/scripts/generic_create_variant.py @@ -7,9 +7,7 @@ board = env.BoardConfig() FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32") -CMSIS_DIR = os.path.join(FRAMEWORK_DIR, "CMSIS", "CMSIS") assert os.path.isdir(FRAMEWORK_DIR) -assert os.path.isdir(CMSIS_DIR) assert os.path.isdir("buildroot/share/PlatformIO/variants") mcu_type = board.get("build.mcu")[:-2] From b6199f8a6e3af38ef1813498435922f078976365 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Wed, 6 Nov 2019 16:33:24 +0100 Subject: [PATCH 03/23] fix build --- Marlin/src/lcd/menu/menu_bed_corners.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 42ddec8bedaa..f3c3a1d904d0 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -97,13 +97,13 @@ static inline void _lcd_level_bed_corners_homing() { #endif ui.goto_previous_screen_no_defer(); }, - GET_TEXT(( + GET_TEXT( #if ENABLED(LEVEL_CENTER_TOO) MSG_LEVEL_BED_NEXT_POINT #else MSG_NEXT_CORNER #endif - )), (PGM_P)nullptr, PSTR("?") + ), (PGM_P)nullptr, PSTR("?") ); ui.set_selection(true); _lcd_goto_next_corner(); From ccdbb2fd2a790ff19d83e01bbf808f9a6b150c76 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Wed, 6 Nov 2019 16:35:38 +0100 Subject: [PATCH 04/23] Ignore SoftwareSerialM again --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index e31023e01303..fc19832a5ddb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -493,7 +493,7 @@ lib_deps = Adafruit NeoPixel LiquidTWI2=https://github.com/lincomatic/LiquidTWI2/archive/master.zip Arduino-L6470=https://github.com/ameyer/Arduino-L6470/archive/dev.zip - SoftwareSerialM=https://github.com/sjasonsmith/SoftwareSerialM/archive/SKR_PRO.zip +lib_ignore = SoftwareSerialM src_filter = ${common.default_src_filter} + monitor_speed = 250000 From cbea0f82dcece04c04816af116c46445bcd19826 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Wed, 6 Nov 2019 16:40:30 +0100 Subject: [PATCH 05/23] TIM4 in SoftSerial conflicts with PWM output --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index fc19832a5ddb..15520163744d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -485,7 +485,7 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_varian build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407ZG\" -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 - -DHAVE_HWSERIAL6 -DSS_TIMER=4 -DFORCE_BAUD_RATE=19200 + -DHAVE_HWSERIAL6 -DSS_TIMER= -DFORCE_BAUD_RATE=19200 lib_deps = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip LiquidCrystal From 51130444f539adb1d339215c1f32eaf0d0ea74f4 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Wed, 6 Nov 2019 17:43:04 +0100 Subject: [PATCH 06/23] Disable PWM on everything but surely needed --- .../PeripheralPins.c | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c index 2e3a5b8a8a8e..2f68c54e05eb 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c +++ b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c @@ -138,79 +138,79 @@ const PinMap PinMap_I2C_SCL[] = { #ifdef HAL_TIM_MODULE_ENABLED const PinMap PinMap_PWM[] = { - {PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 + //{PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 //{PA_0, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1 - {PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 + //{PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 is bltouch analog? //{PA_1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2 - {PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 + //{PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 is bltouch analog? //{PA_2, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3 //{PA_2, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 - {PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 + //{PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 //{PA_3, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4 //{PA_3, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 - {PA_5, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 + //{PA_5, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 //{PA_5, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N - {PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + //{PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 //{PA_6, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 //{PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N - {PA_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 + //{PA_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 //{PA_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N //{PA_7, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 - {PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 - {PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 - {PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 - {PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 + //{PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 + //{PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 + //{PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 + //{PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 //{PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 //{PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N - {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 + {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 HEATER2 //{PB_0, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N //{PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 + {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 HEATER0 //{PB_1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N //{PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 - {PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 - {PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 + //{PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + //{PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 //{PB_6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 //{PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 //{PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 - {PB_8, TIM10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 + //{PB_8, TIM10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 //{PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 - {PB_9, TIM11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 - {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 - {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 - {PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N - {PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N - {PB_14, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N - {PB_14, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 1, 0)}, // TIM12_CH1 - {PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PB_15, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N - {PB_15, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 2, 0)}, // TIM12_CH2 - {PC_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 - {PC_6, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 - {PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 - {PC_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 + //{PB_9, TIM11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 + //{PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 + //{PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 + //{PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N + //{PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N + //{PB_14, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N + //{PB_14, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 1, 0)}, // TIM12_CH1 + //{PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + //{PB_15, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N + //{PB_15, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 2, 0)}, // TIM12_CH2 + //{PC_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + //{PC_6, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 + //{PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 + //{PC_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 {PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 FAN0 - {PC_8, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 + //{PC_8, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 //{PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 - //{PC_9, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 - {PD_12, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 - {PD_13, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 - {PD_14, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 - {PD_15, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 + {PC_9, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 EXPANSION1-4 + {PD_12, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 BED + //{PD_13, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 + {PD_14, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 HEATER1 + //{PD_15, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 {PE_5, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 FAN1 {PE_6, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 FAN2 - {PE_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N - {PE_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 - {PE_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N - {PE_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 - {PE_12, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PE_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 - {PE_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 + //{PE_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N + //{PE_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 + //{PE_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N + //{PE_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 + //{PE_12, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + //{PE_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 + //{PE_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 #if STM32F4X_PIN_NUM >= 144 //144 pins mcu, 114 gpio - {PF_6, TIM10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 - {PF_7, TIM11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 - {PF_8, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 - {PF_9, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 + //{PF_6, TIM10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 + //{PF_7, TIM11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 + //{PF_8, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 + //{PF_9, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 #endif {NC, NP, 0} }; From 1e215eefab729faff122be6c9f70ce5a1fe313ee Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Wed, 6 Nov 2019 20:55:23 +0100 Subject: [PATCH 07/23] SoftwareSerial Timer = 13 --- .../PeripheralPins.c | 18 ++++++++++-------- platformio.ini | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c index 2f68c54e05eb..63a3a521f609 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c +++ b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c @@ -138,6 +138,16 @@ const PinMap PinMap_I2C_SCL[] = { #ifdef HAL_TIM_MODULE_ENABLED const PinMap PinMap_PWM[] = { + {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 HEATER0 + {PD_14, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 HEATER1 + {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 HEATER2 + {PD_12, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 BED + {PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 FAN0 + {PE_5, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 FAN1 + {PE_6, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 FAN2 + {PC_9, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 EXTENSION1-4 + + //probably unused on SKR-Pro. confirmation needed, please. //{PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 //{PA_0, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1 //{PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 is bltouch analog? @@ -162,10 +172,8 @@ const PinMap PinMap_PWM[] = { //{PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 //{PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 //{PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N - {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 HEATER2 //{PB_0, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N //{PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 HEATER0 //{PB_1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N //{PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 //{PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 @@ -189,16 +197,10 @@ const PinMap PinMap_PWM[] = { //{PC_6, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 //{PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 //{PC_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 - {PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 FAN0 //{PC_8, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 //{PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 - {PC_9, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 EXPANSION1-4 - {PD_12, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 BED //{PD_13, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 - {PD_14, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 HEATER1 //{PD_15, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 - {PE_5, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 FAN1 - {PE_6, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 FAN2 //{PE_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N //{PE_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 //{PE_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N diff --git a/platformio.ini b/platformio.ini index 15520163744d..e0e94f6ac31c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -485,7 +485,7 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_varian build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407ZG\" -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 - -DHAVE_HWSERIAL6 -DSS_TIMER= -DFORCE_BAUD_RATE=19200 + -DHAVE_HWSERIAL6 -DSS_TIMER=13 -DFORCE_BAUD_RATE=19200 lib_deps = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip LiquidCrystal From 6a36af21fd30fb47a87bd087e7354ec8d9bd08ed Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Thu, 7 Nov 2019 02:08:15 -0800 Subject: [PATCH 08/23] Added SoftwareSerial by @sjasonsmith * Add SoftwareSerial to HAL_STM32 * Remove SS_TIMER define from SKR Pro which was only needed for temporary SoftwareSerialM use. --- Marlin/src/HAL/HAL_STM32/HAL.cpp | 4 + Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp | 429 ++++++++++++++++++++ Marlin/src/HAL/HAL_STM32/SoftwareSerial.h | 128 ++++++ Marlin/src/HAL/HAL_STM32/timers.cpp | 26 +- Marlin/src/HAL/HAL_STM32/timers.h | 9 + platformio.ini | 17 +- 6 files changed, 603 insertions(+), 10 deletions(-) create mode 100644 Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp create mode 100644 Marlin/src/HAL/HAL_STM32/SoftwareSerial.h diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp index edc161a5d387..1383495d0b16 100644 --- a/Marlin/src/HAL/HAL_STM32/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp @@ -82,6 +82,10 @@ void HAL_init() { // Wait until backup regulator is initialized while (!LL_PWR_IsActiveFlag_BRR()); #endif // EEPROM_EMULATED_SRAM + + #if HAS_TMC220x + swserial_init(); + #endif } void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); } diff --git a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp new file mode 100644 index 000000000000..6fe174f557c9 --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp @@ -0,0 +1,429 @@ +/* + * SoftwareSerial.cpp (formerly NewSoftSerial.cpp) + * + * Multi-instance software serial library for Arduino/Wiring + * -- Interrupt-driven receive and other improvements by ladyada + * (http://ladyada.net) + * -- Tuning, circular buffer, derivation from class Print/Stream, + * multi-instance support, porting to 8MHz processors, + * various optimizations, PROGMEM delay tables, inverse logic and + * direct port writing by Mikal Hart (http://www.arduiniana.org) + * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) + * -- 20MHz processor support by Garrett Mace (http://www.macetech.com) + * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) + * -- STM32 support by Armin van der Togt + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * The latest version of this library can always be found at + * http://arduiniana.org. + */ + +// +// Includes +// +#include "SoftwareSerial.h" +#include + +#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge). + +// defined in bit-periods +#define HALFDUPLEX_SWITCH_DELAY 5 +// It's best to define TIMER_SERIAL in variant.h. If not defined, we choose one here +// The order is based on (lack of) features and compare channels, we choose the simplest available +// because we only need an update interrupt +#if !defined(TIMER_SERIAL) +#if defined (TIM18_BASE) +#define TIMER_SERIAL TIM18 +#elif defined (TIM7_BASE) +#define TIMER_SERIAL TIM7 +#elif defined (TIM6_BASE) +#define TIMER_SERIAL TIM6 +#elif defined (TIM22_BASE) +#define TIMER_SERIAL TIM22 +#elif defined (TIM21_BASE) +#define TIMER_SERIAL TIM21 +#elif defined (TIM17_BASE) +#define TIMER_SERIAL TIM17 +#elif defined (TIM16_BASE) +#define TIMER_SERIAL TIM16 +#elif defined (TIM15_BASE) +#define TIMER_SERIAL TIM15 +#elif defined (TIM14_BASE) +#define TIMER_SERIAL TIM14 +#elif defined (TIM13_BASE) +#define TIMER_SERIAL TIM13 +#elif defined (TIM11_BASE) +#define TIMER_SERIAL TIM11 +#elif defined (TIM10_BASE) +#define TIMER_SERIAL TIM10 +#elif defined (TIM12_BASE) +#define TIMER_SERIAL TIM12 +#elif defined (TIM19_BASE) +#define TIMER_SERIAL TIM19 +#elif defined (TIM9_BASE) +#define TIMER_SERIAL TIM9 +#elif defined (TIM5_BASE) +#define TIMER_SERIAL TIM5 +#elif defined (TIM4_BASE) +#define TIMER_SERIAL TIM4 +#elif defined (TIM3_BASE) +#define TIMER_SERIAL TIM3 +#elif defined (TIM2_BASE) +#define TIMER_SERIAL TIM2 +#elif defined (TIM20_BASE) +#define TIMER_SERIAL TIM20 +#elif defined (TIM8_BASE) +#define TIMER_SERIAL TIM8 +#elif defined (TIM1_BASE) +#define TIMER_SERIAL TIM1 +#else +#error No suitable timer found for SoftwareSerial, define TIMER_SERIAL in variant.h +#endif +#endif +// +// Statics +// +HardwareTimer SoftwareSerial::timer(TIMER_SERIAL); +const IRQn_Type SoftwareSerial::timer_interrupt_number = static_cast(getTimerUpIrq(TIMER_SERIAL)); +uint32_t SoftwareSerial::timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), TIM_IRQ_PRIO, TIM_IRQ_SUBPRIO); +SoftwareSerial *SoftwareSerial::active_listener = nullptr; +SoftwareSerial *volatile SoftwareSerial::active_out = nullptr; +SoftwareSerial *volatile SoftwareSerial::active_in = nullptr; +int32_t SoftwareSerial::tx_tick_cnt = 0; // OVERSAMPLE ticks needed for a bit +int32_t volatile SoftwareSerial::rx_tick_cnt = 0; // OVERSAMPLE ticks needed for a bit +uint32_t SoftwareSerial::tx_buffer = 0; +int32_t SoftwareSerial::tx_bit_cnt = 0; +uint32_t SoftwareSerial::rx_buffer = 0; +int32_t SoftwareSerial::rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit +uint32_t SoftwareSerial::cur_speed = 0; + +void SoftwareSerial::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) +{ + timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preemptPriority, subPriority); +} + +// +// Private methods +// + +void SoftwareSerial::setSpeed(uint32_t speed) +{ + if (speed != cur_speed) { + timer.pause(); + if (speed != 0) { + // Disable the timer + uint32_t clock_rate, cmp_value; + // Get timer clock + clock_rate = timer.getTimerClkFreq(); + int pre = 1; + // Calculate prescale an compare value + do { + cmp_value = clock_rate / (speed * OVERSAMPLE); + if (cmp_value >= UINT16_MAX) { + clock_rate = clock_rate / 2; + pre *= 2; + } + } while (cmp_value >= UINT16_MAX); + timer.setPrescaleFactor(pre); + timer.setOverflow(cmp_value); + timer.setCount(0); + timer.attachInterrupt(&handleInterrupt); + timer.resume(); + NVIC_SetPriority(timer_interrupt_number, timer_interrupt_priority); + } else { + timer.detachInterrupt(); + } + cur_speed = speed; + } +} + +// This function sets the current object as the "listening" +// one and returns true if it replaces another +bool SoftwareSerial::listen() +{ + if (active_listener != this) { + // wait for any transmit to complete as we may change speed + while (active_out); + active_listener->stopListening(); + rx_tick_cnt = 1; // 1 : next interrupt will decrease rx_tick_cnt to 0 which means RX pin level will be considered. + rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit + setSpeed(_speed); + active_listener = this; + if (!_half_duplex) { + active_in = this; + } + return true; + } + return false; +} + +// Stop listening. Returns true if we were actually listening. +bool SoftwareSerial::stopListening() +{ + if (active_listener == this) { + // wait for any output to complete + while (active_out); + if (_half_duplex) { + setRXTX(false); + } + active_listener = nullptr; + active_in = nullptr; + // turn off ints + setSpeed(0); + return true; + } + return false; +} + +inline void SoftwareSerial::setTX() +{ + if (_inverse_logic) { + LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber); + } else { + LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber); + } + pinMode(_transmitPin, OUTPUT); +} + +inline void SoftwareSerial::setRX() +{ + pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic! +} + +inline void SoftwareSerial::setRXTX(bool input) +{ + if (_half_duplex) { + if (input) { + if (active_in != this) { + setRX(); + rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit + rx_tick_cnt = 2; // 2 : next interrupt will be discarded. 2 interrupts required to consider RX pin level + active_in = this; + } + } else { + if (active_in == this) { + setTX(); + active_in = nullptr; + } + } + } +} + +inline void SoftwareSerial::send() +{ + if (--tx_tick_cnt <= 0) { // if tx_tick_cnt > 0 interrupt is discarded. Only when tx_tick_cnt reach 0 we set TX pin. + if (tx_bit_cnt++ < 10) { // tx_bit_cnt < 10 transmission is not fiisehed (10 = 1 start +8 bits + 1 stop) + // send data (including start and stop bits) + if (tx_buffer & 1) { + LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber); + } else { + LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber); + } + tx_buffer >>= 1; + tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE tick to send next bit + } else { // Transmission finished + tx_tick_cnt = 1; + if (_output_pending) { + active_out = nullptr; + + // When in half-duplex mode, wait for HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has + // been transmitted before allowing the switch to RX mode + } else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) { + if (_half_duplex && active_listener == this) { + setRXTX(true); + } + active_out = nullptr; + } + } + } +} + +// +// The receive routine called by the interrupt handler +// +inline void SoftwareSerial::recv() +{ + if (--rx_tick_cnt <= 0) { // if rx_tick_cnt > 0 interrupt is discarded. Only when rx_tick_cnt reach 0 RX pin is considered + bool inbit = LL_GPIO_IsInputPinSet(_receivePinPort, _receivePinNumber) ^ _inverse_logic; + if (rx_bit_cnt == -1) { // rx_bit_cnt = -1 : waiting for start bit + if (!inbit) { + // got start bit + rx_bit_cnt = 0; // rx_bit_cnt == 0 : start bit received + rx_tick_cnt = OVERSAMPLE + 1; // Wait 1 bit (OVERSAMPLE ticks) + 1 tick in order to sample RX pin in the middle of the edge (and not too close to the edge) + rx_buffer = 0; + } else { + rx_tick_cnt = 1; // Waiting for start bit, but we don't get right level. Wait for next Interrupt to ckech RX pin level + } + } else if (rx_bit_cnt >= 8) { // rx_bit_cnt >= 8 : waiting for stop bit + if (inbit) { + // stop bit read complete add to buffer + uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF; + if (next != _receive_buffer_head) { + // save new data in buffer: tail points to where byte goes + _receive_buffer[_receive_buffer_tail] = rx_buffer; // save new byte + _receive_buffer_tail = next; + } else { // rx_bit_cnt = x with x = [0..7] correspond to new bit x received + _buffer_overflow = true; + } + } + // Full trame received. Resart wainting for sart bit at next interrupt + rx_tick_cnt = 1; + rx_bit_cnt = -1; + } else { + // data bits + rx_buffer >>= 1; + if (inbit) { + rx_buffer |= 0x80; + } + rx_bit_cnt++; // Preprare for next bit + rx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks before sampling next bit + } + } +} + +// +// Interrupt handling +// + +/* static */ +inline void SoftwareSerial::handleInterrupt(HardwareTimer *timer) +{ + UNUSED(timer); + if (active_in) { + active_in->recv(); + } + if (active_out) { + active_out->send(); + } +} +// +// Constructor +// +SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic /* = false */) : + _receivePin(receivePin), + _transmitPin(transmitPin), + _receivePinPort(digitalPinToPort(receivePin)), + _receivePinNumber(STM_LL_GPIO_PIN(digitalPinToPinName(receivePin))), + _transmitPinPort(digitalPinToPort(transmitPin)), + _transmitPinNumber(STM_LL_GPIO_PIN(digitalPinToPinName(transmitPin))), + _speed(0), + _buffer_overflow(false), + _inverse_logic(inverse_logic), + _half_duplex(receivePin == transmitPin), + _output_pending(0), + _receive_buffer_tail(0), + _receive_buffer_head(0) +{ + if ((receivePin < NUM_DIGITAL_PINS) || (transmitPin < NUM_DIGITAL_PINS)) { + /* Enable GPIO clock for tx and rx pin*/ + set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin))); + set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin))); + } else { + _Error_Handler("ERROR: invalid pin number\n", -1); + } +} + +// +// Destructor +// +SoftwareSerial::~SoftwareSerial() +{ + end(); +} + +// +// Public methods +// + +void SoftwareSerial::begin(long speed) +{ +#ifdef FORCE_BAUD_RATE + speed = FORCE_BAUD_RATE; +#endif + _speed = speed; + if (!_half_duplex) { + setTX(); + setRX(); + listen(); + } else { + setTX(); + } +} + +void SoftwareSerial::end() +{ + stopListening(); +} + +// Read data from buffer +int SoftwareSerial::read() +{ + // Empty buffer? + if (_receive_buffer_head == _receive_buffer_tail) { + return -1; + } + + // Read from "head" + uint8_t d = _receive_buffer[_receive_buffer_head]; // grab next byte + _receive_buffer_head = (_receive_buffer_head + 1) % _SS_MAX_RX_BUFF; + return d; +} + +int SoftwareSerial::available() +{ + return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; +} + +size_t SoftwareSerial::write(uint8_t b) +{ + // wait for previous transmit to complete + _output_pending = 1; + while (active_out) + ; + // add start and stop bits. + tx_buffer = b << 1 | 0x200; + if (_inverse_logic) { + tx_buffer = ~tx_buffer; + } + tx_bit_cnt = 0; + tx_tick_cnt = OVERSAMPLE; + setSpeed(_speed); + if (_half_duplex) { + setRXTX(false); + } + _output_pending = 0; + // make us active + active_out = this; + return 1; +} + +void SoftwareSerial::flush() +{ + noInterrupts(); + _receive_buffer_head = _receive_buffer_tail = 0; + interrupts(); +} + +int SoftwareSerial::peek() +{ + // Empty buffer? + if (_receive_buffer_head == _receive_buffer_tail) { + return -1; + } + + // Read from "head" + return _receive_buffer[_receive_buffer_head]; +} diff --git a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h new file mode 100644 index 000000000000..45b0c03c9fd2 --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h @@ -0,0 +1,128 @@ +/* + * SoftwareSerial.h (formerly NewSoftSerial.h) + * + * Multi-instance software serial library for Arduino/Wiring + * -- Interrupt-driven receive and other improvements by ladyada + * (http://ladyada.net) + * -- Tuning, circular buffer, derivation from class Print/Stream, + * multi-instance support, porting to 8MHz processors, + * various optimizations, PROGMEM delay tables, inverse logic and + * direct port writing by Mikal Hart (http://www.arduiniana.org) + * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) + * -- 20MHz processor support by Garrett Mace (http://www.macetech.com) + * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * The latest version of this library can always be found at + * http://arduiniana.org. + */ + +#ifndef SOFTWARESERIAL_H +#define SOFTWARESERIAL_H + +#include + +/****************************************************************************** +* Definitions +******************************************************************************/ + +#define _SS_MAX_RX_BUFF 64 // RX buffer size + +class SoftwareSerial : public Stream { + private: + // per object data + uint16_t _receivePin; + uint16_t _transmitPin; + GPIO_TypeDef *_receivePinPort; + uint32_t _receivePinNumber; + GPIO_TypeDef *_transmitPinPort; + uint32_t _transmitPinNumber; + uint32_t _speed; + + uint16_t _buffer_overflow: 1; + uint16_t _inverse_logic: 1; + uint16_t _half_duplex: 1; + uint16_t _output_pending: 1; + + unsigned char _receive_buffer[_SS_MAX_RX_BUFF]; + volatile uint8_t _receive_buffer_tail; + volatile uint8_t _receive_buffer_head; + + uint32_t delta_start = 0; + + // static data + static bool initialised; + static HardwareTimer timer; + static const IRQn_Type timer_interrupt_number; + static uint32_t timer_interrupt_priority; + static SoftwareSerial *active_listener; + static SoftwareSerial *volatile active_out; + static SoftwareSerial *volatile active_in; + static int32_t tx_tick_cnt; + static volatile int32_t rx_tick_cnt; + static uint32_t tx_buffer; + static int32_t tx_bit_cnt; + static uint32_t rx_buffer; + static int32_t rx_bit_cnt; + static uint32_t cur_speed; + + // private methods + void send(); + void recv(); + void setTX(); + void setRX(); + void setSpeed(uint32_t speed); + void setRXTX(bool input); + static void handleInterrupt(HardwareTimer *timer); + + public: + // public methods + + SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic = false); + virtual ~SoftwareSerial(); + void begin(long speed); + bool listen(); + void end(); + bool isListening() + { + return active_listener == this; + } + bool stopListening(); + bool overflow() + { + bool ret = _buffer_overflow; + if (ret) { + _buffer_overflow = false; + } + return ret; + } + int peek(); + + virtual size_t write(uint8_t byte); + virtual int read(); + virtual int available(); + virtual void flush(); + operator bool() + { + return true; + } + + static void setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority); + + using Print::write; +}; + +#endif // SOFTWARESERIAL_H diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index a152e6d763fa..d9440b517080 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -26,6 +26,10 @@ #include "timers.h" +#if HAS_TMC220x + #include +#endif + // ------------------------ // Local defines // ------------------------ @@ -72,8 +76,6 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); //the -1 is done internally timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE) /* /frequency */), TICK_FORMAT); timer_instance[timer_num]->attachInterrupt(Step_Handler); // Called on rollover - - // IRQ priority is left unchanged for SoftSerial compatibility break; case TEMP_TIMER_NUM: // TEMP TIMER - any available 16bit timer timer_instance[timer_num] = new HardwareTimer(TEMP_TIMER_DEV); @@ -91,8 +93,17 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) { timer_instance[timer_num]->resume(); // Resume the timer to start receiving the interrupt // HardwareTimer::resume() reinits the timer, resetting the priority. Set again. - if (timer_num == TEMP_TIMER_NUM) - HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TIM_IRQ_PRIO + 1, 0); //default+1 + // This is fixed in Arduino_Core_STM32 1.8. These calls can be removed, and replaced + // timer_instance[timer_num]->setInterruptPriority one time in HAL_timer_start. + switch (timer_num) { + case STEP_TIMER_NUM: + HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_PRIORITY, 0); + break; + + case TEMP_TIMER_NUM: + HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_PRIORITY, 0); + break; + } } } @@ -117,4 +128,11 @@ TIM_TypeDef * HAL_timer_device(const uint8_t timer_num) { return nullptr; } +#if HAS_TMC220x + void swserial_init() + { + SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_PRIORITY, 0); + } +#endif + #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/HAL_STM32/timers.h b/Marlin/src/HAL/HAL_STM32/timers.h index 66ccf2bb749c..ad4823655991 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.h +++ b/Marlin/src/HAL/HAL_STM32/timers.h @@ -33,6 +33,10 @@ #define hal_timer_t uint32_t #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit +#define SWSERIAL_TIMER_PRIORITY 0 +#define STEP_TIMER_PRIORITY 1 +#define TEMP_TIMER_PRIORITY 8 + #ifdef STM32F0xx #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals @@ -69,6 +73,7 @@ #define TEMP_TIMER 14 #endif + // TIM7 is consumed by Software Serial if used. #endif #define STEP_TIMER_NUM 0 // index of timer to use for stepper @@ -143,3 +148,7 @@ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const ha #define HAL_timer_isr_prologue(TIMER_NUM) #define HAL_timer_isr_epilogue(TIMER_NUM) + +#if HAS_TMC220x + void swserial_init(); +#endif diff --git a/platformio.ini b/platformio.ini index 3bfc63119851..5b7f5af2ab79 100644 --- a/platformio.ini +++ b/platformio.ini @@ -355,9 +355,12 @@ monitor_speed = 250000 platform = ststm32@>=5.7.0 framework = arduino board = armed_v1 -build_flags = ${common.build_flags} -DUSBCON -DUSBD_VID=0x0483 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="ARMED_V1"' -DUSBD_USE_CDC -O2 -ffreestanding -fsigned-char -fno-move-loop-invariants -fno-strict-aliasing -std=gnu11 -std=gnu++11 +build_flags = + ${common.build_flags} -DUSBCON -DUSBD_VID=0x0483 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="ARMED_V1"' -DUSBD_USE_CDC + -O2 -ffreestanding -fsigned-char -fno-move-loop-invariants -fno-strict-aliasing -std=gnu11 -std=gnu++11 + -IMarlin/src/HAL/HAL_STM32 lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel +lib_ignore = Adafruit NeoPixel, SoftwareSerial src_filter = ${common.default_src_filter} + monitor_speed = 250000 @@ -468,8 +471,9 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_varian build_flags = ${common.build_flags} -DTARGET_STM32F4 -DARDUINO_BLACK_F407VE -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"BLACK_F407VE\" + -IMarlin/src/HAL/HAL_STM32 lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel, TMCStepper, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster +lib_ignore = Adafruit NeoPixel, TMCStepper, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster, SoftwareSerial src_filter = ${common.default_src_filter} + monitor_speed = 250000 @@ -485,7 +489,7 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_varian build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407ZG\" -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 - -DHAVE_HWSERIAL6 -DSS_TIMER=13 -DFORCE_BAUD_RATE=19200 + -DHAVE_HWSERIAL6 -DFORCE_BAUD_RATE=19200 lib_deps = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip LiquidCrystal @@ -493,7 +497,7 @@ lib_deps = Adafruit NeoPixel LiquidTWI2=https://github.com/lincomatic/LiquidTWI2/archive/master.zip Arduino-L6470=https://github.com/ameyer/Arduino-L6470/archive/dev.zip -lib_ignore = SoftwareSerialM +lib_ignore = SoftwareSerial src_filter = ${common.default_src_filter} + monitor_speed = 250000 @@ -512,8 +516,9 @@ build_flags = ${common.build_flags} -DHAVE_HWSERIAL2 -DPIN_SERIAL2_RX=PD_6 -DPIN_SERIAL2_TX=PD_5 -DHAVE_HWSERIAL3 -DFORCE_BAUD_RATE=19200 + -IMarlin/src/HAL/HAL_STM32 lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster +lib_ignore = Adafruit NeoPixel, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster, SoftwareSerial src_filter = ${common.default_src_filter} + monitor_speed = 250000 From 9e5d85c8955b45bf765de78f0623a0d1e832ae98 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Thu, 7 Nov 2019 14:04:55 +0100 Subject: [PATCH 09/23] Modify @sjasonsmith 's implementation --- Marlin/src/HAL/HAL_STM32/HAL.cpp | 14 ++++++++++++-- Marlin/src/HAL/HAL_STM32/timers.cpp | 11 ----------- Marlin/src/HAL/HAL_STM32/timers.h | 10 +++------- .../BIGTREE_GENERIC_STM32F407_5X/variant.h | 1 + platformio.ini | 3 ++- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp index 1383495d0b16..4a2644051195 100644 --- a/Marlin/src/HAL/HAL_STM32/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp @@ -28,6 +28,16 @@ #include "../../inc/MarlinConfig.h" #include "../shared/Delay.h" +#if (__cplusplus == 201703L) && defined(__has_include) + #define HAS_SOFTSERIAL __has_include() +#else + #define HAS_SOFTSERIAL HAS_TMC220x +#endif + +#if HAS_SOFTSERIAL + #include "SoftwareSerial.h" +#endif + #if ENABLED(SRAM_EEPROM_EMULATION) #if STM32F7xx #include "stm32f7xx_ll_pwr.h" @@ -83,8 +93,8 @@ void HAL_init() { while (!LL_PWR_IsActiveFlag_BRR()); #endif // EEPROM_EMULATED_SRAM - #if HAS_TMC220x - swserial_init(); + #if HAS_SOFTSERIAL + SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_PRIORITY, 0); #endif } diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index d9440b517080..db737453bcdb 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -26,10 +26,6 @@ #include "timers.h" -#if HAS_TMC220x - #include -#endif - // ------------------------ // Local defines // ------------------------ @@ -128,11 +124,4 @@ TIM_TypeDef * HAL_timer_device(const uint8_t timer_num) { return nullptr; } -#if HAS_TMC220x - void swserial_init() - { - SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_PRIORITY, 0); - } -#endif - #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/HAL_STM32/timers.h b/Marlin/src/HAL/HAL_STM32/timers.h index ad4823655991..094a4ced191b 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.h +++ b/Marlin/src/HAL/HAL_STM32/timers.h @@ -33,9 +33,9 @@ #define hal_timer_t uint32_t #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit -#define SWSERIAL_TIMER_PRIORITY 0 -#define STEP_TIMER_PRIORITY 1 -#define TEMP_TIMER_PRIORITY 8 +#define SWSERIAL_TIMER_PRIORITY 1 +#define STEP_TIMER_PRIORITY 2 +#define TEMP_TIMER_PRIORITY 14 #ifdef STM32F0xx @@ -148,7 +148,3 @@ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const ha #define HAL_timer_isr_prologue(TIMER_NUM) #define HAL_timer_isr_epilogue(TIMER_NUM) - -#if HAS_TMC220x - void swserial_init(); -#endif diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h index e138ab8e131e..2e70f8a303db 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h +++ b/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h @@ -247,6 +247,7 @@ extern "C" { // Timer Definitions //Do not use timer used by PWM pins when possible. See PinMap_PWM in PeripheralPins.c #define TIMER_TONE TIM6 +#define TIMER_SERIAL TIM7 // Do not use basic timer: OC is required #define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work diff --git a/platformio.ini b/platformio.ini index 5b7f5af2ab79..13a3d60c5dcc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -490,6 +490,7 @@ build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407ZG\" -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 -DHAVE_HWSERIAL6 -DFORCE_BAUD_RATE=19200 + -IMarlin/src/HAL/HAL_STM32 lib_deps = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip LiquidCrystal @@ -497,7 +498,7 @@ lib_deps = Adafruit NeoPixel LiquidTWI2=https://github.com/lincomatic/LiquidTWI2/archive/master.zip Arduino-L6470=https://github.com/ameyer/Arduino-L6470/archive/dev.zip -lib_ignore = SoftwareSerial +lib_ignore = SoftwareSerial, SoftwareSerialM src_filter = ${common.default_src_filter} + monitor_speed = 250000 From fd7fb517eda70744fd8942ddabf820b1dfd2ba09 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Thu, 7 Nov 2019 15:04:22 +0100 Subject: [PATCH 10/23] Faster force update (test) --- Marlin/src/HAL/HAL_STM32/timers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/timers.h b/Marlin/src/HAL/HAL_STM32/timers.h index 094a4ced191b..d85c7e217289 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.h +++ b/Marlin/src/HAL/HAL_STM32/timers.h @@ -124,7 +124,7 @@ void HAL_timer_enable_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); -//TIM_TypeDef * HAL_timer_device(const uint8_t timer_num); no need to be public for now. not public = not used externally +TIM_TypeDef* HAL_timer_device(const uint8_t timer_num); //no need to be public for now. not public = not used externally // FORCE_INLINE because these are used in performance-critical situations FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) { @@ -142,7 +142,7 @@ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const ha // wiki: "force all registers (Autoreload, prescaler, compare) to be taken into account" // So, if the new overflow value is less than the count it will trigger a rollover interrupt. if (overflow < timer_instance[timer_num]->getCount()) // Added 'if' here because reports say it won't boot without it - timer_instance[timer_num]->refresh(); + HAL_timer_device(timer_num)->EGR |= TIM_EGR_UG; } } From 14e880d314bae1e15473f6912e325c4e63398ea5 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Thu, 7 Nov 2019 20:22:03 +0100 Subject: [PATCH 11/23] Revert changes to BTT002 for now. Since it hasn't been released yet and we need the pinout we don't care. When the board will be documented we'll see how to integrate it properly --- .travis.yml | 2 +- .../PlatformIO/boards/BigTree_Btt002.json | 6 ++--- .../PlatformIO/boards/BigTree_SKR_Pro.json | 6 ++--- .../PeripheralPins.c | 0 .../PinNamesVar.h | 0 .../ldscript.ld | 0 .../variant.cpp | 0 .../variant.h | 0 platformio.ini | 25 +++++++++---------- 9 files changed, 17 insertions(+), 22 deletions(-) rename buildroot/share/PlatformIO/variants/{BIGTREE_GENERIC_STM32F407_5X => BIGTREE_SKR_PRO_1v1}/PeripheralPins.c (100%) rename buildroot/share/PlatformIO/variants/{BIGTREE_GENERIC_STM32F407_5X => BIGTREE_SKR_PRO_1v1}/PinNamesVar.h (100%) rename buildroot/share/PlatformIO/variants/{BIGTREE_GENERIC_STM32F407_5X => BIGTREE_SKR_PRO_1v1}/ldscript.ld (100%) rename buildroot/share/PlatformIO/variants/{BIGTREE_GENERIC_STM32F407_5X => BIGTREE_SKR_PRO_1v1}/variant.cpp (100%) rename buildroot/share/PlatformIO/variants/{BIGTREE_GENERIC_STM32F407_5X => BIGTREE_SKR_PRO_1v1}/variant.h (100%) diff --git a/.travis.yml b/.travis.yml index da11e0a53e58..dec65af7db86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,6 @@ env: - TEST_PLATFORM="jgaurora_a5s_a1" - TEST_PLATFORM="STM32F103VE_longer" - TEST_PLATFORM="STM32F407VE_black" - - TEST_PLATFORM="BIGTREE_BTT002" - TEST_PLATFORM="BIGTREE_SKR_PRO" - TEST_PLATFORM="mks_robin" - TEST_PLATFORM="ARMED" @@ -42,6 +41,7 @@ env: - TEST_PLATFORM="LPC1769" # Non-working environment tests + #- TEST_PLATFORM="BIGTREE_BTT002" this board isn't released yet. we need pinout to be sure about what we do #- TEST_PLATFORM="at90usb1286_cdc" #- TEST_PLATFORM="at90usb1286_dfu" #- TEST_PLATFORM="STM32F103CB_malyan" diff --git a/buildroot/share/PlatformIO/boards/BigTree_Btt002.json b/buildroot/share/PlatformIO/boards/BigTree_Btt002.json index d325747ef73f..976f198d65dc 100644 --- a/buildroot/share/PlatformIO/boards/BigTree_Btt002.json +++ b/buildroot/share/PlatformIO/boards/BigTree_Btt002.json @@ -16,7 +16,7 @@ ], "ldscript": "stm32f407xg.ld", "mcu": "stm32f407vet6", - "variant": "BIGTREE_GENERIC_STM32F407_5X" + "variant": "BIGTREE_TBD" }, "debug": { "jlink_device": "STM32F407VE", @@ -24,9 +24,7 @@ "svd_path": "STM32F40x.svd" }, "frameworks": [ - "arduino", - "cmsis", - "stm32cube" + "arduino" ], "name": "STM32F407VE (192k RAM. 512k Flash)", "upload": { diff --git a/buildroot/share/PlatformIO/boards/BigTree_SKR_Pro.json b/buildroot/share/PlatformIO/boards/BigTree_SKR_Pro.json index 9a03f3b1599e..a949e00a350d 100644 --- a/buildroot/share/PlatformIO/boards/BigTree_SKR_Pro.json +++ b/buildroot/share/PlatformIO/boards/BigTree_SKR_Pro.json @@ -16,7 +16,7 @@ ], "ldscript": "stm32f407xg.ld", "mcu": "stm32f407zgt6", - "variant": "BIGTREE_GENERIC_STM32F407_5X" + "variant": "BIGTREE_SKR_PRO_1v1" }, "debug": { "jlink_device": "STM32F407ZG", @@ -24,9 +24,7 @@ "svd_path": "STM32F40x.svd" }, "frameworks": [ - "arduino", - "cmsis", - "stm32cube" + "arduino" ], "name": "STM32F407ZG (192k RAM. 1024k Flash)", "upload": { diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PeripheralPins.c similarity index 100% rename from buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PeripheralPins.c rename to buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PeripheralPins.c diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PinNamesVar.h b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PinNamesVar.h similarity index 100% rename from buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/PinNamesVar.h rename to buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PinNamesVar.h diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/ldscript.ld b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/ldscript.ld similarity index 100% rename from buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/ldscript.ld rename to buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/ldscript.ld diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.cpp b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.cpp similarity index 100% rename from buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.cpp rename to buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.cpp diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.h similarity index 100% rename from buildroot/share/PlatformIO/variants/BIGTREE_GENERIC_STM32F407_5X/variant.h rename to buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.h diff --git a/platformio.ini b/platformio.ini index 13a3d60c5dcc..dfc6d7e2664f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -506,22 +506,21 @@ monitor_speed = 250000 # BIGTREE_SKR_BTT002 (STM32F407VET6 ARM Cortex-M4) # [env:BIGTREE_BTT002] -platform = ststm32@>=5.7.0 -framework = arduino -platform_packages = framework-arduinoststm32@>=3.10700.191028 -board = BigTree_Btt002 -extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py -build_flags = ${common.build_flags} +platform = ststm32@5.6.0 +framework = arduino +board = BigTree_Btt002 +extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py +build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407VE\" -DTARGET_STM32F4 -DSTM32F407_5VX -DVECT_TAB_OFFSET=0x8000 - -DHAVE_HWSERIAL2 -DPIN_SERIAL2_RX=PD_6 -DPIN_SERIAL2_TX=PD_5 + -DHAVE_HWSERIAL2 -DHAVE_HWSERIAL3 - -DFORCE_BAUD_RATE=19200 - -IMarlin/src/HAL/HAL_STM32 -lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster, SoftwareSerial -src_filter = ${common.default_src_filter} + -monitor_speed = 250000 + -DPIN_SERIAL2_RX=PD_6 + -DPIN_SERIAL2_TX=PD_5 +lib_deps = ${common.lib_deps} +lib_ignore = Adafruit NeoPixel, SailfishLCD, SailfishRGB_LED, SlowSoftI2CMaster +src_filter = ${common.default_src_filter} + +monitor_speed = 250000 # # Teensy 3.1 / 3.2 (ARM Cortex-M4) From 36d0253ef2d44aaa773840c75cf95c646232f54a Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Thu, 7 Nov 2019 20:43:00 +0100 Subject: [PATCH 12/23] Minimize changes with base branch (to make final review easier) --- Marlin/src/HAL/HAL_STM32/HAL.cpp | 10 +++++----- Marlin/src/HAL/HAL_STM32/timers.cpp | 4 ++-- Marlin/src/HAL/HAL_STM32/timers.h | 20 ++++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp index 4a2644051195..3ad7977dd5fb 100644 --- a/Marlin/src/HAL/HAL_STM32/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp @@ -29,12 +29,12 @@ #include "../shared/Delay.h" #if (__cplusplus == 201703L) && defined(__has_include) - #define HAS_SOFTSERIAL __has_include() + #define HAS_SWSERIAL __has_include() #else - #define HAS_SOFTSERIAL HAS_TMC220x + #define HAS_SWSERIAL HAS_TMC220x #endif -#if HAS_SOFTSERIAL +#if HAS_SWSERIAL #include "SoftwareSerial.h" #endif @@ -93,8 +93,8 @@ void HAL_init() { while (!LL_PWR_IsActiveFlag_BRR()); #endif // EEPROM_EMULATED_SRAM - #if HAS_SOFTSERIAL - SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_PRIORITY, 0); + #if HAS_SWSERIAL + SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0); #endif } diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index db737453bcdb..c9a39c4bcea7 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -93,11 +93,11 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) { // timer_instance[timer_num]->setInterruptPriority one time in HAL_timer_start. switch (timer_num) { case STEP_TIMER_NUM: - HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_PRIORITY, 0); + HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0); break; case TEMP_TIMER_NUM: - HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_PRIORITY, 0); + HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0); break; } } diff --git a/Marlin/src/HAL/HAL_STM32/timers.h b/Marlin/src/HAL/HAL_STM32/timers.h index d85c7e217289..317048cf4b3d 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.h +++ b/Marlin/src/HAL/HAL_STM32/timers.h @@ -33,9 +33,6 @@ #define hal_timer_t uint32_t #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit -#define SWSERIAL_TIMER_PRIORITY 1 -#define STEP_TIMER_PRIORITY 2 -#define TEMP_TIMER_PRIORITY 14 #ifdef STM32F0xx @@ -70,10 +67,21 @@ #endif #ifndef TEMP_TIMER - #define TEMP_TIMER 14 + #define TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used. #endif - // TIM7 is consumed by Software Serial if used. +#endif + +#ifndef SWSERIAL_TIMER_IRQ_PRIO + #define SWSERIAL_TIMER_IRQ_PRIO 1 +#endif + +#ifndef STEP_TIMER_IRQ_PRIO + #define STEP_TIMER_IRQ_PRIO 2 +#endif + +#ifndef TEMP_TIMER_IRQ_PRIO + #define TEMP_TIMER_IRQ_PRIO 14 //14 = after hardware ISRs #endif #define STEP_TIMER_NUM 0 // index of timer to use for stepper @@ -84,7 +92,7 @@ //TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp #define STEPPER_TIMER_RATE 2000000 // 2 Mhz -#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE) / (STEPPER_TIMER_RATE)) +#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE)) #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs #define PULSE_TIMER_RATE STEPPER_TIMER_RATE From 7ef68e432a0761b136ad2a78881f2726691ba3f3 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Fri, 8 Nov 2019 12:09:35 +0100 Subject: [PATCH 13/23] IRQ enable/disable without timer re-init. --- Marlin/src/HAL/HAL_STM32/timers.cpp | 42 ++++++++++++++++++----------- Marlin/src/HAL/HAL_STM32/timers.h | 4 +-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index c9a39c4bcea7..8c2802bcabf2 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -50,8 +50,6 @@ bool timer_enabled[NUM_HARDWARE_TIMERS] = { false }; // frequency is in Hertz void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { - static_assert(TIM_IRQ_PRIO > 0 && TIM_IRQ_PRIO < 15, "Default timer interrupt priority is too low to allow proper prioritization of interrupts."); - if (!HAL_timer_initialized(timer_num)) { switch (timer_num) { case STEP_TIMER_NUM: // STEPPER TIMER - use a 32bit timer if possible @@ -71,13 +69,34 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { */ timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); //the -1 is done internally timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE) /* /frequency */), TICK_FORMAT); - timer_instance[timer_num]->attachInterrupt(Step_Handler); // Called on rollover break; case TEMP_TIMER_NUM: // TEMP TIMER - any available 16bit timer timer_instance[timer_num] = new HardwareTimer(TEMP_TIMER_DEV); // The prescale factor is computed automatically for HERTZ_FORMAT timer_instance[timer_num]->setOverflow(frequency, HERTZ_FORMAT); - timer_instance[timer_num]->attachInterrupt(Temp_Handler); + break; + } + + HAL_timer_enable_interrupt(timer_num); + + /* + * Initializes (and unfortunately starts) the timer. + * This is needed to set correct IRQ priority at the moment but causes + * no harm since every call to HAL_timer_start() is actually followed by + * a call to HAL_timer_enable_interrupt() which means that there isn't + * a case in which you want the timer to run without a callback. + */ + timer_instance[timer_num]->resume(); //the first call to resume MUST follow the attachInterrupt + + // This is fixed in Arduino_Core_STM32 1.8. + // These calls can be removed and replaced with + // timer_instance[timer_num]->setInterruptPriority + switch (timer_num) { + case STEP_TIMER_NUM: + HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0); + break; + case TEMP_TIMER_NUM: + HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0); break; } } @@ -86,18 +105,12 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { void HAL_timer_enable_interrupt(const uint8_t timer_num) { if (HAL_timer_initialized(timer_num) && !timer_enabled[timer_num]) { timer_enabled[timer_num] = true; - timer_instance[timer_num]->resume(); // Resume the timer to start receiving the interrupt - - // HardwareTimer::resume() reinits the timer, resetting the priority. Set again. - // This is fixed in Arduino_Core_STM32 1.8. These calls can be removed, and replaced - // timer_instance[timer_num]->setInterruptPriority one time in HAL_timer_start. switch (timer_num) { case STEP_TIMER_NUM: - HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0); + timer_instance[timer_num]->attachInterrupt(Step_Handler); break; - - case TEMP_TIMER_NUM: - HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0); + case TEMP_TIMER_NUM: + timer_instance[timer_num]->attachInterrupt(Temp_Handler); break; } } @@ -105,9 +118,8 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) { void HAL_timer_disable_interrupt(const uint8_t timer_num) { if (HAL_timer_interrupt_enabled(timer_num)) { - // Pause the timer instead of detaching the interrupt through detachInterrupt() - timer_instance[timer_num]->pause(); timer_enabled[timer_num] = false; + timer_instance[timer_num]->detachInterrupt(); } } diff --git a/Marlin/src/HAL/HAL_STM32/timers.h b/Marlin/src/HAL/HAL_STM32/timers.h index 317048cf4b3d..1d2c095f2bb8 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.h +++ b/Marlin/src/HAL/HAL_STM32/timers.h @@ -132,7 +132,7 @@ void HAL_timer_enable_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); -TIM_TypeDef* HAL_timer_device(const uint8_t timer_num); //no need to be public for now. not public = not used externally +//TIM_TypeDef* HAL_timer_device(const uint8_t timer_num); no need to be public for now. not public = not used externally // FORCE_INLINE because these are used in performance-critical situations FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) { @@ -150,7 +150,7 @@ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const ha // wiki: "force all registers (Autoreload, prescaler, compare) to be taken into account" // So, if the new overflow value is less than the count it will trigger a rollover interrupt. if (overflow < timer_instance[timer_num]->getCount()) // Added 'if' here because reports say it won't boot without it - HAL_timer_device(timer_num)->EGR |= TIM_EGR_UG; + timer_instance[timer_num]->refresh(); } } From 1169ae1d3861aaef2081ae51bb46eb69381c5811 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Fri, 8 Nov 2019 13:33:48 +0100 Subject: [PATCH 14/23] Better instruction order in case of multi IRQ --- Marlin/src/HAL/HAL_STM32/timers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index 8c2802bcabf2..8a6e0e436e1f 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -118,8 +118,8 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) { void HAL_timer_disable_interrupt(const uint8_t timer_num) { if (HAL_timer_interrupt_enabled(timer_num)) { - timer_enabled[timer_num] = false; timer_instance[timer_num]->detachInterrupt(); + timer_enabled[timer_num] = false; } } From e8668d54d5db36ddf4e99fffe1327e04d8af9f0a Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Fri, 8 Nov 2019 14:01:26 +0100 Subject: [PATCH 15/23] Remove un-needed define FORCE_BAUD_RATE It's anyway defined the TMC_BAUD_RATE in Marlin\src\pins\stm32\pins_BIGTREE_SKR_PRO_V1.1.h Now that we have the priorities done right we could try increasing that and see if it still works as it should. --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index dfc6d7e2664f..b388988132cd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -489,7 +489,7 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/generic_create_varian build_flags = ${common.build_flags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSB_PRODUCT=\"STM32F407ZG\" -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000 - -DHAVE_HWSERIAL6 -DFORCE_BAUD_RATE=19200 + -DHAVE_HWSERIAL6 -IMarlin/src/HAL/HAL_STM32 lib_deps = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip From 8c09d3b404c44f4c41ef5fac853eaa01cb057e16 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Sat, 9 Nov 2019 19:01:09 +0100 Subject: [PATCH 16/23] Revert F4_F7 timers Since that HAL doesn't make sense we revert the changes to make the F4/F7 test boards compile and pass validation. Once the features in HAL_F4_F7 will be ported to HAL_STM32 we will drop the whole F4_F7 HAL and retarget boards which still used it --- .travis.yml | 6 +- .../HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp | 117 +++++++++++++++ .../src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h | 126 ++++++++++++++++ .../HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp | 131 +++++++++++++++++ .../src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h | 97 +++++++++++++ Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp | 92 ------------ Marlin/src/HAL/HAL_STM32_F4_F7/timers.h | 136 +----------------- 7 files changed, 479 insertions(+), 226 deletions(-) create mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp create mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h create mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp create mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h delete mode 100644 Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp diff --git a/.travis.yml b/.travis.yml index dec65af7db86..28c3582ce9f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,10 @@ env: - TEST_PLATFORM="mks_robin" - TEST_PLATFORM="ARMED" + # STM32 with non-STM framework. + - TEST_PLATFORM="STM32F4" + - TEST_PLATFORM="STM32F7" + # Put lengthy tests last - TEST_PLATFORM="LPC1768" - TEST_PLATFORM="LPC1769" @@ -49,8 +53,6 @@ env: #- TEST_PLATFORM="mks_robin_mini" #- TEST_PLATFORM="mks_robin_nano" #- TEST_PLATFORM="SAMD51_grandcentral_m4" - #- TEST_PLATFORM="STM32F4" - #- TEST_PLATFORM="STM32F7" before_install: # diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp new file mode 100644 index 000000000000..32219962ee75 --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp @@ -0,0 +1,117 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#if defined(STM32GENERIC) && defined(STM32F4) + +#include "../HAL.h" +#include "timers.h" + +// ------------------------ +// Local defines +// ------------------------ + +#define NUM_HARDWARE_TIMERS 2 +#define STEP_TIMER_IRQ_ID TIM5_IRQn +#define TEMP_TIMER_IRQ_ID TIM7_IRQn + +// ------------------------ +// Private Variables +// ------------------------ + +stm32_timer_t TimerHandle[NUM_HARDWARE_TIMERS]; + +// ------------------------ +// Public functions +// ------------------------ + +bool timers_initialized[NUM_HARDWARE_TIMERS] = {false}; + +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { + + if (!timers_initialized[timer_num]) { + constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1, + temp_prescaler = TEMP_TIMER_PRESCALE - 1; + switch (timer_num) { + case STEP_TIMER_NUM: + // STEPPER TIMER TIM5 - use a 32bit timer + __HAL_RCC_TIM5_CLK_ENABLE(); + TimerHandle[timer_num].handle.Instance = TIM5; + TimerHandle[timer_num].handle.Init.Prescaler = step_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)TC5_Handler; + HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 1, 0); + break; + + case TEMP_TIMER_NUM: + // TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM) + __HAL_RCC_TIM7_CLK_ENABLE(); + 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; + HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0); + break; + } + timers_initialized[timer_num] = true; + } + + TimerHandle[timer_num].handle.Init.Period = (((HAL_TIMER_RATE) / TimerHandle[timer_num].handle.Init.Prescaler) / frequency) - 1; + if (HAL_TIM_Base_Init(&TimerHandle[timer_num].handle) == HAL_OK) + HAL_TIM_Base_Start_IT(&TimerHandle[timer_num].handle); +} + +extern "C" void TIM5_IRQHandler() { + ((void(*)())TimerHandle[0].callback)(); +} +extern "C" void TIM7_IRQHandler() { + ((void(*)())TimerHandle[1].callback)(); +} + +void HAL_timer_enable_interrupt(const uint8_t timer_num) { + 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) { + 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! + // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) + __DSB(); + __ISB(); +} + +bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { + switch (timer_num) { + 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)); + } + return false; +} + +#endif // STM32GENERIC && STM32F4 diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h new file mode 100644 index 000000000000..726207fbcfc6 --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h @@ -0,0 +1,126 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2017 Victor Perez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include + +// ------------------------ +// Defines +// ------------------------ + +#define FORCE_INLINE __attribute__((always_inline)) inline + +#define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked? +#define HAL_TIMER_TYPE_MAX 0xFFFF + +#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals + +#define STEP_TIMER_NUM 0 // index of timer to use for stepper +#define TEMP_TIMER_NUM 1 // index of timer to use for temperature +#define PULSE_TIMER_NUM STEP_TIMER_NUM + +#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz +#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency + +#define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz +#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer +#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs + +#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer +#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE +#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US + +#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) +#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) +#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) + +#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) +#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) + +// 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 + + +// ------------------------ +// Types +// ------------------------ + +#ifdef STM32GENERIC + typedef struct { + TIM_HandleTypeDef handle; + uint32_t callback; + } tTimerConfig; + typedef tTimerConfig stm32_timer_t; +#else + typedef stimer_t stm32_timer_t; +#endif + +// ------------------------ +// Public Variables +// ------------------------ + +extern stm32_timer_t TimerHandle[]; + +// ------------------------ +// Public functions +// ------------------------ + +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); +void HAL_timer_enable_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); + +FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) { + return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle); +} + +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); +} + +#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 + +#define HAL_timer_isr_epilogue(TIMER_NUM) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp new file mode 100644 index 000000000000..5a3b32ef5bce --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp @@ -0,0 +1,131 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#if defined(STM32GENERIC) && defined(STM32F7) + +#include "../HAL.h" +#include "timers.h" + +// ------------------------ +// Local defines +// ------------------------ + +#define NUM_HARDWARE_TIMERS 2 + +//#define PRESCALER 1 + +// ------------------------ +// Private Variables +// ------------------------ + +tTimerConfig timerConfig[NUM_HARDWARE_TIMERS]; + +// ------------------------ +// Public functions +// ------------------------ + +bool timers_initialized[NUM_HARDWARE_TIMERS] = { false }; + +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { + + if (!timers_initialized[timer_num]) { + switch (timer_num) { + case STEP_TIMER_NUM: + //STEPPER TIMER TIM5 //use a 32bit timer + __HAL_RCC_TIM5_CLK_ENABLE(); + timerConfig[0].timerdef.Instance = TIM5; + timerConfig[0].timerdef.Init.Prescaler = (STEPPER_TIMER_PRESCALE); + timerConfig[0].timerdef.Init.CounterMode = TIM_COUNTERMODE_UP; + timerConfig[0].timerdef.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + timerConfig[0].IRQ_Id = TIM5_IRQn; + timerConfig[0].callback = (uint32_t)TC5_Handler; + HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0); + #if PIN_EXISTS(STEPPER_ENABLE) + OUT_WRITE(STEPPER_ENABLE_PIN, HIGH); + #endif + break; + case TEMP_TIMER_NUM: + //TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM) + __HAL_RCC_TIM7_CLK_ENABLE(); + timerConfig[1].timerdef.Instance = TIM7; + timerConfig[1].timerdef.Init.Prescaler = (TEMP_TIMER_PRESCALE); + timerConfig[1].timerdef.Init.CounterMode = TIM_COUNTERMODE_UP; + timerConfig[1].timerdef.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + timerConfig[1].IRQ_Id = TIM7_IRQn; + timerConfig[1].callback = (uint32_t)TC7_Handler; + HAL_NVIC_SetPriority(timerConfig[1].IRQ_Id, 2, 0); + break; + } + timers_initialized[timer_num] = true; + } + + timerConfig[timer_num].timerdef.Init.Period = (((HAL_TIMER_RATE) / timerConfig[timer_num].timerdef.Init.Prescaler) / frequency) - 1; + + if (HAL_TIM_Base_Init(&timerConfig[timer_num].timerdef) == HAL_OK) + HAL_TIM_Base_Start_IT(&timerConfig[timer_num].timerdef); +} + +//forward the interrupt +extern "C" void TIM5_IRQHandler() { + ((void(*)())timerConfig[0].callback)(); +} +extern "C" void TIM7_IRQHandler() { + ((void(*)())timerConfig[1].callback)(); +} + +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) { + HAL_NVIC_EnableIRQ(timerConfig[timer_num].IRQ_Id); +} + +void HAL_timer_disable_interrupt(const uint8_t timer_num) { + HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id); + + // We NEED memory barriers to ensure Interrupts are actually disabled! + // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) + __DSB(); + __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_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) { + const uint32_t IRQ_Id = uint32_t(timerConfig[timer_num].IRQ_Id); + return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F); +} + +#endif // STM32GENERIC && STM32F7 diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h new file mode 100644 index 000000000000..38ecde30bb94 --- /dev/null +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h @@ -0,0 +1,97 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2017 Victor Perez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include + +// ------------------------ +// Defines +// ------------------------ + +#define FORCE_INLINE __attribute__((always_inline)) inline + +#define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked? +#define HAL_TIMER_TYPE_MAX 0xFFFF + +#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals + +#define STEP_TIMER_NUM 0 // index of timer to use for stepper +#define TEMP_TIMER_NUM 1 // index of timer to use for temperature +#define PULSE_TIMER_NUM STEP_TIMER_NUM + +#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency +#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz + +#define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz +#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer +#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs + +#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer +#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE +#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US + +#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) +#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) + +#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) + +// TODO change this + +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 +// ------------------------ + +typedef struct { + TIM_HandleTypeDef timerdef; + IRQn_Type IRQ_Id; + uint32_t callback; +} tTimerConfig; + +// ------------------------ +// Public Variables +// ------------------------ + +//extern const tTimerConfig timerConfig[]; + +// ------------------------ +// Public functions +// ------------------------ + +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); +void HAL_timer_enable_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); + +void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare); +hal_timer_t HAL_timer_get_compare(const uint8_t timer_num); +uint32_t HAL_timer_get_count(const uint8_t timer_num); +void HAL_timer_isr_prologue(const uint8_t timer_num); +#define HAL_timer_isr_epilogue(TIMER_NUM) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp deleted file mode 100644 index ab06cf3b206c..000000000000 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) - -#include "HAL.h" - -#include "timers.h" - -// ------------------------ -// Local defines -// ------------------------ - -#define NUM_HARDWARE_TIMERS 2 - -// ------------------------ -// Private Variables -// ------------------------ - -HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL }; -bool timer_enabled[NUM_HARDWARE_TIMERS] = { false }; - -// ------------------------ -// Public functions -// ------------------------ - -// 'frequency' is in Hertz -void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { - if (!HAL_timer_initialized(timer_num)) { - // According to documentation the prescale factor is computed automatically if setOverflow is in HERTZ_FORMAT - switch (timer_num) { - case STEP_TIMER_NUM: - // STEPPER TIMER - use a 32bit timer if possible - timer_instance[timer_num] = new HardwareTimer(STEP_TIMER_DEV); - timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); - timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE) / frequency), TICK_FORMAT); - timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); - timer_instance[timer_num]->attachInterrupt(Step_Handler); // Called on update interruption (rollover) - timer_instance[timer_num]->resume(); - break; - case TEMP_TIMER_NUM: - // TEMP TIMER - any available 16bit Timer - timer_instance[timer_num] = new HardwareTimer(TEMP_TIMER_DEV); - timer_instance[timer_num]->setMode(1, TIMER_OUTPUT_COMPARE); - timer_instance[timer_num]->setOverflow(frequency, HERTZ_FORMAT); - timer_instance[timer_num]->attachInterrupt(Temp_Handler); - timer_instance[timer_num]->resume(); - break; - } - } -} - -void HAL_timer_enable_interrupt(const uint8_t timer_num) { - if (HAL_timer_initialized(timer_num) && !timer_enabled[timer_num]) { - // Resume the timer to start receiving the interrupt - timer_instance[timer_num]->resume(); - timer_enabled[timer_num] = true; - } -} - -void HAL_timer_disable_interrupt(const uint8_t timer_num) { - if (HAL_timer_interrupt_enabled(timer_num)) { - // Pause the timer instead of detaching the interrupt through detachInterrupt() - timer_instance[timer_num]->pause(); - timer_enabled[timer_num] = false; - } -} - -bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { - return HAL_timer_initialized(timer_num) && timer_enabled[timer_num]; -} - -#endif // STM32GENERIC && (STM32F4 || STM32F7) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h index 55371126e4c7..cf33205bddab 100644 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h @@ -21,136 +21,8 @@ */ #pragma once -#include -#include "../../inc/MarlinConfig.h" - -// ------------------------ -// Defines -// ------------------------ - -#define FORCE_INLINE __attribute__((always_inline)) inline - -#define hal_timer_t uint32_t -#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit - -#ifdef STM32F0xx - - #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 16 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 17 - #endif - -#elif defined(STM32F1xx) - - #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 4 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 2 - #endif - -#elif defined(STM32F4xx) || defined(STM32F7xx) - - #define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 5 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 7 - #endif - +#ifdef STM32F4 + #include "STM32F4/timers.h" +#else + #include "STM32F7/timers.h" #endif - -#define STEP_TIMER_NUM 0 // index of timer to use for stepper -#define TEMP_TIMER_NUM 1 // index of timer to use for temperature -#define PULSE_TIMER_NUM STEP_TIMER_NUM - -#define TEMP_TIMER_RATE 72000 // 72 Khz -#define TEMP_TIMER_PRESCALE ((HAL_TIMER_RATE)/(TEMP_TIMER_RATE)) -#define TEMP_TIMER_FREQUENCY 1000 - -#define STEPPER_TIMER_RATE 2000000 // 2 Mhz -#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE)) -#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs - -#define PULSE_TIMER_RATE STEPPER_TIMER_RATE -#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE -#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US - -#define __TIMER_DEV(X) TIM##X -#define _TIMER_DEV(X) __TIMER_DEV(X) -#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER) -#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER) - -#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) -#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) -#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) - -#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) -#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) - -extern void Step_Handler(HardwareTimer *htim); -extern void Temp_Handler(HardwareTimer *htim); -#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim) -#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim) - -// ------------------------ -// Public Variables -// ------------------------ - -extern HardwareTimer *timer_instance[]; - -// ------------------------ -// Public functions -// ------------------------ - -void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); -void HAL_timer_enable_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); - -//made FORCE_INLINE because it's used from FORCE_INLINE (performance critical) methods -FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) { - return timer_instance[timer_num] != NULL; -} -FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) { - return HAL_timer_initialized(timer_num) ? timer_instance[timer_num]->getCount() : 0; -} - -FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) { - if (HAL_timer_initialized(timer_num)) { - #ifdef HW_TIMERS - timer_instance[timer_num]->setOverflow(compare, TICK_FORMAT); - const uint32_t cnt = timer_instance[timer_num]->getCount(TICK_FORMAT); - if (cnt >= compare) timer_instance[timer_num]->refresh(); - #else - __HAL_TIM_SET_AUTORELOAD(&timer_instance[timer_num].handle, compare); - if (HAL_timer_get_count(timer_num) >= compare) - timer_instance[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt - #endif - } -} - -FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) { - if (!HAL_timer_initialized(timer_num)) return 0; - return ( - #ifdef HW_TIMERS - timer_instance[timer_num]->getOverflow(TICK_FORMAT) - #else - __HAL_TIM_GET_AUTORELOAD(&timer_instance[timer_num].handle) - #endif - ); -} - -#define HAL_timer_isr_prologue(TIMER_NUM) -#define HAL_timer_isr_epilogue(TIMER_NUM) From ffc41d0e6bd020d932f77608580dea26dca21e53 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Sat, 9 Nov 2019 20:24:06 +0100 Subject: [PATCH 17/23] DIsable travis on F4 & F7 since SPI is broken --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 28c3582ce9f0..745023fc5bf1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,9 +36,9 @@ env: - TEST_PLATFORM="mks_robin" - TEST_PLATFORM="ARMED" - # STM32 with non-STM framework. - - TEST_PLATFORM="STM32F4" - - TEST_PLATFORM="STM32F7" + # STM32 with non-STM framework. both broken for now. they should use HAL_STM32 which is working. + #- TEST_PLATFORM="STM32F4" + #- TEST_PLATFORM="STM32F7" # Put lengthy tests last - TEST_PLATFORM="LPC1768" From 2fde417abb99c6467da77314f15c6b8ff39d8de2 Mon Sep 17 00:00:00 2001 From: Lino Barreca Date: Tue, 12 Nov 2019 21:47:47 +0100 Subject: [PATCH 18/23] Improved variant pins for SKR Pro 1.1 (cherry pick on MultiSPI dev branch) --- .../BIGTREE_SKR_PRO_1v1/PeripheralPins.c | 107 ++---------------- .../BIGTREE_SKR_PRO_1v1/hal_conf_extra.h | 52 +++++++++ .../variants/BIGTREE_SKR_PRO_1v1/variant.h | 7 -- 3 files changed, 64 insertions(+), 102 deletions(-) create mode 100644 buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PeripheralPins.c b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PeripheralPins.c index 63a3a521f609..9b92ee60a05c 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PeripheralPins.c +++ b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/PeripheralPins.c @@ -42,45 +42,21 @@ #ifdef HAL_ADC_MODULE_ENABLED const PinMap PinMap_ADC[] = { {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 E0_DIR - //{PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 - //{PA_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 BLTOUCH_2 - //{PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 - //{PA_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 BLTOUCH_4 - //{PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 - //{PA_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 E1_EN - //{PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 - //{PA_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 TF_SS - //{PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 TF_SCLK - //{PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 TF_MISO - //{PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 LED - //{PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 HEATER2 - //{PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 HEATER0 - //{PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 Z_EN - //{PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 - //{PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC3_IN10 {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 EXP_14 - //{PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 - //{PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_IN11 {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 Z_DIR - //{PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 - //{PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC3_IN12 {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 E0_EN - //{PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 - //{PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC3_IN13 {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 EXP_8 - //{PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 EXP_7 - //{PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 #if STM32F4X_PIN_NUM >= 144 //144 pins mcu, 114 gpio, 24 ADC {PF_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 TH_0 @@ -288,42 +264,30 @@ const PinMap PinMap_UART_CTS[] = { #ifdef HAL_SPI_MODULE_ENABLED const PinMap PinMap_SPI_MOSI[] = { - {PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_5, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, + {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, - {PC_3, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_12, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; const PinMap PinMap_SPI_MISO[] = { - {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, + {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, - {PC_2, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_11, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; const PinMap PinMap_SPI_SCLK[] = { - {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PB_3, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, - {PB_10, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, {PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_10, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; const PinMap PinMap_SPI_SSEL[] = { - {PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PA_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, - {PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, - {PA_15, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, - {PB_9, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, {PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PA_15, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} }; #endif @@ -331,87 +295,40 @@ const PinMap PinMap_SPI_SSEL[] = { //*** CAN *** #ifdef HAL_CAN_MODULE_ENABLED -const PinMap PinMap_CAN_RD[] = { - {PA_11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {PB_5, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PB_8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {PB_12, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PD_0, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {NC, NP, 0} -}; - -const PinMap PinMap_CAN_TD[] = { - {PA_12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {PB_6, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PB_9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {PB_13, CAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PD_1, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {NC, NP, 0} -}; +#error "CAN bus isn't available on this board. Driver should be disabled." #endif //*** ETHERNET *** - #ifdef HAL_ETH_MODULE_ENABLED -const PinMap PinMap_Ethernet[] = { - {PA_0, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_CRS - {PA_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_REF_CLK|ETH_RX_CLK - {PA_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_MDIO - {PA_3, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_COL - {PA_7, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_CRS_DV|ETH_RX_DV - {PB_0, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD2 - {PB_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD3 - {PB_5, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_PPS_OUT - {PB_8, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD3 - {PB_10, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RX_ER - {PB_11, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TX_EN - {PB_12, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD0 - {PB_13, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD1 - {PC_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_MDC - {PC_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD2 - {PC_3, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TX_CLK - {PC_4, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD0 - {PC_5, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD1 - {PE_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD3 - #if STM32F4X_PIN_NUM >= 144 //144 pins mcu, 114 gpio - {PG_8, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_PPS_OUT - {PG_11, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TX_EN - {PG_13, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD0 - {PG_14, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD1 - #endif - {NC, NP, 0} -}; +#error "Ethernet port isn't available on this board. Driver should be disabled." #endif //*** No QUADSPI *** //*** USB *** - #ifdef HAL_PCD_MODULE_ENABLED const PinMap PinMap_USB_OTG_FS[] = { - //{PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF - //{PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS - //{PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID + //{PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF used by LCD + //{PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS available on wifi port, if empty + //{PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID available on UART1_RX if not used {PA_11, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DM {PA_12, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP {NC, NP, 0} }; -const PinMap PinMap_USB_OTG_HS[] = { +const PinMap PinMap_USB_OTG_HS[] = { /* #ifdef USE_USB_HS_IN_FS - {PA_4, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_SOF {PB_12, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_ID {PB_13, USB_OTG_HS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_HS_VBUS {PB_14, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_DM {PB_15, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG_HS_FS)}, // USB_OTG_HS_DP #else + #error "USB in HS mode isn't supported by the board" {PA_3, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D0 - {PA_5, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_CK {PB_0, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D1 {PB_1, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D2 {PB_5, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D7 {PB_10, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D3 - {PB_11, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D4 {PB_12, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D5 {PB_13, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_D6 {PC_0, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_HS)}, // USB_OTG_HS_ULPI_STP diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h new file mode 100644 index 000000000000..610c0ace1b10 --- /dev/null +++ b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h @@ -0,0 +1,52 @@ +#pragma once + +#define HAL_MODULE_ENABLED +#define HAL_ADC_MODULE_ENABLED +#define HAL_CRC_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +//#define HAL_RTC_MODULE_ENABLED Real Time Clock...do we use it? +#define HAL_SPI_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_USART_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED +//#define HAL_UART_MODULE_ENABLED //by default +// #define HAL_PCD_MODULE_ENABLED //Since STM32 v3.10700.191028 this is automatically added if any type of USB is enabled (as in Arduino IDE) + +#undef HAL_SD_MODULE_ENABLED +#undef HAL_DAC_MODULE_ENABLED +#undef HAL_FLASH_MODULE_ENABLED +#undef HAL_CAN_MODULE_ENABLED +#undef HAL_CAN_LEGACY_MODULE_ENABLED +#undef HAL_CEC_MODULE_ENABLED +#undef HAL_CRYP_MODULE_ENABLED +#undef HAL_DCMI_MODULE_ENABLED +#undef HAL_DMA2D_MODULE_ENABLED +#undef HAL_ETH_MODULE_ENABLED +#undef HAL_NAND_MODULE_ENABLED +#undef HAL_NOR_MODULE_ENABLED +#undef HAL_PCCARD_MODULE_ENABLED +#undef HAL_SRAM_MODULE_ENABLED +#undef HAL_SDRAM_MODULE_ENABLED +#undef HAL_HASH_MODULE_ENABLED +#undef HAL_EXTI_MODULE_ENABLED +#undef HAL_SMBUS_MODULE_ENABLED +#undef HAL_I2S_MODULE_ENABLED +#undef HAL_IWDG_MODULE_ENABLED +#undef HAL_LTDC_MODULE_ENABLED +#undef HAL_DSI_MODULE_ENABLED +#undef HAL_QSPI_MODULE_ENABLED +#undef HAL_RNG_MODULE_ENABLED +#undef HAL_SAI_MODULE_ENABLED +#undef HAL_IRDA_MODULE_ENABLED +#undef HAL_SMARTCARD_MODULE_ENABLED +#undef HAL_WWDG_MODULE_ENABLED +#undef HAL_HCD_MODULE_ENABLED +#undef HAL_FMPI2C_MODULE_ENABLED +#undef HAL_SPDIFRX_MODULE_ENABLED +#undef HAL_DFSDM_MODULE_ENABLED +#undef HAL_LPTIM_MODULE_ENABLED +#undef HAL_MMC_MODULE_ENABLED \ No newline at end of file diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.h b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.h index 2e70f8a303db..396f3138c096 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.h +++ b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/variant.h @@ -267,13 +267,6 @@ extern "C" { #define PIN_SERIAL_RX PA10 #define PIN_SERIAL_TX PA9 -/* Extra HAL modules */ -#ifndef HAL_PCD_MODULE_ENABLED - #define HAL_PCD_MODULE_ENABLED //Since STM32 v3.10700.191028 this is automatically added if any type of USB is enabled (as in Arduino IDE) -#endif - -#define HAL_DAC_MODULE_ENABLED - #ifdef __cplusplus } // extern "C" #endif From 784049321114472cacd91e9044c3839e3d7c8705 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 12 Nov 2019 18:52:30 -0600 Subject: [PATCH 19/23] Update HAL.cpp --- Marlin/src/HAL/HAL_STM32/HAL.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp index 3ad7977dd5fb..1d8eb44470fe 100644 --- a/Marlin/src/HAL/HAL_STM32/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp @@ -29,9 +29,9 @@ #include "../shared/Delay.h" #if (__cplusplus == 201703L) && defined(__has_include) - #define HAS_SWSERIAL __has_include() + #define HAS_SWSERIAL __has_include() #else - #define HAS_SWSERIAL HAS_TMC220x + #define HAS_SWSERIAL HAS_TMC220x #endif #if HAS_SWSERIAL From 6cc2a1a585a806fbff26fce791ae013885866c82 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 12 Nov 2019 19:03:11 -0600 Subject: [PATCH 20/23] Formatting, spelling, etc. --- Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp | 174 ++++++++------------ 1 file changed, 68 insertions(+), 106 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp index 6fe174f557c9..7ca1d47540ae 100644 --- a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp +++ b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp @@ -110,8 +110,7 @@ uint32_t SoftwareSerial::rx_buffer = 0; int32_t SoftwareSerial::rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit uint32_t SoftwareSerial::cur_speed = 0; -void SoftwareSerial::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) -{ +void SoftwareSerial::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) { timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preemptPriority, subPriority); } @@ -119,8 +118,7 @@ void SoftwareSerial::setInterruptPriority(uint32_t preemptPriority, uint32_t sub // Private methods // -void SoftwareSerial::setSpeed(uint32_t speed) -{ +void SoftwareSerial::setSpeed(uint32_t speed) { if (speed != cur_speed) { timer.pause(); if (speed != 0) { @@ -133,7 +131,7 @@ void SoftwareSerial::setSpeed(uint32_t speed) do { cmp_value = clock_rate / (speed * OVERSAMPLE); if (cmp_value >= UINT16_MAX) { - clock_rate = clock_rate / 2; + clock_rate /= 2; pre *= 2; } } while (cmp_value >= UINT16_MAX); @@ -143,17 +141,16 @@ void SoftwareSerial::setSpeed(uint32_t speed) timer.attachInterrupt(&handleInterrupt); timer.resume(); NVIC_SetPriority(timer_interrupt_number, timer_interrupt_priority); - } else { - timer.detachInterrupt(); } + else + timer.detachInterrupt(); cur_speed = speed; } } // This function sets the current object as the "listening" // one and returns true if it replaces another -bool SoftwareSerial::listen() -{ +bool SoftwareSerial::listen() { if (active_listener != this) { // wait for any transmit to complete as we may change speed while (active_out); @@ -162,23 +159,18 @@ bool SoftwareSerial::listen() rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit setSpeed(_speed); active_listener = this; - if (!_half_duplex) { - active_in = this; - } + if (!_half_duplex) active_in = this; return true; } return false; } // Stop listening. Returns true if we were actually listening. -bool SoftwareSerial::stopListening() -{ +bool SoftwareSerial::stopListening() { if (active_listener == this) { // wait for any output to complete while (active_out); - if (_half_duplex) { - setRXTX(false); - } + if (_half_duplex) setRXTX(false); active_listener = nullptr; active_in = nullptr; // turn off ints @@ -188,23 +180,19 @@ bool SoftwareSerial::stopListening() return false; } -inline void SoftwareSerial::setTX() -{ - if (_inverse_logic) { +inline void SoftwareSerial::setTX() { + if (_inverse_logic) LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber); - } else { + else LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber); - } pinMode(_transmitPin, OUTPUT); } -inline void SoftwareSerial::setRX() -{ +inline void SoftwareSerial::setRX() { pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic! } -inline void SoftwareSerial::setRXTX(bool input) -{ +inline void SoftwareSerial::setRXTX(bool input) { if (_half_duplex) { if (input) { if (active_in != this) { @@ -213,7 +201,8 @@ inline void SoftwareSerial::setRXTX(bool input) rx_tick_cnt = 2; // 2 : next interrupt will be discarded. 2 interrupts required to consider RX pin level active_in = this; } - } else { + } + else { if (active_in == this) { setTX(); active_in = nullptr; @@ -222,29 +211,27 @@ inline void SoftwareSerial::setRXTX(bool input) } } -inline void SoftwareSerial::send() -{ - if (--tx_tick_cnt <= 0) { // if tx_tick_cnt > 0 interrupt is discarded. Only when tx_tick_cnt reach 0 we set TX pin. - if (tx_bit_cnt++ < 10) { // tx_bit_cnt < 10 transmission is not fiisehed (10 = 1 start +8 bits + 1 stop) - // send data (including start and stop bits) - if (tx_buffer & 1) { +inline void SoftwareSerial::send() { + if (--tx_tick_cnt <= 0) { // if tx_tick_cnt > 0 interrupt is discarded. Only when tx_tick_cnt reaches 0 is TX pin set. + if (tx_bit_cnt++ < 10) { // tx_bit_cnt < 10 transmission is not finished (10 = 1 start +8 bits + 1 stop) + // Send data (including start and stop bits) + if (tx_buffer & 1) LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber); - } else { + else LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber); - } tx_buffer >>= 1; - tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE tick to send next bit - } else { // Transmission finished + tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks to send next bit + } + else { // Transmission finished tx_tick_cnt = 1; if (_output_pending) { active_out = nullptr; - // When in half-duplex mode, wait for HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has + // In half-duplex mode wait HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has // been transmitted before allowing the switch to RX mode - } else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) { - if (_half_duplex && active_listener == this) { - setRXTX(true); - } + } + else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) { + if (_half_duplex && active_listener == this) setRXTX(true); active_out = nullptr; } } @@ -254,9 +241,8 @@ inline void SoftwareSerial::send() // // The receive routine called by the interrupt handler // -inline void SoftwareSerial::recv() -{ - if (--rx_tick_cnt <= 0) { // if rx_tick_cnt > 0 interrupt is discarded. Only when rx_tick_cnt reach 0 RX pin is considered +inline void SoftwareSerial::recv() { + if (--rx_tick_cnt <= 0) { // if rx_tick_cnt > 0 interrupt is discarded. Only when rx_tick_cnt reaches 0 is RX pin considered bool inbit = LL_GPIO_IsInputPinSet(_receivePinPort, _receivePinNumber) ^ _inverse_logic; if (rx_bit_cnt == -1) { // rx_bit_cnt = -1 : waiting for start bit if (!inbit) { @@ -264,31 +250,31 @@ inline void SoftwareSerial::recv() rx_bit_cnt = 0; // rx_bit_cnt == 0 : start bit received rx_tick_cnt = OVERSAMPLE + 1; // Wait 1 bit (OVERSAMPLE ticks) + 1 tick in order to sample RX pin in the middle of the edge (and not too close to the edge) rx_buffer = 0; - } else { - rx_tick_cnt = 1; // Waiting for start bit, but we don't get right level. Wait for next Interrupt to ckech RX pin level } - } else if (rx_bit_cnt >= 8) { // rx_bit_cnt >= 8 : waiting for stop bit + else + rx_tick_cnt = 1; // Waiting for start bit, but wrong level. Wait for next Interrupt to check RX pin level + } + else if (rx_bit_cnt >= 8) { // rx_bit_cnt >= 8 : waiting for stop bit if (inbit) { - // stop bit read complete add to buffer + // Stop-bit read complete. Add to buffer. uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF; if (next != _receive_buffer_head) { - // save new data in buffer: tail points to where byte goes + // save new data in buffer: tail points to byte destination _receive_buffer[_receive_buffer_tail] = rx_buffer; // save new byte _receive_buffer_tail = next; - } else { // rx_bit_cnt = x with x = [0..7] correspond to new bit x received - _buffer_overflow = true; } + else // rx_bit_cnt = x with x = [0..7] correspond to new bit x received + _buffer_overflow = true; } - // Full trame received. Resart wainting for sart bit at next interrupt + // Full trame received. Restart waiting for start bit at next interrupt rx_tick_cnt = 1; rx_bit_cnt = -1; - } else { + } + else { // data bits rx_buffer >>= 1; - if (inbit) { - rx_buffer |= 0x80; - } - rx_bit_cnt++; // Preprare for next bit + if (inbit) rx_buffer |= 0x80; + rx_bit_cnt++; // Prepare for next bit rx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks before sampling next bit } } @@ -299,16 +285,11 @@ inline void SoftwareSerial::recv() // /* static */ -inline void SoftwareSerial::handleInterrupt(HardwareTimer *timer) -{ - UNUSED(timer); - if (active_in) { - active_in->recv(); - } - if (active_out) { - active_out->send(); - } +inline void SoftwareSerial::handleInterrupt(HardwareTimer*) { + if (active_in) active_in->recv(); + if (active_out) active_out->send(); } + // // Constructor // @@ -331,50 +312,42 @@ SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool i /* Enable GPIO clock for tx and rx pin*/ set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin))); set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin))); - } else { - _Error_Handler("ERROR: invalid pin number\n", -1); } + else + _Error_Handler("ERROR: invalid pin number\n", -1); } // // Destructor // -SoftwareSerial::~SoftwareSerial() -{ - end(); -} +SoftwareSerial::~SoftwareSerial() { end(); } // // Public methods // -void SoftwareSerial::begin(long speed) -{ -#ifdef FORCE_BAUD_RATE - speed = FORCE_BAUD_RATE; -#endif +void SoftwareSerial::begin(long speed) { + #ifdef FORCE_BAUD_RATE + speed = FORCE_BAUD_RATE; + #endif _speed = speed; if (!_half_duplex) { setTX(); setRX(); listen(); - } else { - setTX(); } + else + setTX(); } -void SoftwareSerial::end() -{ +void SoftwareSerial::end() { stopListening(); } // Read data from buffer -int SoftwareSerial::read() -{ +int SoftwareSerial::read() { // Empty buffer? - if (_receive_buffer_head == _receive_buffer_tail) { - return -1; - } + if (_receive_buffer_head == _receive_buffer_tail) return -1; // Read from "head" uint8_t d = _receive_buffer[_receive_buffer_head]; // grab next byte @@ -382,47 +355,36 @@ int SoftwareSerial::read() return d; } -int SoftwareSerial::available() -{ +int SoftwareSerial::available() { return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; } -size_t SoftwareSerial::write(uint8_t b) -{ +size_t SoftwareSerial::write(uint8_t b) { // wait for previous transmit to complete _output_pending = 1; - while (active_out) - ; + while (active_out) { /* nada */ } // add start and stop bits. tx_buffer = b << 1 | 0x200; - if (_inverse_logic) { - tx_buffer = ~tx_buffer; - } + if (_inverse_logic) tx_buffer = ~tx_buffer; tx_bit_cnt = 0; tx_tick_cnt = OVERSAMPLE; setSpeed(_speed); - if (_half_duplex) { - setRXTX(false); - } + if (_half_duplex) setRXTX(false); _output_pending = 0; // make us active active_out = this; return 1; } -void SoftwareSerial::flush() -{ +void SoftwareSerial::flush() { noInterrupts(); _receive_buffer_head = _receive_buffer_tail = 0; interrupts(); } -int SoftwareSerial::peek() -{ +int SoftwareSerial::peek() { // Empty buffer? - if (_receive_buffer_head == _receive_buffer_tail) { - return -1; - } + if (_receive_buffer_head == _receive_buffer_tail) return -1; // Read from "head" return _receive_buffer[_receive_buffer_head]; From 9f359f31efd5a057cdb54a1ddbb7746a57cc59d1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 12 Nov 2019 19:05:14 -0600 Subject: [PATCH 21/23] Update SoftwareSerial.h --- Marlin/src/HAL/HAL_STM32/SoftwareSerial.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h index 45b0c03c9fd2..3799701cfe5b 100644 --- a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h +++ b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h @@ -1,4 +1,4 @@ -/* +/** * SoftwareSerial.h (formerly NewSoftSerial.h) * * Multi-instance software serial library for Arduino/Wiring @@ -36,8 +36,8 @@ #include /****************************************************************************** -* Definitions -******************************************************************************/ + * Definitions + ******************************************************************************/ #define _SS_MAX_RX_BUFF 64 // RX buffer size @@ -96,17 +96,11 @@ class SoftwareSerial : public Stream { void begin(long speed); bool listen(); void end(); - bool isListening() - { - return active_listener == this; - } + bool isListening() { return active_listener == this; } bool stopListening(); - bool overflow() - { + bool overflow() { bool ret = _buffer_overflow; - if (ret) { - _buffer_overflow = false; - } + if (ret) _buffer_overflow = false; return ret; } int peek(); @@ -115,10 +109,7 @@ class SoftwareSerial : public Stream { virtual int read(); virtual int available(); virtual void flush(); - operator bool() - { - return true; - } + operator bool() { return true; } static void setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority); From 19d3490587c31be9e14c395f12d201634d678a04 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 12 Nov 2019 19:06:28 -0600 Subject: [PATCH 22/23] Update timers.cpp --- Marlin/src/HAL/HAL_STM32/timers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/HAL_STM32/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp index 8a6e0e436e1f..709c447b0853 100644 --- a/Marlin/src/HAL/HAL_STM32/timers.cpp +++ b/Marlin/src/HAL/HAL_STM32/timers.cpp @@ -86,7 +86,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { * a call to HAL_timer_enable_interrupt() which means that there isn't * a case in which you want the timer to run without a callback. */ - timer_instance[timer_num]->resume(); //the first call to resume MUST follow the attachInterrupt + timer_instance[timer_num]->resume(); // First call to resume() MUST follow the attachInterrupt() // This is fixed in Arduino_Core_STM32 1.8. // These calls can be removed and replaced with From 362288cc095c6d3c7d4a97860d31ad2851591f89 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 12 Nov 2019 19:08:32 -0600 Subject: [PATCH 23/23] Update hal_conf_extra.h --- .../variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h index 610c0ace1b10..e0e8239aac08 100644 --- a/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h +++ b/buildroot/share/PlatformIO/variants/BIGTREE_SKR_PRO_1v1/hal_conf_extra.h @@ -13,8 +13,8 @@ #define HAL_TIM_MODULE_ENABLED #define HAL_USART_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED -//#define HAL_UART_MODULE_ENABLED //by default -// #define HAL_PCD_MODULE_ENABLED //Since STM32 v3.10700.191028 this is automatically added if any type of USB is enabled (as in Arduino IDE) +//#define HAL_UART_MODULE_ENABLED // by default +//#define HAL_PCD_MODULE_ENABLED // Since STM32 v3.10700.191028 this is automatically added if any type of USB is enabled (as in Arduino IDE) #undef HAL_SD_MODULE_ENABLED #undef HAL_DAC_MODULE_ENABLED @@ -49,4 +49,4 @@ #undef HAL_SPDIFRX_MODULE_ENABLED #undef HAL_DFSDM_MODULE_ENABLED #undef HAL_LPTIM_MODULE_ENABLED -#undef HAL_MMC_MODULE_ENABLED \ No newline at end of file +#undef HAL_MMC_MODULE_ENABLED