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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifdef TARGET_LPC1768
  2. // ---------------------
  3. // Userspace entry point
  4. // ---------------------
  5. extern void setup();
  6. extern void loop();
  7. extern "C" {
  8. #include <lpc17xx_gpio.h>
  9. }
  10. #include <usb/usb.h>
  11. #include <usb/usbcfg.h>
  12. #include <usb/usbhw.h>
  13. #include <usb/usbcore.h>
  14. #include <usb/cdc.h>
  15. #include <usb/cdcuser.h>
  16. #include <usb/mscuser.h>
  17. extern "C" {
  18. #include <debug_frmwrk.h>
  19. #include <chanfs/diskio.h>
  20. #include <chanfs/ff.h>
  21. }
  22. #include "../../inc/MarlinConfig.h"
  23. #include "HAL.h"
  24. #include "fastio.h"
  25. #include "HAL_timers.h"
  26. #include <stdio.h>
  27. #include <stdarg.h>
  28. #include <Arduino.h>
  29. #include "serial.h"
  30. #include "LPC1768_PWM.h"
  31. static __INLINE uint32_t SysTick_Config(uint32_t ticks) {
  32. if (ticks > SysTick_LOAD_RELOAD_Msk)
  33. return (1); /* Reload value impossible */
  34. SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
  35. NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(0, 0, 0)); /* set Priority for Cortex-M3 System Interrupts */
  36. SysTick->VAL = 0; /* Load the SysTick Counter Value */
  37. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  38. SysTick_CTRL_TICKINT_Msk |
  39. SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
  40. return (0); /* Function successful */
  41. }
  42. extern "C" {
  43. extern void disk_timerproc(void);
  44. volatile uint32_t _millis;
  45. void SysTick_Handler(void) {
  46. ++_millis;
  47. disk_timerproc(); /* Disk timer process */
  48. }
  49. }
  50. // runs after clock init and before global static constructors
  51. extern "C" void SystemPostInit() {
  52. _millis = 0; // initialise the millisecond counter value;
  53. SysTick_Config(SystemCoreClock / 1000); // start millisecond global counter
  54. GPIO_SetDir(4, 1UL << 28, 1);
  55. for (int i = 0; i < 4; ++i) {
  56. GPIO_SetValue(4, 1UL << 28);
  57. delay(100);
  58. GPIO_ClearValue(4, 1UL << 28);
  59. delay(100);
  60. }
  61. }
  62. // detect 17x[4-8] (100MHz) or 17x9 (120MHz)
  63. static bool isLPC1769() {
  64. #define IAP_LOCATION 0x1FFF1FF1
  65. uint32_t command[1];
  66. uint32_t result[5];
  67. typedef void (*IAP)(uint32_t*, uint32_t*);
  68. IAP iap = (IAP) IAP_LOCATION;
  69. command[0] = 54;
  70. iap(command, result);
  71. return ((result[1] & 0x00100000) != 0);
  72. }
  73. extern uint32_t MSC_SD_Init(uint8_t pdrv);
  74. int main(void) {
  75. (void)MSC_SD_Init(0);
  76. USB_Init(); // USB Initialization
  77. USB_Connect(TRUE); // USB Connect
  78. const uint32_t usb_timeout = millis() + 2000;
  79. while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
  80. delay(50);
  81. #if PIN_EXISTS(LED)
  82. TOGGLE(LED_PIN); // Flash fast while USB initialisation completes
  83. #endif
  84. }
  85. #if NUM_SERIAL > 0
  86. MYSERIAL0.begin(BAUDRATE);
  87. #if NUM_SERIAL > 1
  88. MYSERIAL1.begin(BAUDRATE);
  89. #endif
  90. SERIAL_PRINTF("\n\n%s (%dMhz) UART0 Initialised\n", isLPC1769() ? "LPC1769" : "LPC1768", SystemCoreClock / 1000000);
  91. SERIAL_FLUSHTX();
  92. #endif
  93. HAL_timer_init();
  94. LPC1768_PWM_init();
  95. setup();
  96. for (;;) loop();
  97. }
  98. #endif // TARGET_LPC1768