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.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #pragma once
  24. #define CPU_32_BIT
  25. #include "../../inc/MarlinConfigPre.h"
  26. #include "../shared/Marduino.h"
  27. #include "../shared/math_32bit.h"
  28. #include "../shared/HAL_SPI.h"
  29. #include "fastio.h"
  30. #include "watchdog.h"
  31. #include <stdint.h>
  32. #if defined(STM32F4) && USBCON
  33. #include <USBSerial.h>
  34. #endif
  35. // ------------------------
  36. // Defines
  37. // ------------------------
  38. // Serial override
  39. //extern HalSerial usb_serial;
  40. #define _MSERIAL(X) SerialUART##X
  41. #define MSERIAL(X) _MSERIAL(X)
  42. #define SerialUART0 Serial1
  43. #if defined(STM32F4) && SERIAL_PORT == 0
  44. #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  45. #elif SERIAL_PORT == -1
  46. #define MYSERIAL0 SerialUSB
  47. #elif WITHIN(SERIAL_PORT, 0, 6)
  48. #define MYSERIAL0 MSERIAL(SERIAL_PORT)
  49. #else
  50. #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
  51. #endif
  52. #ifdef SERIAL_PORT_2
  53. #if defined(STM32F4) && SERIAL_PORT_2 == 0
  54. #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
  55. #elif SERIAL_PORT_2 == -1
  56. #define MYSERIAL1 SerialUSB
  57. #elif WITHIN(SERIAL_PORT_2, 0, 6)
  58. #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
  59. #else
  60. #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
  61. #endif
  62. #endif
  63. #ifdef LCD_SERIAL_PORT
  64. #if defined(STM32F4) && LCD_SERIAL_PORT == 0
  65. #error "LCD_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  66. #elif LCD_SERIAL_PORT == -1
  67. #define LCD_SERIAL SerialUSB
  68. #elif WITHIN(LCD_SERIAL_PORT, 0, 6)
  69. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  70. #else
  71. #error "LCD_SERIAL_PORT must be from -1 to 6. Please update your configuration."
  72. #endif
  73. #endif
  74. /**
  75. * TODO: review this to return 1 for pins that are not analog input
  76. */
  77. #ifndef analogInputToDigitalPin
  78. #define analogInputToDigitalPin(p) (p)
  79. #endif
  80. #define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
  81. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  82. #define ISRS_ENABLED() (!__get_PRIMASK())
  83. #define ENABLE_ISRS() __enable_irq()
  84. #define DISABLE_ISRS() __disable_irq()
  85. #define cli() __disable_irq()
  86. #define sei() __enable_irq()
  87. // On AVR this is in math.h?
  88. #define square(x) ((x)*(x))
  89. #ifndef strncpy_P
  90. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  91. #endif
  92. // Fix bug in pgm_read_ptr
  93. #undef pgm_read_ptr
  94. #define pgm_read_ptr(addr) (*(addr))
  95. // ------------------------
  96. // Types
  97. // ------------------------
  98. typedef int8_t pin_t;
  99. #ifdef STM32F4
  100. #define HAL_SERVO_LIB libServo
  101. #endif
  102. // ------------------------
  103. // Public Variables
  104. // ------------------------
  105. // Result of last ADC conversion
  106. extern uint16_t HAL_adc_result;
  107. // ------------------------
  108. // Public functions
  109. // ------------------------
  110. // Memory related
  111. #define __bss_end __bss_end__
  112. inline void HAL_init() {}
  113. // Clear reset reason
  114. void HAL_clear_reset_source();
  115. // Reset reason
  116. uint8_t HAL_get_reset_source();
  117. void _delay_ms(const int delay);
  118. /*
  119. extern "C" {
  120. int freeMemory();
  121. }
  122. */
  123. extern "C" char* _sbrk(int incr);
  124. /*
  125. int freeMemory() {
  126. volatile int top;
  127. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  128. return top;
  129. }
  130. */
  131. #pragma GCC diagnostic push
  132. #pragma GCC diagnostic ignored "-Wunused-function"
  133. static inline int freeMemory() {
  134. volatile char top;
  135. return &top - reinterpret_cast<char*>(_sbrk(0));
  136. }
  137. #pragma GCC diagnostic pop
  138. //
  139. // ADC
  140. //
  141. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  142. inline void HAL_adc_init() {}
  143. #define HAL_ADC_VREF 3.3
  144. #define HAL_ADC_RESOLUTION 10
  145. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  146. #define HAL_READ_ADC() HAL_adc_result
  147. #define HAL_ADC_READY() true
  148. void HAL_adc_start_conversion(const uint8_t adc_pin);
  149. uint16_t HAL_adc_get_result();
  150. #define GET_PIN_MAP_PIN(index) index
  151. #define GET_PIN_MAP_INDEX(pin) pin
  152. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  153. #ifdef STM32F4
  154. #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
  155. #define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
  156. #endif