My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. /**
  25. * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
  26. */
  27. #define CPU_32_BIT
  28. #include "../../core/macros.h"
  29. #include "../shared/Marduino.h"
  30. #include "../shared/math_32bit.h"
  31. #include "../shared/HAL_SPI.h"
  32. #include "fastio.h"
  33. #include "watchdog.h"
  34. #include "timers.h"
  35. #include <stdint.h>
  36. #include <util/atomic.h>
  37. #include "../../inc/MarlinConfigPre.h"
  38. #ifdef USE_USB_COMPOSITE
  39. #include "msc_sd.h"
  40. #endif
  41. // ------------------------
  42. // Defines
  43. // ------------------------
  44. #ifndef STM32_FLASH_SIZE
  45. #ifdef MCU_STM32F103RE
  46. #define STM32_FLASH_SIZE 512
  47. #else
  48. #define STM32_FLASH_SIZE 256
  49. #endif
  50. #endif
  51. #ifdef SERIAL_USB
  52. #ifndef USE_USB_COMPOSITE
  53. #define UsbSerial Serial
  54. #else
  55. #define UsbSerial MarlinCompositeSerial
  56. #endif
  57. #define MSerial1 Serial1
  58. #define MSerial2 Serial2
  59. #define MSerial3 Serial3
  60. #define MSerial4 Serial4
  61. #define MSerial5 Serial5
  62. #else
  63. #define MSerial1 Serial
  64. #define MSerial2 Serial1
  65. #define MSerial3 Serial2
  66. #define MSerial4 Serial3
  67. #define MSerial5 Serial4
  68. #endif
  69. #if SERIAL_PORT == 0
  70. #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  71. #elif SERIAL_PORT == -1
  72. #define MYSERIAL0 UsbSerial
  73. #elif SERIAL_PORT == 1
  74. #define MYSERIAL0 MSerial1
  75. #elif SERIAL_PORT == 2
  76. #define MYSERIAL0 MSerial2
  77. #elif SERIAL_PORT == 3
  78. #define MYSERIAL0 MSerial3
  79. #elif SERIAL_PORT == 4
  80. #define MYSERIAL0 MSerial4
  81. #elif SERIAL_PORT == 5
  82. #define MYSERIAL0 MSerial5
  83. #else
  84. #error "SERIAL_PORT must be from -1 to 5. Please update your configuration."
  85. #endif
  86. #ifdef SERIAL_PORT_2
  87. #if SERIAL_PORT_2 == 0
  88. #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
  89. #elif SERIAL_PORT_2 == SERIAL_PORT
  90. #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
  91. #elif SERIAL_PORT_2 == -1
  92. #define MYSERIAL1 UsbSerial
  93. #elif SERIAL_PORT_2 == 1
  94. #define MYSERIAL1 MSerial1
  95. #elif SERIAL_PORT_2 == 2
  96. #define MYSERIAL1 MSerial2
  97. #elif SERIAL_PORT_2 == 3
  98. #define MYSERIAL1 MSerial3
  99. #elif SERIAL_PORT_2 == 4
  100. #define MYSERIAL1 MSerial4
  101. #elif SERIAL_PORT_2 == 5
  102. #define MYSERIAL1 MSerial5
  103. #else
  104. #error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration."
  105. #endif
  106. #define NUM_SERIAL 2
  107. #else
  108. #define NUM_SERIAL 1
  109. #endif
  110. // Set interrupt grouping for this MCU
  111. void HAL_init();
  112. #define HAL_IDLETASK 1
  113. void HAL_idletask();
  114. /**
  115. * TODO: review this to return 1 for pins that are not analog input
  116. */
  117. #ifndef analogInputToDigitalPin
  118. #define analogInputToDigitalPin(p) (p)
  119. #endif
  120. #ifndef digitalPinHasPWM
  121. #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
  122. #endif
  123. #define CRITICAL_SECTION_START uint32_t primask = __get_primask(); (void)__iCliRetVal()
  124. #define CRITICAL_SECTION_END if (!primask) (void)__iSeiRetVal()
  125. #define ISRS_ENABLED() (!__get_primask())
  126. #define ENABLE_ISRS() ((void)__iSeiRetVal())
  127. #define DISABLE_ISRS() ((void)__iCliRetVal())
  128. // On AVR this is in math.h?
  129. #define square(x) ((x)*(x))
  130. #ifndef strncpy_P
  131. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  132. #endif
  133. // Fix bug in pgm_read_ptr
  134. #undef pgm_read_ptr
  135. #define pgm_read_ptr(addr) (*(addr))
  136. #define RST_POWER_ON 1
  137. #define RST_EXTERNAL 2
  138. #define RST_BROWN_OUT 4
  139. #define RST_WATCHDOG 8
  140. #define RST_JTAG 16
  141. #define RST_SOFTWARE 32
  142. #define RST_BACKUP 64
  143. // ------------------------
  144. // Types
  145. // ------------------------
  146. typedef int8_t pin_t;
  147. // ------------------------
  148. // Public Variables
  149. // ------------------------
  150. // Result of last ADC conversion
  151. extern uint16_t HAL_adc_result;
  152. // ------------------------
  153. // Public functions
  154. // ------------------------
  155. // Disable interrupts
  156. #define cli() noInterrupts()
  157. // Enable interrupts
  158. #define sei() interrupts()
  159. // Memory related
  160. #define __bss_end __bss_end__
  161. // Clear reset reason
  162. void HAL_clear_reset_source();
  163. // Reset reason
  164. uint8_t HAL_get_reset_source();
  165. void _delay_ms(const int delay);
  166. #pragma GCC diagnostic push
  167. #pragma GCC diagnostic ignored "-Wunused-function"
  168. /*
  169. extern "C" {
  170. int freeMemory();
  171. }
  172. */
  173. extern "C" char* _sbrk(int incr);
  174. /*
  175. static int freeMemory() {
  176. volatile int top;
  177. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  178. return top;
  179. }
  180. */
  181. static int freeMemory() {
  182. volatile char top;
  183. return &top - reinterpret_cast<char*>(_sbrk(0));
  184. }
  185. #pragma GCC diagnostic pop
  186. //
  187. // EEPROM
  188. //
  189. /**
  190. * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
  191. * Wire library should work for i2c EEPROMs.
  192. */
  193. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  194. uint8_t eeprom_read_byte(uint8_t *pos);
  195. void eeprom_read_block(void *__dst, const void *__src, size_t __n);
  196. void eeprom_update_block(const void *__src, void *__dst, size_t __n);
  197. //
  198. // ADC
  199. //
  200. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT_ANALOG);
  201. void HAL_adc_init();
  202. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  203. #define HAL_ADC_RESOLUTION 10
  204. #define HAL_READ_ADC() HAL_adc_result
  205. #define HAL_ADC_READY() true
  206. void HAL_adc_start_conversion(const uint8_t adc_pin);
  207. uint16_t HAL_adc_get_result();
  208. uint16_t analogRead(pin_t pin); // need HAL_ANALOG_SELECT() first
  209. void analogWrite(pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
  210. #define GET_PIN_MAP_PIN(index) index
  211. #define GET_PIN_MAP_INDEX(pin) pin
  212. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  213. #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
  214. #define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
  215. #define PLATFORM_M997_SUPPORT
  216. void flashFirmware(int16_t value);