My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HAL.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  7. * Copyright (c) 2017 Victor Perez
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  24. #include "HAL.h"
  25. #include "../../inc/MarlinConfig.h"
  26. #include "../shared/Delay.h"
  27. #if TMC_HAS_SW_SERIAL
  28. #include "SoftwareSerial.h"
  29. #endif
  30. #if ENABLED(SRAM_EEPROM_EMULATION)
  31. #if STM32F7xx
  32. #include <stm32f7xx_ll_pwr.h>
  33. #elif STM32F4xx
  34. #include <stm32f4xx_ll_pwr.h>
  35. #else
  36. #error "SRAM_EEPROM_EMULATION is currently only supported for STM32F4xx and STM32F7xx"
  37. #endif
  38. #endif
  39. // ------------------------
  40. // Public Variables
  41. // ------------------------
  42. uint16_t HAL_adc_result;
  43. // ------------------------
  44. // Public functions
  45. // ------------------------
  46. // Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
  47. #if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
  48. // HAL pre-initialization task
  49. // Force the preinit function to run between the premain() and main() function
  50. // of the STM32 arduino core
  51. __attribute__((constructor (102)))
  52. void HAL_preinit() {
  53. enableCycleCounter();
  54. }
  55. #endif
  56. // HAL initialization task
  57. void HAL_init() {
  58. FastIO_init();
  59. #if ENABLED(SDSUPPORT)
  60. OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
  61. #endif
  62. #if PIN_EXISTS(LED)
  63. OUT_WRITE(LED_PIN, LOW);
  64. #endif
  65. #if ENABLED(SRAM_EEPROM_EMULATION)
  66. // Enable access to backup SRAM
  67. __HAL_RCC_PWR_CLK_ENABLE();
  68. HAL_PWR_EnableBkUpAccess();
  69. __HAL_RCC_BKPSRAM_CLK_ENABLE();
  70. // Enable backup regulator
  71. LL_PWR_EnableBkUpRegulator();
  72. // Wait until backup regulator is initialized
  73. while (!LL_PWR_IsActiveFlag_BRR());
  74. #endif // EEPROM_EMULATED_SRAM
  75. #if TMC_HAS_SW_SERIAL
  76. SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0);
  77. #endif
  78. }
  79. void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
  80. uint8_t HAL_get_reset_source() {
  81. return
  82. #ifdef RCC_FLAG_IWDGRST // Some sources may not exist...
  83. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) ? RST_WATCHDOG :
  84. #endif
  85. #ifdef RCC_FLAG_IWDG1RST
  86. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDG1RST) ? RST_WATCHDOG :
  87. #endif
  88. #ifdef RCC_FLAG_IWDG2RST
  89. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDG2RST) ? RST_WATCHDOG :
  90. #endif
  91. #ifdef RCC_FLAG_SFTRST
  92. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) ? RST_SOFTWARE :
  93. #endif
  94. #ifdef RCC_FLAG_PINRST
  95. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) ? RST_EXTERNAL :
  96. #endif
  97. #ifdef RCC_FLAG_PORRST
  98. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) ? RST_POWER_ON :
  99. #endif
  100. 0
  101. ;
  102. }
  103. void _delay_ms(const int delay_ms) { delay(delay_ms); }
  104. extern "C" {
  105. extern unsigned int _ebss; // end of bss section
  106. }
  107. // ------------------------
  108. // ADC
  109. // ------------------------
  110. // TODO: Make sure this doesn't cause any delay
  111. void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
  112. uint16_t HAL_adc_get_result() { return HAL_adc_result; }
  113. void flashFirmware(int16_t) { NVIC_SystemReset(); }
  114. #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC