Marlin 2.0 for Flying Bear 4S/5
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.9 KiB

/**
* Marlin 3D Printer Firmware
*
4 years ago
* Copyright (c) 2020 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
4 years ago
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
// ------------------------
// Local defines
// ------------------------
// ------------------------
// Public functions
// ------------------------
/**
* Timer_clock1: Prescaler 2 -> 36 MHz
* Timer_clock2: Prescaler 8 -> 9 MHz
* Timer_clock3: Prescaler 32 -> 2.25 MHz
* Timer_clock4: Prescaler 128 -> 562.5 kHz
*/
/**
* TODO: Calculate Timer prescale value, so we get the 32bit to adjust
*/
4 years ago
void timer_set_interrupt_priority(uint_fast8_t timer_num, uint_fast8_t priority) {
nvic_irq_num irq_num;
switch (timer_num) {
case 1: irq_num = NVIC_TIMER1_CC; break;
case 2: irq_num = NVIC_TIMER2; break;
case 3: irq_num = NVIC_TIMER3; break;
case 4: irq_num = NVIC_TIMER4; break;
case 5: irq_num = NVIC_TIMER5; break;
#ifdef STM32_HIGH_DENSITY
// 6 & 7 are basic timers, avoid them
case 8: irq_num = NVIC_TIMER8_CC; break;
#endif
default:
/**
* This should never happen. Add a Sanitycheck for timer number.
* Should be a general timer since basic timers have no CC channels.
*/
4 years ago
return;
}
4 years ago
nvic_irq_set_priority(irq_num, priority);
}
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
/**
* Give the Stepper ISR a higher priority (lower number)
* so it automatically preempts the Temperature ISR.
*/
switch (timer_num) {
case STEP_TIMER_NUM:
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_pause(STEP_TIMER_DEV);
timer_set_mode(STEP_TIMER_DEV, STEP_TIMER_CHAN, TIMER_OUTPUT_COMPARE); // counter
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_set_count(STEP_TIMER_DEV, 0);
timer_set_prescaler(STEP_TIMER_DEV, (uint16_t)(STEPPER_TIMER_PRESCALE - 1));
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
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_no_ARR_preload_ARPE(STEP_TIMER_DEV); // Need to be sure no preload on ARR register
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_attach_interrupt(STEP_TIMER_DEV, STEP_TIMER_CHAN, stepTC_Handler);
4 years ago
timer_set_interrupt_priority(STEP_TIMER_NUM, STEP_TIMER_IRQ_PRIO);
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_generate_update(STEP_TIMER_DEV);
timer_resume(STEP_TIMER_DEV);
break;
case TEMP_TIMER_NUM:
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_pause(TEMP_TIMER_DEV);
timer_set_mode(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, TIMER_OUTPUT_COMPARE);
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_set_count(TEMP_TIMER_DEV, 0);
timer_set_prescaler(TEMP_TIMER_DEV, (uint16_t)(TEMP_TIMER_PRESCALE - 1));
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
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));
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler);
4 years ago
timer_set_interrupt_priority(TEMP_TIMER_NUM, TEMP_TIMER_IRQ_PRIO);
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
7 years ago
timer_generate_update(TEMP_TIMER_DEV);
timer_resume(TEMP_TIMER_DEV);
break;
}
}
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: ENABLE_STEPPER_DRIVER_INTERRUPT(); break;
case TEMP_TIMER_NUM: ENABLE_TEMPERATURE_INTERRUPT(); break;
}
}
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: DISABLE_STEPPER_DRIVER_INTERRUPT(); break;
case TEMP_TIMER_NUM: DISABLE_TEMPERATURE_INTERRUPT(); break;
}
}
static inline bool timer_irq_enabled(const timer_dev * const dev, const uint8_t interrupt) {
return bool(*bb_perip(&(dev->regs).gen->DIER, interrupt));
}
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: return timer_irq_enabled(STEP_TIMER_DEV, STEP_TIMER_CHAN);
case TEMP_TIMER_NUM: return timer_irq_enabled(TEMP_TIMER_DEV, TEMP_TIMER_CHAN);
}
return false;
}
timer_dev* get_timer_dev(int number) {
switch (number) {
#if STM32_HAVE_TIMER(1)
case 1: return &timer1;
#endif
#if STM32_HAVE_TIMER(2)
case 2: return &timer2;
#endif
#if STM32_HAVE_TIMER(3)
case 3: return &timer3;
#endif
#if STM32_HAVE_TIMER(4)
case 4: return &timer4;
#endif
#if STM32_HAVE_TIMER(5)
case 5: return &timer5;
#endif
#if STM32_HAVE_TIMER(6)
case 6: return &timer6;
#endif
#if STM32_HAVE_TIMER(7)
case 7: return &timer7;
#endif
#if STM32_HAVE_TIMER(8)
case 8: return &timer8;
#endif
#if STM32_HAVE_TIMER(9)
case 9: return &timer9;
#endif
#if STM32_HAVE_TIMER(10)
case 10: return &timer10;
#endif
#if STM32_HAVE_TIMER(11)
case 11: return &timer11;
#endif
#if STM32_HAVE_TIMER(12)
case 12: return &timer12;
#endif
#if STM32_HAVE_TIMER(13)
case 13: return &timer13;
#endif
#if STM32_HAVE_TIMER(14)
case 14: return &timer14;
#endif
default: return nullptr;
}
}
#endif // __STM32F1__