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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #pragma once
  24. #define CPU_32_BIT
  25. #ifndef vsnprintf_P
  26. #define vsnprintf_P vsnprintf
  27. #endif
  28. // --------------------------------------------------------------------------
  29. // Includes
  30. // --------------------------------------------------------------------------
  31. #include "../shared/Marduino.h"
  32. #include "../shared/math_32bit.h"
  33. #include "../shared/HAL_SPI.h"
  34. #include "fastio_STM32F4.h"
  35. #include "watchdog_STM32F4.h"
  36. #include "HAL_timers_STM32F4.h"
  37. #include "../../inc/MarlinConfigPre.h"
  38. #include <stdint.h>
  39. #ifdef USBCON
  40. #include <USBSerial.h>
  41. #endif
  42. // --------------------------------------------------------------------------
  43. // Defines
  44. // --------------------------------------------------------------------------
  45. //Serial override
  46. //extern HalSerial usb_serial;
  47. #if SERIAL_PORT == 0
  48. #error "Serial port 0 does not exist"
  49. #endif
  50. #if !WITHIN(SERIAL_PORT, -1, 6)
  51. #error "SERIAL_PORT must be from -1 to 6"
  52. #endif
  53. #if SERIAL_PORT == -1
  54. #define MYSERIAL0 SerialUSB
  55. #elif SERIAL_PORT == 1
  56. #define MYSERIAL0 SerialUART1
  57. #elif SERIAL_PORT == 2
  58. #define MYSERIAL0 SerialUART2
  59. #elif SERIAL_PORT == 3
  60. #define MYSERIAL0 SerialUART3
  61. #elif SERIAL_PORT == 4
  62. #define MYSERIAL0 SerialUART4
  63. #elif SERIAL_PORT == 5
  64. #define MYSERIAL0 SerialUART5
  65. #elif SERIAL_PORT == 6
  66. #define MYSERIAL0 SerialUART6
  67. #endif
  68. #ifdef SERIAL_PORT_2
  69. #if SERIAL_PORT_2 == 0
  70. #error "Serial port 0 does not exist"
  71. #endif
  72. #if !WITHIN(SERIAL_PORT_2, -1, 6)
  73. #error "SERIAL_PORT_2 must be from -1 to 6"
  74. #elif SERIAL_PORT_2 == SERIAL_PORT
  75. #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
  76. #endif
  77. #define NUM_SERIAL 2
  78. #if SERIAL_PORT_2 == -1
  79. #define MYSERIAL1 SerialUSB
  80. #elif SERIAL_PORT_2 == 1
  81. #define MYSERIAL1 SerialUART1
  82. #elif SERIAL_PORT_2 == 2
  83. #define MYSERIAL1 SerialUART2
  84. #elif SERIAL_PORT_2 == 3
  85. #define MYSERIAL1 SerialUART3
  86. #elif SERIAL_PORT_2 == 4
  87. #define MYSERIAL1 SerialUART4
  88. #elif SERIAL_PORT_2 == 5
  89. #define MYSERIAL1 SerialUART5
  90. #elif SERIAL_PORT_2 == 6
  91. #define MYSERIAL1 SerialUART6
  92. #endif
  93. #else
  94. #define NUM_SERIAL 1
  95. #endif
  96. #undef _BV
  97. #define _BV(b) (1 << (b))
  98. /**
  99. * TODO: review this to return 1 for pins that are not analog input
  100. */
  101. #ifndef analogInputToDigitalPin
  102. #define analogInputToDigitalPin(p) (p)
  103. #endif
  104. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  105. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  106. #define ISRS_ENABLED() (!__get_PRIMASK())
  107. #define ENABLE_ISRS() __enable_irq()
  108. #define DISABLE_ISRS() __disable_irq()
  109. #define cli() __disable_irq()
  110. #define sei() __enable_irq()
  111. // On AVR this is in math.h?
  112. #define square(x) ((x)*(x))
  113. #ifndef strncpy_P
  114. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  115. #endif
  116. // Fix bug in pgm_read_ptr
  117. #undef pgm_read_ptr
  118. #define pgm_read_ptr(addr) (*(addr))
  119. // --------------------------------------------------------------------------
  120. // Types
  121. // --------------------------------------------------------------------------
  122. typedef int8_t pin_t;
  123. #define HAL_SERVO_LIB libServo
  124. // --------------------------------------------------------------------------
  125. // Public Variables
  126. // --------------------------------------------------------------------------
  127. /** result of last ADC conversion */
  128. extern uint16_t HAL_adc_result;
  129. // --------------------------------------------------------------------------
  130. // Public functions
  131. // --------------------------------------------------------------------------
  132. // Memory related
  133. #define __bss_end __bss_end__
  134. inline void HAL_init(void) { }
  135. /** clear reset reason */
  136. void HAL_clear_reset_source (void);
  137. /** reset reason */
  138. uint8_t HAL_get_reset_source(void);
  139. void _delay_ms(const int delay);
  140. /*
  141. extern "C" {
  142. int freeMemory(void);
  143. }
  144. */
  145. extern "C" char* _sbrk(int incr);
  146. /*
  147. static int freeMemory() {
  148. volatile int top;
  149. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  150. return top;
  151. }
  152. */
  153. static int freeMemory() {
  154. volatile char top;
  155. return &top - reinterpret_cast<char*>(_sbrk(0));
  156. }
  157. //
  158. // SPI: Extended functions which take a channel number (hardware SPI only)
  159. //
  160. /** Write single byte to specified SPI channel */
  161. void spiSend(uint32_t chan, byte b);
  162. /** Write buffer to specified SPI channel */
  163. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  164. /** Read single byte from specified SPI channel */
  165. uint8_t spiRec(uint32_t chan);
  166. //
  167. // EEPROM
  168. //
  169. /**
  170. * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
  171. * Wire library should work for i2c EEPROMs.
  172. */
  173. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  174. uint8_t eeprom_read_byte(uint8_t *pos);
  175. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  176. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  177. //
  178. // ADC
  179. //
  180. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  181. inline void HAL_adc_init(void) {}
  182. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  183. #define HAL_READ_ADC() HAL_adc_result
  184. #define HAL_ADC_READY() true
  185. void HAL_adc_start_conversion(const uint8_t adc_pin);
  186. uint16_t HAL_adc_get_result(void);
  187. #define GET_PIN_MAP_PIN(index) index
  188. #define GET_PIN_MAP_INDEX(pin) pin
  189. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  190. #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
  191. #define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)