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.

main.cpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #ifdef TARGET_LPC1768
  23. #include <usb/usb.h>
  24. #include <usb/usbcfg.h>
  25. #include <usb/usbhw.h>
  26. #include <usb/usbcore.h>
  27. #include <usb/cdc.h>
  28. #include <usb/cdcuser.h>
  29. #include <usb/mscuser.h>
  30. #include <CDCSerial.h>
  31. #include <usb/mscuser.h>
  32. #include "../../inc/MarlinConfig.h"
  33. #include "../../core/millis_t.h"
  34. #include "../../sd/cardreader.h"
  35. extern uint32_t MSC_SD_Init(uint8_t pdrv);
  36. extern "C" {
  37. #include <debug_frmwrk.h>
  38. extern "C" int isLPC1769();
  39. extern "C" void disk_timerproc();
  40. }
  41. void SysTick_Callback() { disk_timerproc(); }
  42. TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial());
  43. void MarlinHAL::init() {
  44. // Init LEDs
  45. #if PIN_EXISTS(LED)
  46. SET_DIR_OUTPUT(LED_PIN);
  47. WRITE_PIN_CLR(LED_PIN);
  48. #if PIN_EXISTS(LED2)
  49. SET_DIR_OUTPUT(LED2_PIN);
  50. WRITE_PIN_CLR(LED2_PIN);
  51. #if PIN_EXISTS(LED3)
  52. SET_DIR_OUTPUT(LED3_PIN);
  53. WRITE_PIN_CLR(LED3_PIN);
  54. #if PIN_EXISTS(LED4)
  55. SET_DIR_OUTPUT(LED4_PIN);
  56. WRITE_PIN_CLR(LED4_PIN);
  57. #endif
  58. #endif
  59. #endif
  60. // Flash status LED 3 times to indicate Marlin has started booting
  61. LOOP_L_N(i, 6) {
  62. TOGGLE(LED_PIN);
  63. delay(100);
  64. }
  65. #endif
  66. // Init Servo Pins
  67. #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
  68. #if HAS_SERVO_0
  69. INIT_SERVO(0);
  70. #endif
  71. #if HAS_SERVO_1
  72. INIT_SERVO(1);
  73. #endif
  74. #if HAS_SERVO_2
  75. INIT_SERVO(2);
  76. #endif
  77. #if HAS_SERVO_3
  78. INIT_SERVO(3);
  79. #endif
  80. //debug_frmwrk_init();
  81. //_DBG("\n\nDebug running\n");
  82. // Initialize the SD card chip select pins as soon as possible
  83. #if PIN_EXISTS(SD_SS)
  84. OUT_WRITE(SD_SS_PIN, HIGH);
  85. #endif
  86. #if PIN_EXISTS(ONBOARD_SD_CS) && ONBOARD_SD_CS_PIN != SD_SS_PIN
  87. OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH);
  88. #endif
  89. #ifdef LPC1768_ENABLE_CLKOUT_12M
  90. /**
  91. * CLKOUTCFG register
  92. * bit 8 (CLKOUT_EN) = enables CLKOUT signal. Disabled for now to prevent glitch when enabling GPIO.
  93. * bits 7:4 (CLKOUTDIV) = set to 0 for divider setting of /1
  94. * bits 3:0 (CLKOUTSEL) = set to 1 to select main crystal oscillator as CLKOUT source
  95. */
  96. LPC_SC->CLKOUTCFG = (0<<8)|(0<<4)|(1<<0);
  97. // set P1.27 pin to function 01 (CLKOUT)
  98. PINSEL_CFG_Type PinCfg;
  99. PinCfg.Portnum = 1;
  100. PinCfg.Pinnum = 27;
  101. PinCfg.Funcnum = 1; // function 01 (CLKOUT)
  102. PinCfg.OpenDrain = 0; // not open drain
  103. PinCfg.Pinmode = 2; // no pull-up/pull-down
  104. PINSEL_ConfigPin(&PinCfg);
  105. // now set CLKOUT_EN bit
  106. SBI(LPC_SC->CLKOUTCFG, 8);
  107. #endif
  108. USB_Init(); // USB Initialization
  109. USB_Connect(false); // USB clear connection
  110. delay(1000); // Give OS time to notice
  111. USB_Connect(true);
  112. TERN_(HAS_SD_HOST_DRIVE, MSC_SD_Init(0)); // Enable USB SD card access
  113. const millis_t usb_timeout = millis() + 2000;
  114. while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
  115. delay(50);
  116. idletask();
  117. #if PIN_EXISTS(LED)
  118. TOGGLE(LED_PIN); // Flash quickly during USB initialization
  119. #endif
  120. }
  121. HAL_timer_init();
  122. TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
  123. }
  124. // HAL idle task
  125. void MarlinHAL::idletask() {
  126. #if HAS_SHARED_MEDIA
  127. // If Marlin is using the SD card we need to lock it to prevent access from
  128. // a PC via USB.
  129. // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
  130. // this will not reliably detect delete operations. To be safe we will lock
  131. // the disk if Marlin has it mounted. Unfortunately there is currently no way
  132. // to unmount the disk from the LCD menu.
  133. // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
  134. if (card.isMounted())
  135. MSC_Aquire_Lock();
  136. else
  137. MSC_Release_Lock();
  138. #endif
  139. // Perform USB stack housekeeping
  140. MSC_RunDeferredCommands();
  141. }
  142. #endif // TARGET_LPC1768