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_Stm32f1.h 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #undef DEBUG_NONE
  29. #ifndef vsnprintf_P
  30. #define vsnprintf_P vsnprintf
  31. #endif
  32. // --------------------------------------------------------------------------
  33. // Includes
  34. // --------------------------------------------------------------------------
  35. #include <stdint.h>
  36. #include <Arduino.h>
  37. // --------------------------------------------------------------------------
  38. // Undefine DEBUG_ settings
  39. // --------------------------------------------------------------------------
  40. #undef DEBUG_NONE
  41. #undef DEBUG_FAULT
  42. #undef DEBUG_ALL
  43. // --------------------------------------------------------------------------
  44. // Includes
  45. // --------------------------------------------------------------------------
  46. #include "fastio_Stm32f1.h"
  47. #include "watchdog_Stm32f1.h"
  48. #include "HAL_timers_Stm32f1.h"
  49. // --------------------------------------------------------------------------
  50. // Defines
  51. // --------------------------------------------------------------------------
  52. #if SERIAL_PORT == -1
  53. #define MYSERIAL SerialUSB
  54. #elif SERIAL_PORT == 0
  55. #define MYSERIAL Serial
  56. #elif SERIAL_PORT == 1
  57. #define MYSERIAL Serial1
  58. #elif SERIAL_PORT == 2
  59. #define MYSERIAL Serial2
  60. #elif SERIAL_PORT == 3
  61. #define MYSERIAL Serial3
  62. #endif
  63. /**
  64. * TODO: review this to return 1 for pins that are not analog input
  65. */
  66. #ifndef analogInputToDigitalPin
  67. #define analogInputToDigitalPin(p) (p)
  68. #endif
  69. #define CRITICAL_SECTION_START noInterrupts();
  70. #define CRITICAL_SECTION_END interrupts();
  71. // On AVR this is in math.h?
  72. #define square(x) ((x)*(x))
  73. #ifndef strncpy_P
  74. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  75. #endif
  76. // Fix bug in pgm_read_ptr
  77. #undef pgm_read_ptr
  78. #define pgm_read_ptr(addr) (*(addr))
  79. #define RST_POWER_ON 1
  80. #define RST_EXTERNAL 2
  81. #define RST_BROWN_OUT 4
  82. #define RST_WATCHDOG 8
  83. #define RST_JTAG 16
  84. #define RST_SOFTWARE 32
  85. #define RST_BACKUP 64
  86. // --------------------------------------------------------------------------
  87. // Types
  88. // --------------------------------------------------------------------------
  89. typedef int8_t pin_t;
  90. // --------------------------------------------------------------------------
  91. // Public Variables
  92. // --------------------------------------------------------------------------
  93. /** result of last ADC conversion */
  94. extern uint16_t HAL_adc_result;
  95. // --------------------------------------------------------------------------
  96. // Public functions
  97. // --------------------------------------------------------------------------
  98. // Disable interrupts
  99. #define cli() noInterrupts()
  100. // Enable interrupts
  101. #define sei() interrupts()
  102. // Memory related
  103. #define __bss_end __bss_end__
  104. /** clear reset reason */
  105. void HAL_clear_reset_source (void);
  106. /** reset reason */
  107. uint8_t HAL_get_reset_source (void);
  108. void _delay_ms(const int delay);
  109. /*
  110. extern "C" {
  111. int freeMemory(void);
  112. }
  113. */
  114. extern "C" char* _sbrk(int incr);
  115. /*
  116. static int freeMemory() {
  117. volatile int top;
  118. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  119. return top;
  120. }
  121. */
  122. static int freeMemory() {
  123. volatile char top;
  124. return &top - reinterpret_cast<char*>(_sbrk(0));
  125. }
  126. // SPI: Extended functions which take a channel number (hardware SPI only)
  127. /** Write single byte to specified SPI channel */
  128. void spiSend(uint32_t chan, byte b);
  129. /** Write buffer to specified SPI channel */
  130. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  131. /** Read single byte from specified SPI channel */
  132. uint8_t spiRec(uint32_t chan);
  133. // EEPROM
  134. /**
  135. * TODO: Write all this eeprom stuff. Can emulate eeprom in flash as last resort.
  136. * Wire library should work for i2c eeproms.
  137. */
  138. void eeprom_write_byte(unsigned char *pos, unsigned char value);
  139. unsigned char eeprom_read_byte(unsigned char *pos);
  140. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  141. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  142. // ADC
  143. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT_ANALOG);
  144. inline void HAL_adc_init(void) {}
  145. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  146. #define HAL_READ_ADC HAL_adc_result
  147. void HAL_adc_start_conversion(const uint8_t adc_pin);
  148. uint16_t HAL_adc_get_result(void);
  149. /* Todo: Confirm none of this is needed.
  150. uint16_t HAL_getAdcReading(uint8_t chan);
  151. void HAL_startAdcConversion(uint8_t chan);
  152. uint8_t HAL_pinToAdcChannel(int pin);
  153. uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
  154. //uint16_t HAL_getAdcSuperSample(uint8_t chan);
  155. void HAL_enable_AdcFreerun(void);
  156. //void HAL_disable_AdcFreerun(uint8_t chan);
  157. */
  158. #define GET_PIN_MAP_PIN(index) index
  159. #define GET_PIN_MAP_INDEX(pin) pin
  160. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  161. #endif // _HAL_STM32F1_H