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.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (C) 2016 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. #ifdef ARDUINO_ARCH_STM32
  24. // --------------------------------------------------------------------------
  25. // Includes
  26. // --------------------------------------------------------------------------
  27. #include "HAL.h"
  28. #include "../../inc/MarlinConfig.h"
  29. #include "../shared/Delay.h"
  30. #if ENABLED(EEPROM_EMULATED_WITH_SRAM)
  31. #if STM32F7xx
  32. #include "stm32f7xx_ll_pwr.h"
  33. #else
  34. #error "EEPROM_EMULATED_WITH_SRAM is currently only supported for STM32F7xx"
  35. #endif
  36. #endif // EEPROM_EMULATED_WITH_SRAM
  37. // --------------------------------------------------------------------------
  38. // Externals
  39. // --------------------------------------------------------------------------
  40. // --------------------------------------------------------------------------
  41. // Local defines
  42. // --------------------------------------------------------------------------
  43. // --------------------------------------------------------------------------
  44. // Types
  45. // --------------------------------------------------------------------------
  46. // --------------------------------------------------------------------------
  47. // Variables
  48. // --------------------------------------------------------------------------
  49. // --------------------------------------------------------------------------
  50. // Public Variables
  51. // --------------------------------------------------------------------------
  52. uint16_t HAL_adc_result;
  53. // --------------------------------------------------------------------------
  54. // Private Variables
  55. // --------------------------------------------------------------------------
  56. // --------------------------------------------------------------------------
  57. // Function prototypes
  58. // --------------------------------------------------------------------------
  59. // --------------------------------------------------------------------------
  60. // Private functions
  61. // --------------------------------------------------------------------------
  62. // --------------------------------------------------------------------------
  63. // Public functions
  64. // --------------------------------------------------------------------------
  65. // Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
  66. #if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
  67. // HAL pre-initialization task
  68. // Force the preinit function to run between the premain() and main() function
  69. // of the STM32 arduino core
  70. __attribute__((constructor (102)))
  71. void HAL_preinit() {
  72. enableCycleCounter();
  73. }
  74. #endif
  75. // HAL initialization task
  76. void HAL_init(void) {
  77. FastIO_init();
  78. #if ENABLED(SDSUPPORT)
  79. OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
  80. #endif
  81. #if PIN_EXISTS(LED)
  82. OUT_WRITE(LED_PIN, LOW);
  83. #endif
  84. #if ENABLED(EEPROM_EMULATED_WITH_SRAM)
  85. // Enable access to backup SRAM
  86. __HAL_RCC_PWR_CLK_ENABLE();
  87. HAL_PWR_EnableBkUpAccess();
  88. __HAL_RCC_BKPSRAM_CLK_ENABLE();
  89. // Enable backup regulator
  90. LL_PWR_EnableBkUpRegulator();
  91. // Wait until backup regulator is initialized
  92. while (!LL_PWR_IsActiveFlag_BRR());
  93. #endif // EEPROM_EMULATED_SRAM
  94. }
  95. void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
  96. uint8_t HAL_get_reset_source (void) {
  97. if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
  98. if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) return RST_SOFTWARE;
  99. if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET) return RST_EXTERNAL;
  100. if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET) return RST_POWER_ON;
  101. return 0;
  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. void HAL_adc_start_conversion(const uint8_t adc_pin) {
  111. HAL_adc_result = analogRead(adc_pin);
  112. }
  113. uint16_t HAL_adc_get_result(void) {
  114. return HAL_adc_result;
  115. }
  116. #endif // ARDUINO_ARCH_STM32