My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HAL.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /**
  24. * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
  25. */
  26. #ifndef _HAL_STM32F1_H
  27. #define _HAL_STM32F1_H
  28. #define CPU_32_BIT
  29. #undef DEBUG_NONE
  30. #ifndef vsnprintf_P
  31. #define vsnprintf_P vsnprintf
  32. #endif
  33. // --------------------------------------------------------------------------
  34. // Includes
  35. // --------------------------------------------------------------------------
  36. #include <stdint.h>
  37. #include <util/atomic.h>
  38. #include <Arduino.h>
  39. // --------------------------------------------------------------------------
  40. // Undefine DEBUG_ settings
  41. // --------------------------------------------------------------------------
  42. #undef DEBUG_NONE
  43. #undef DEBUG_FAULT
  44. #undef DEBUG_ALL
  45. // --------------------------------------------------------------------------
  46. // Includes
  47. // --------------------------------------------------------------------------
  48. #include "../shared/math_32bit.h"
  49. #include "../shared/HAL_SPI.h"
  50. #include "fastio_Stm32f1.h"
  51. #include "watchdog_Stm32f1.h"
  52. #include "HAL_timers_Stm32f1.h"
  53. // --------------------------------------------------------------------------
  54. // Defines
  55. // --------------------------------------------------------------------------
  56. #if !WITHIN(SERIAL_PORT, -1, 3)
  57. #error "SERIAL_PORT must be from -1 to 3"
  58. #endif
  59. #if SERIAL_PORT == -1
  60. extern USBSerial SerialUSB;
  61. #define MYSERIAL0 SerialUSB
  62. #elif SERIAL_PORT == 0
  63. #define MYSERIAL0 Serial
  64. #elif SERIAL_PORT == 1
  65. #define MYSERIAL0 Serial1
  66. #elif SERIAL_PORT == 2
  67. #define MYSERIAL0 Serial2
  68. #elif SERIAL_PORT == 3
  69. #define MYSERIAL0 Serial3
  70. #endif
  71. #ifdef SERIAL_PORT_2
  72. #if !WITHIN(SERIAL_PORT_2, -1, 3)
  73. #error "SERIAL_PORT_2 must be from -1 to 3"
  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. extern USBSerial SerialUSB;
  80. #define MYSERIAL1 SerialUSB
  81. #elif SERIAL_PORT_2 == 0
  82. #define MYSERIAL1 Serial
  83. #elif SERIAL_PORT_2 == 1
  84. #define MYSERIAL1 Serial1
  85. #elif SERIAL_PORT_2 == 2
  86. #define MYSERIAL1 Serial2
  87. #elif SERIAL_PORT_2 == 3
  88. #define MYSERIAL1 Serial3
  89. #endif
  90. #else
  91. #define NUM_SERIAL 1
  92. #endif
  93. // Use HAL_init() to set interrupt grouping.
  94. #define HAL_INIT
  95. void HAL_init();
  96. /**
  97. * TODO: review this to return 1 for pins that are not analog input
  98. */
  99. #ifndef analogInputToDigitalPin
  100. #define analogInputToDigitalPin(p) (p)
  101. #endif
  102. #define CRITICAL_SECTION_START uint32_t primask = __get_primask(); (void)__iCliRetVal()
  103. #define CRITICAL_SECTION_END if (!primask) (void)__iSeiRetVal()
  104. #define ISRS_ENABLED() (!__get_primask())
  105. #define ENABLE_ISRS() ((void)__iSeiRetVal())
  106. #define DISABLE_ISRS() ((void)__iCliRetVal())
  107. // On AVR this is in math.h?
  108. #define square(x) ((x)*(x))
  109. #ifndef strncpy_P
  110. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  111. #endif
  112. // Fix bug in pgm_read_ptr
  113. #undef pgm_read_ptr
  114. #define pgm_read_ptr(addr) (*(addr))
  115. #define RST_POWER_ON 1
  116. #define RST_EXTERNAL 2
  117. #define RST_BROWN_OUT 4
  118. #define RST_WATCHDOG 8
  119. #define RST_JTAG 16
  120. #define RST_SOFTWARE 32
  121. #define RST_BACKUP 64
  122. // --------------------------------------------------------------------------
  123. // Types
  124. // --------------------------------------------------------------------------
  125. typedef int8_t pin_t;
  126. // --------------------------------------------------------------------------
  127. // Public Variables
  128. // --------------------------------------------------------------------------
  129. /** result of last ADC conversion */
  130. extern uint16_t HAL_adc_result;
  131. // --------------------------------------------------------------------------
  132. // Public functions
  133. // --------------------------------------------------------------------------
  134. // Disable interrupts
  135. #define cli() noInterrupts()
  136. // Enable interrupts
  137. #define sei() interrupts()
  138. // Memory related
  139. #define __bss_end __bss_end__
  140. /** clear reset reason */
  141. void HAL_clear_reset_source (void);
  142. /** reset reason */
  143. uint8_t HAL_get_reset_source (void);
  144. void _delay_ms(const int delay);
  145. /*
  146. extern "C" {
  147. int freeMemory(void);
  148. }
  149. */
  150. extern "C" char* _sbrk(int incr);
  151. /*
  152. static int freeMemory() {
  153. volatile int top;
  154. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  155. return top;
  156. }
  157. */
  158. static int freeMemory() {
  159. volatile char top;
  160. return &top - reinterpret_cast<char*>(_sbrk(0));
  161. }
  162. // SPI: Extended functions which take a channel number (hardware SPI only)
  163. /** Write single byte to specified SPI channel */
  164. void spiSend(uint32_t chan, byte b);
  165. /** Write buffer to specified SPI channel */
  166. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  167. /** Read single byte from specified SPI channel */
  168. uint8_t spiRec(uint32_t chan);
  169. // EEPROM
  170. /**
  171. * TODO: Write all this eeprom stuff. Can emulate eeprom in flash as last resort.
  172. * Wire library should work for i2c eeproms.
  173. */
  174. void eeprom_write_byte(unsigned char *pos, unsigned char value);
  175. unsigned char eeprom_read_byte(unsigned char *pos);
  176. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  177. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  178. // ADC
  179. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT_ANALOG);
  180. void HAL_adc_init(void);
  181. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  182. #define HAL_READ_ADC() HAL_adc_result
  183. #define HAL_ADC_READY() true
  184. void HAL_adc_start_conversion(const uint8_t adc_pin);
  185. uint16_t HAL_adc_get_result(void);
  186. /* Todo: Confirm none of this is needed.
  187. uint16_t HAL_getAdcReading(uint8_t chan);
  188. void HAL_startAdcConversion(uint8_t chan);
  189. uint8_t HAL_pinToAdcChannel(int pin);
  190. uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
  191. //uint16_t HAL_getAdcSuperSample(uint8_t chan);
  192. void HAL_enable_AdcFreerun(void);
  193. //void HAL_disable_AdcFreerun(uint8_t chan);
  194. */
  195. #define GET_PIN_MAP_PIN(index) index
  196. #define GET_PIN_MAP_INDEX(pin) pin
  197. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  198. #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
  199. #endif // _HAL_STM32F1_H