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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 <http://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. #if defined(STM32F4) && SERIAL_PORT == 0
  41. #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  42. #elif SERIAL_PORT == -1
  43. #define MYSERIAL0 SerialUSB
  44. #elif SERIAL_PORT == 0
  45. #define MYSERIAL0 Serial1
  46. #elif SERIAL_PORT == 1
  47. #define MYSERIAL0 SerialUART1
  48. #elif SERIAL_PORT == 2
  49. #define MYSERIAL0 SerialUART2
  50. #elif SERIAL_PORT == 3
  51. #define MYSERIAL0 SerialUART3
  52. #elif SERIAL_PORT == 4
  53. #define MYSERIAL0 SerialUART4
  54. #elif SERIAL_PORT == 5
  55. #define MYSERIAL0 SerialUART5
  56. #elif SERIAL_PORT == 6
  57. #define MYSERIAL0 SerialUART6
  58. #else
  59. #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
  60. #endif
  61. #ifdef SERIAL_PORT_2
  62. #if defined(STM32F4) && SERIAL_PORT_2 == 0
  63. #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
  64. #elif SERIAL_PORT_2 == SERIAL_PORT
  65. #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
  66. #elif SERIAL_PORT_2 == -1
  67. #define MYSERIAL1 SerialUSB
  68. #elif SERIAL_PORT_2 == 0
  69. #define MYSERIAL1 Serial1
  70. #elif SERIAL_PORT_2 == 1
  71. #define MYSERIAL1 SerialUART1
  72. #elif SERIAL_PORT_2 == 2
  73. #define MYSERIAL1 SerialUART2
  74. #elif SERIAL_PORT_2 == 3
  75. #define MYSERIAL1 SerialUART3
  76. #elif SERIAL_PORT_2 == 4
  77. #define MYSERIAL1 SerialUART4
  78. #elif SERIAL_PORT_2 == 5
  79. #define MYSERIAL1 SerialUART5
  80. #elif SERIAL_PORT_2 == 6
  81. #define MYSERIAL1 SerialUART6
  82. #else
  83. #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
  84. #endif
  85. #define NUM_SERIAL 2
  86. #else
  87. #define NUM_SERIAL 1
  88. #endif
  89. #ifdef DGUS_SERIAL_PORT
  90. #if defined(STM32F4) && DGUS_SERIAL_PORT == 0
  91. #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  92. #elif DGUS_SERIAL_PORT == SERIAL_PORT
  93. #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
  94. #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
  95. #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
  96. #elif DGUS_SERIAL_PORT == -1
  97. #define DGUS_SERIAL SerialUSB
  98. #elif DGUS_SERIAL_PORT == 0
  99. #define DGUS_SERIAL Serial1
  100. #elif DGUS_SERIAL_PORT == 1
  101. #define DGUS_SERIAL SerialUART1
  102. #elif DGUS_SERIAL_PORT == 2
  103. #define DGUS_SERIAL SerialUART2
  104. #elif DGUS_SERIAL_PORT == 3
  105. #define DGUS_SERIAL SerialUART3
  106. #elif DGUS_SERIAL_PORT == 4
  107. #define DGUS_SERIAL SerialUART4
  108. #elif DGUS_SERIAL_PORT == 5
  109. #define DGUS_SERIAL SerialUART5
  110. #elif DGUS_SERIAL_PORT == 6
  111. #define DGUS_SERIAL SerialUART6
  112. #else
  113. #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
  114. #endif
  115. #endif
  116. /**
  117. * TODO: review this to return 1 for pins that are not analog input
  118. */
  119. #ifndef analogInputToDigitalPin
  120. #define analogInputToDigitalPin(p) (p)
  121. #endif
  122. #define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
  123. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  124. #define ISRS_ENABLED() (!__get_PRIMASK())
  125. #define ENABLE_ISRS() __enable_irq()
  126. #define DISABLE_ISRS() __disable_irq()
  127. #define cli() __disable_irq()
  128. #define sei() __enable_irq()
  129. // On AVR this is in math.h?
  130. #define square(x) ((x)*(x))
  131. #ifndef strncpy_P
  132. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  133. #endif
  134. // Fix bug in pgm_read_ptr
  135. #undef pgm_read_ptr
  136. #define pgm_read_ptr(addr) (*(addr))
  137. // ------------------------
  138. // Types
  139. // ------------------------
  140. typedef int8_t pin_t;
  141. #ifdef STM32F4
  142. #define HAL_SERVO_LIB libServo
  143. #endif
  144. // ------------------------
  145. // Public Variables
  146. // ------------------------
  147. // Result of last ADC conversion
  148. extern uint16_t HAL_adc_result;
  149. // ------------------------
  150. // Public functions
  151. // ------------------------
  152. // Memory related
  153. #define __bss_end __bss_end__
  154. inline void HAL_init() {}
  155. // Clear reset reason
  156. void HAL_clear_reset_source();
  157. // Reset reason
  158. uint8_t HAL_get_reset_source();
  159. void _delay_ms(const int delay);
  160. /*
  161. extern "C" {
  162. int freeMemory();
  163. }
  164. */
  165. extern "C" char* _sbrk(int incr);
  166. /*
  167. int freeMemory() {
  168. volatile int top;
  169. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  170. return top;
  171. }
  172. */
  173. #pragma GCC diagnostic push
  174. #pragma GCC diagnostic ignored "-Wunused-function"
  175. static inline int freeMemory() {
  176. volatile char top;
  177. return &top - reinterpret_cast<char*>(_sbrk(0));
  178. }
  179. #pragma GCC diagnostic pop
  180. //
  181. // ADC
  182. //
  183. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  184. inline void HAL_adc_init() {}
  185. #define HAL_ADC_VREF 3.3
  186. #define HAL_ADC_RESOLUTION 10
  187. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  188. #define HAL_READ_ADC() HAL_adc_result
  189. #define HAL_ADC_READY() true
  190. void HAL_adc_start_conversion(const uint8_t adc_pin);
  191. uint16_t HAL_adc_get_result();
  192. #define GET_PIN_MAP_PIN(index) index
  193. #define GET_PIN_MAP_INDEX(pin) pin
  194. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  195. #ifdef STM32F4
  196. #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
  197. #define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
  198. #endif