My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

HAL_timers_STM32F7.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2017 Victor Perez
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. // --------------------------------------------------------------------------
  24. // Includes
  25. // --------------------------------------------------------------------------
  26. #include <stdint.h>
  27. // --------------------------------------------------------------------------
  28. // Defines
  29. // --------------------------------------------------------------------------
  30. #define FORCE_INLINE __attribute__((always_inline)) inline
  31. #define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked?
  32. #define HAL_TIMER_TYPE_MAX 0xFFFF
  33. #define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
  34. #define STEP_TIMER_NUM 0 // index of timer to use for stepper
  35. #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
  36. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  37. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  38. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  39. #define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz
  40. #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
  41. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  42. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  43. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  44. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  45. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  46. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  47. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  48. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  49. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  50. #define TEMP_ISR_ENABLED() HAL_timer_interrupt_enabled(TEMP_TIMER_NUM)
  51. // TODO change this
  52. extern void TC5_Handler();
  53. extern void TC7_Handler();
  54. #define HAL_STEP_TIMER_ISR() void TC5_Handler()
  55. #define HAL_TEMP_TIMER_ISR() void TC7_Handler()
  56. // --------------------------------------------------------------------------
  57. // Types
  58. // --------------------------------------------------------------------------
  59. typedef struct {
  60. TIM_HandleTypeDef timerdef;
  61. IRQn_Type IRQ_Id;
  62. uint32_t callback;
  63. } tTimerConfig;
  64. // --------------------------------------------------------------------------
  65. // Public Variables
  66. // --------------------------------------------------------------------------
  67. //extern const tTimerConfig timerConfig[];
  68. // --------------------------------------------------------------------------
  69. // Public functions
  70. // --------------------------------------------------------------------------
  71. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  72. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  73. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  74. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  75. void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
  76. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  77. uint32_t HAL_timer_get_count(const uint8_t timer_num);
  78. void HAL_timer_isr_prologue(const uint8_t timer_num);
  79. #define HAL_timer_isr_epilogue(TIMER_NUM)