My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

HAL.cpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #include "../platforms.h"
  24. #ifdef HAL_STM32
  25. #include "HAL.h"
  26. #include "usb_serial.h"
  27. #include "../../inc/MarlinConfig.h"
  28. #include "../shared/Delay.h"
  29. #ifdef USBCON
  30. DefaultSerial1 MSerial0(false, SerialUSB);
  31. #endif
  32. #if ENABLED(SRAM_EEPROM_EMULATION)
  33. #if STM32F7xx
  34. #include <stm32f7xx_ll_pwr.h>
  35. #elif STM32F4xx
  36. #include <stm32f4xx_ll_pwr.h>
  37. #else
  38. #error "SRAM_EEPROM_EMULATION is currently only supported for STM32F4xx and STM32F7xx"
  39. #endif
  40. #endif
  41. #if HAS_SD_HOST_DRIVE
  42. #include "msc_sd.h"
  43. #include "usbd_cdc_if.h"
  44. #endif
  45. // ------------------------
  46. // Public Variables
  47. // ------------------------
  48. uint16_t MarlinHAL::adc_result;
  49. // ------------------------
  50. // Public functions
  51. // ------------------------
  52. #if ENABLED(POSTMORTEM_DEBUGGING)
  53. extern void install_min_serial();
  54. #endif
  55. // HAL initialization task
  56. void MarlinHAL::init() {
  57. // Ensure F_CPU is a constant expression.
  58. // If the compiler breaks here, it means that delay code that should compute at compile time will not work.
  59. // So better safe than sorry here.
  60. constexpr int cpuFreq = F_CPU;
  61. UNUSED(cpuFreq);
  62. #if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT) && (defined(SDSS) && SDSS != -1)
  63. OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
  64. #endif
  65. #if PIN_EXISTS(LED)
  66. OUT_WRITE(LED_PIN, LOW);
  67. #endif
  68. #if ENABLED(SRAM_EEPROM_EMULATION)
  69. __HAL_RCC_PWR_CLK_ENABLE();
  70. HAL_PWR_EnableBkUpAccess(); // Enable access to backup SRAM
  71. __HAL_RCC_BKPSRAM_CLK_ENABLE();
  72. LL_PWR_EnableBkUpRegulator(); // Enable backup regulator
  73. while (!LL_PWR_IsActiveFlag_BRR()); // Wait until backup regulator is initialized
  74. #endif
  75. SetTimerInterruptPriorities();
  76. #if ENABLED(EMERGENCY_PARSER) && USBD_USE_CDC
  77. USB_Hook_init();
  78. #endif
  79. TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
  80. TERN_(HAS_SD_HOST_DRIVE, MSC_SD_init()); // Enable USB SD card access
  81. #if PIN_EXISTS(USB_CONNECT)
  82. OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING); // USB clear connection
  83. delay(1000); // Give OS time to notice
  84. WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
  85. #endif
  86. }
  87. // HAL idle task
  88. void MarlinHAL::idletask() {
  89. #if HAS_SHARED_MEDIA
  90. // Stm32duino currently doesn't have a "loop/idle" method
  91. CDC_resume_receive();
  92. CDC_continue_transmit();
  93. #endif
  94. }
  95. void MarlinHAL::reboot() { NVIC_SystemReset(); }
  96. uint8_t MarlinHAL::get_reset_source() {
  97. return
  98. #ifdef RCC_FLAG_IWDGRST // Some sources may not exist...
  99. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) ? RST_WATCHDOG :
  100. #endif
  101. #ifdef RCC_FLAG_IWDG1RST
  102. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDG1RST) ? RST_WATCHDOG :
  103. #endif
  104. #ifdef RCC_FLAG_IWDG2RST
  105. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDG2RST) ? RST_WATCHDOG :
  106. #endif
  107. #ifdef RCC_FLAG_SFTRST
  108. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) ? RST_SOFTWARE :
  109. #endif
  110. #ifdef RCC_FLAG_PINRST
  111. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) ? RST_EXTERNAL :
  112. #endif
  113. #ifdef RCC_FLAG_PORRST
  114. RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) ? RST_POWER_ON :
  115. #endif
  116. 0
  117. ;
  118. }
  119. void MarlinHAL::clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
  120. extern "C" {
  121. extern unsigned int _ebss; // end of bss section
  122. }
  123. // Reset the system to initiate a firmware flash
  124. WEAK void flashFirmware(const int16_t) { hal.reboot(); }
  125. // Maple Compatibility
  126. volatile uint32_t systick_uptime_millis = 0;
  127. systickCallback_t systick_user_callback;
  128. void systick_attach_callback(systickCallback_t cb) { systick_user_callback = cb; }
  129. void HAL_SYSTICK_Callback() {
  130. systick_uptime_millis++;
  131. if (systick_user_callback) systick_user_callback();
  132. }
  133. #endif // HAL_STM32