My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MinSerial.cpp 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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. #ifdef ARDUINO_ARCH_SAM
  23. #include "../../inc/MarlinConfigPre.h"
  24. #if ENABLED(POSTMORTEM_DEBUGGING)
  25. #include "../shared/MinSerial.h"
  26. #include <stdarg.h>
  27. static void TXBegin() {
  28. // Disable UART interrupt in NVIC
  29. NVIC_DisableIRQ( UART_IRQn );
  30. // We NEED memory barriers to ensure Interrupts are actually disabled!
  31. // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
  32. __DSB();
  33. __ISB();
  34. // Disable clock
  35. pmc_disable_periph_clk( ID_UART );
  36. // Configure PMC
  37. pmc_enable_periph_clk( ID_UART );
  38. // Disable PDC channel
  39. UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
  40. // Reset and disable receiver and transmitter
  41. UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;
  42. // Configure mode: 8bit, No parity, 1 bit stop
  43. UART->UART_MR = UART_MR_CHMODE_NORMAL | US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO;
  44. // Configure baudrate (asynchronous, no oversampling) to BAUDRATE bauds
  45. UART->UART_BRGR = (SystemCoreClock / (BAUDRATE << 4));
  46. // Enable receiver and transmitter
  47. UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
  48. }
  49. // A SW memory barrier, to ensure GCC does not overoptimize loops
  50. #define sw_barrier() __asm__ volatile("": : :"memory");
  51. static void TX(char c) {
  52. while (!(UART->UART_SR & UART_SR_TXRDY)) { WDT_Restart(WDT); sw_barrier(); };
  53. UART->UART_THR = c;
  54. }
  55. void install_min_serial() {
  56. HAL_min_serial_init = &TXBegin;
  57. HAL_min_serial_out = &TX;
  58. }
  59. #if DISABLED(DYNAMIC_VECTORTABLE)
  60. extern "C" {
  61. __attribute__((naked)) void JumpHandler_ASM() {
  62. __asm__ __volatile__ (
  63. "b CommonHandler_ASM\n"
  64. );
  65. }
  66. void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler();
  67. void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler();
  68. void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler();
  69. void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler();
  70. void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler();
  71. }
  72. #endif
  73. #endif // POSTMORTEM_DEBUGGING
  74. #endif // ARDUINO_ARCH_SAM