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.

MarlinSerial.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../platforms.h"
  23. #ifdef HAL_STM32
  24. #include "../../inc/MarlinConfig.h"
  25. #include "MarlinSerial.h"
  26. #if ENABLED(EMERGENCY_PARSER)
  27. #include "../../feature/e_parser.h"
  28. #endif
  29. #ifndef USART4
  30. #define USART4 UART4
  31. #endif
  32. #ifndef USART5
  33. #define USART5 UART5
  34. #endif
  35. #define DECLARE_SERIAL_PORT(ser_num) \
  36. void _rx_complete_irq_ ## ser_num (serial_t * obj); \
  37. MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \
  38. void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); }
  39. #if USING_HW_SERIAL1
  40. DECLARE_SERIAL_PORT(1)
  41. #endif
  42. #if USING_HW_SERIAL2
  43. DECLARE_SERIAL_PORT(2)
  44. #endif
  45. #if USING_HW_SERIAL3
  46. DECLARE_SERIAL_PORT(3)
  47. #endif
  48. #if USING_HW_SERIAL4
  49. DECLARE_SERIAL_PORT(4)
  50. #endif
  51. #if USING_HW_SERIAL5
  52. DECLARE_SERIAL_PORT(5)
  53. #endif
  54. #if USING_HW_SERIAL6
  55. DECLARE_SERIAL_PORT(6)
  56. #endif
  57. #if USING_HW_SERIAL7
  58. DECLARE_SERIAL_PORT(7)
  59. #endif
  60. #if USING_HW_SERIAL8
  61. DECLARE_SERIAL_PORT(8)
  62. #endif
  63. #if USING_HW_SERIAL9
  64. DECLARE_SERIAL_PORT(9)
  65. #endif
  66. #if USING_HW_SERIAL10
  67. DECLARE_SERIAL_PORT(10)
  68. #endif
  69. #if USING_HW_SERIALLP1
  70. DECLARE_SERIAL_PORT(LP1)
  71. #endif
  72. void MarlinSerial::begin(unsigned long baud, uint8_t config) {
  73. HardwareSerial::begin(baud, config);
  74. // Replace the IRQ callback with the one we have defined
  75. TERN_(EMERGENCY_PARSER, _serial.rx_callback = _rx_callback);
  76. }
  77. // This function is Copyright (c) 2006 Nicholas Zambetti.
  78. void MarlinSerial::_rx_complete_irq(serial_t *obj) {
  79. // No Parity error, read byte and store it in the buffer if there is room
  80. unsigned char c;
  81. if (uart_getc(obj, &c) == 0) {
  82. rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % SERIAL_RX_BUFFER_SIZE;
  83. // if we should be storing the received character into the location
  84. // just before the tail (meaning that the head would advance to the
  85. // current location of the tail), we're about to overflow the buffer
  86. // and so we don't write the character or advance the head.
  87. if (i != obj->rx_tail) {
  88. obj->rx_buff[obj->rx_head] = c;
  89. obj->rx_head = i;
  90. }
  91. #if ENABLED(EMERGENCY_PARSER)
  92. emergency_parser.update(static_cast<MSerialT*>(this)->emergency_state, c);
  93. #endif
  94. }
  95. }
  96. #endif // HAL_STM32