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

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