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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://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. extern "C" {
  33. #include <debug_frmwrk.h>
  34. }
  35. #include "../../sd/cardreader.h"
  36. #include "../../inc/MarlinConfig.h"
  37. #include "HAL.h"
  38. #include "timers.h"
  39. extern uint32_t MSC_SD_Init(uint8_t pdrv);
  40. extern "C" int isLPC1769();
  41. extern "C" void disk_timerproc(void);
  42. void SysTick_Callback() { disk_timerproc(); }
  43. void HAL_init(void) {
  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. for (uint8_t i = 0; i < 6; ++i) {
  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. // Initialise the SD card chip select pins as soon as possible
  83. #if PIN_EXISTS(SS)
  84. OUT_WRITE(SS_PIN, HIGH);
  85. #endif
  86. #if PIN_EXISTS(ONBOARD_SD_CS) && ONBOARD_SD_CS_PIN != 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. LPC_SC->CLKOUTCFG |= (1<<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. #if !BOTH(SHARED_SD_CARD, INIT_SDCARD_ON_BOOT) && DISABLED(NO_SD_HOST_DRIVE)
  113. MSC_SD_Init(0); // Enable USB SD card access
  114. #endif
  115. const millis_t usb_timeout = millis() + 2000;
  116. while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
  117. delay(50);
  118. HAL_idletask();
  119. #if PIN_EXISTS(LED)
  120. TOGGLE(LED_PIN); // Flash quickly during USB initialization
  121. #endif
  122. }
  123. #if NUM_SERIAL > 0
  124. MYSERIAL0.begin(BAUDRATE);
  125. #if NUM_SERIAL > 1
  126. MYSERIAL1.begin(BAUDRATE);
  127. #endif
  128. SERIAL_PRINTF("\n\necho:%s (%dMhz) Initialized\n", isLPC1769() ? "LPC1769" : "LPC1768", SystemCoreClock / 1000000);
  129. SERIAL_FLUSHTX();
  130. #endif
  131. HAL_timer_init();
  132. }
  133. // HAL idle task
  134. void HAL_idletask(void) {
  135. #if ENABLED(SHARED_SD_CARD)
  136. // If Marlin is using the SD card we need to lock it to prevent access from
  137. // a PC via USB.
  138. // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
  139. // this will not reliably detect delete operations. To be safe we will lock
  140. // the disk if Marlin has it mounted. Unfortuately there is currently no way
  141. // to unmount the disk from the LCD menu.
  142. // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
  143. if (card.isMounted())
  144. MSC_Aquire_Lock();
  145. else
  146. MSC_Release_Lock();
  147. #endif
  148. // Perform USB stack housekeeping
  149. MSC_RunDeferredCommands();
  150. }
  151. #endif // TARGET_LPC1768