Use FastIO, sanity-check LPC SD options, apply formatting (#12231)

This commit is contained in:
Scott Lahteine 2018-10-26 15:23:02 -05:00 committed by GitHub
parent d015f746cc
commit 5580773191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 53 deletions

View File

@ -76,14 +76,14 @@ void Servo_Handler(timer16_Sequence_t timer, Tc *tc, uint8_t channel) {
tc->TC_CHANNEL[channel].TC_SR; tc->TC_CHANNEL[channel].TC_SR;
if (Channel[timer] < 0) if (Channel[timer] < 0)
tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer
else if (SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive) else if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && SERVO(timer, Channel[timer]).Pin.isActive)
digitalWrite(SERVO(timer,Channel[timer]).Pin.nbr, LOW); // pulse this channel low if activated digitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, LOW); // pulse this channel low if activated
Channel[timer]++; // increment to the next channel Channel[timer]++; // increment to the next channel
if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) { if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) {
tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + SERVO(timer,Channel[timer]).ticks; tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + SERVO(timer,Channel[timer]).ticks;
if (SERVO(timer,Channel[timer]).Pin.isActive) // check if activated if (SERVO(timer,Channel[timer]).Pin.isActive) // check if activated
digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,HIGH); // its an active channel so pulse it high digitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, HIGH); // its an active channel so pulse it high
} }
else { else {
// finished all channels so wait for the refresh period to expire before starting over // finished all channels so wait for the refresh period to expire before starting over

View File

@ -74,3 +74,11 @@
|| MB(RAMPS_14_RE_ARM_SF)) || MB(RAMPS_14_RE_ARM_SF))
#error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI" #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI"
#endif #endif
#if 1 < (ENABLED(LPC_SD_CUSTOM_CABLE) + ENABLED(LPC_SD_LCD) + ENABLED(LPC_SD_ONBOARD))
#error "Enable only one of LPC_SD_CUSTOM_CABLE, LPC_SD_LCD, or LPC_SD_ONBOARD."
#endif
#if 1 < (ENABLED(USB_SD_DISABLED) + ENABLED(USB_SD_ONBOARD))
#error "Enable only one of USB_SD_DISABLED or USB_SD_ONBOARD."
#endif

View File

@ -56,21 +56,25 @@ void HAL_init() {
//debug_frmwrk_init(); //debug_frmwrk_init();
//_DBG("\n\nDebug running\n"); //_DBG("\n\nDebug running\n");
// Initialise the SD card chip select pins as soon as possible // Initialise the SD card chip select pins as soon as possible
#ifdef SS_PIN #if PIN_EXISTS(SS)
digitalWrite(SS_PIN, HIGH); WRITE(SS_PIN, HIGH);
pinMode(SS_PIN, OUTPUT); SET_OUTPUT(SS_PIN);
#endif #endif
#ifdef ONBOARD_SD_CS
digitalWrite(ONBOARD_SD_CS, HIGH); #if defined(ONBOARD_SD_CS) && ONBOARD_SD_CS > -1
pinMode(ONBOARD_SD_CS, OUTPUT); WRITE(ONBOARD_SD_CS, HIGH);
SET_OUTPUT(ONBOARD_SD_CS);
#endif #endif
USB_Init(); // USB Initialization USB_Init(); // USB Initialization
USB_Connect(FALSE); // USB clear connection USB_Connect(FALSE); // USB clear connection
delay(1000); // Give OS time to notice delay(1000); // Give OS time to notice
USB_Connect(TRUE); USB_Connect(TRUE);
#ifndef USB_SD_DISABLED
#if DISABLED(USB_SD_DISABLED)
MSC_SD_Init(0); // Enable USB SD card access MSC_SD_Init(0); // Enable USB SD card access
#endif #endif
const millis_t usb_timeout = millis() + 2000; const millis_t usb_timeout = millis() + 2000;
while (!USB_Configuration && PENDING(millis(), usb_timeout)) { while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
delay(50); delay(50);
@ -94,7 +98,7 @@ void HAL_init() {
// HAL idle task // HAL idle task
void HAL_idletask(void) { void HAL_idletask(void) {
#if ENABLED(SDSUPPORT) && defined(SHARED_SD_CARD) #if ENABLED(SDSUPPORT) && ENABLED(SHARED_SD_CARD)
// If Marlin is using the SD card we need to lock it to prevent access from // If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB. // a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but

View File

@ -85,8 +85,8 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
timerConfig[0].IRQ_Id = TIM5_IRQn; timerConfig[0].IRQ_Id = TIM5_IRQn;
timerConfig[0].callback = (uint32_t)TC5_Handler; timerConfig[0].callback = (uint32_t)TC5_Handler;
HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0); HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0);
pinMode(STEPPER_ENABLE_PIN,OUTPUT); SET_OUTPUT(STEPPER_ENABLE_PIN);
digitalWrite(STEPPER_ENABLE_PIN,LOW); WRITE(STEPPER_ENABLE_PIN);
break; break;
case TEMP_TIMER_NUM: case TEMP_TIMER_NUM:
//TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM) //TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM)

View File

@ -190,7 +190,7 @@ void TMC26XStepper::start() {
pinMode(step_pin, OUTPUT); pinMode(step_pin, OUTPUT);
pinMode(dir_pin, OUTPUT); pinMode(dir_pin, OUTPUT);
pinMode(cs_pin, OUTPUT); pinMode(cs_pin, OUTPUT);
//pinMode(STEPPER_ENABLE_PIN, OUTPUT); //SET_OUTPUT(STEPPER_ENABLE_PIN);
digitalWrite(step_pin, LOW); digitalWrite(step_pin, LOW);
digitalWrite(dir_pin, LOW); digitalWrite(dir_pin, LOW);
digitalWrite(cs_pin, HIGH); digitalWrite(cs_pin, HIGH);
@ -887,7 +887,7 @@ inline void TMC26XStepper::send262(uint32_t datagram) {
//} //}
//select the TMC driver //select the TMC driver
digitalWrite(cs_pin,LOW); digitalWrite(cs_pin, LOW);
//ensure that only valid bist are set (0-19) //ensure that only valid bist are set (0-19)
//datagram &=REGISTER_BIT_PATTERN; //datagram &=REGISTER_BIT_PATTERN;
@ -916,7 +916,7 @@ inline void TMC26XStepper::send262(uint32_t datagram) {
#endif #endif
//deselect the TMC chip //deselect the TMC chip
digitalWrite(cs_pin,HIGH); digitalWrite(cs_pin, HIGH);
//restore the previous SPI mode if neccessary //restore the previous SPI mode if neccessary
//if the mode is not correct set it to mode 3 //if the mode is not correct set it to mode 3

View File

@ -187,14 +187,15 @@
// is powered on to enable SD access. // is powered on to enable SD access.
#if ENABLED(LPC_SD_LCD) #if ENABLED(LPC_SD_LCD)
#define SCK_PIN P0_15 #define SCK_PIN P0_15
#define MISO_PIN P0_17 #define MISO_PIN P0_17
#define MOSI_PIN P0_18 #define MOSI_PIN P0_18
#define SS_PIN P1_23 // Chip select for SD card used by Marlin #define SS_PIN P1_23 // Chip select for SD card used by Marlin
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#endif
#if ENABLED(LPC_SD_ONBOARD) #elif ENABLED(LPC_SD_ONBOARD)
#if ENABLED(USB_SD_ONBOARD) #if ENABLED(USB_SD_ONBOARD)
// When sharing the SD card with a PC we want the menu options to // When sharing the SD card with a PC we want the menu options to
// mount/unmount the card and refresh it. So we disable card detect. // mount/unmount the card and refresh it. So we disable card detect.
@ -206,4 +207,5 @@
#define MOSI_PIN P0_09 #define MOSI_PIN P0_09
#define SS_PIN P0_06 // Chip select for SD card used by Marlin #define SS_PIN P0_06 // Chip select for SD card used by Marlin
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#endif #endif

View File

@ -196,16 +196,17 @@
/* /*
* There are a number of configurations available for the SBase SD card reader. * There are a number of configurations available for the SBase SD card reader.
* A custom cable can be used to allow access to the LCD based SD card. * - A custom cable can be used to allow access to the LCD based SD card.
* A standard cable can be used for access to the LCD SD card (but no SD detect). * - A standard cable can be used for access to the LCD SD card (but no SD detect).
* The onboard SD card can be used and optionally shared with a PC via USB. * - The onboard SD card can be used and optionally shared with a PC via USB.
*/ */
//#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD //#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD
//#define LPC_SD_LCD // Marlin uses the SD drive attached to the LCD //#define LPC_SD_LCD // Marlin uses the SD drive attached to the LCD
#define LPC_SD_ONBOARD // Marlin uses the SD drive attached to the control board #define LPC_SD_ONBOARD // Marlin uses the SD drive attached to the control board
#ifdef LPC_SD_CUSTOM_CABLE #if ENABLED(LPC_SD_CUSTOM_CABLE)
/** /**
* A custom cable is needed. See the README file in the * A custom cable is needed. See the README file in the
* Marlin\src\config\examples\Mks\Sbase directory * Marlin\src\config\examples\Mks\Sbase directory
@ -218,43 +219,41 @@
* If you can't find a pin to use for the LCD's SD_DETECT then comment out * If you can't find a pin to use for the LCD's SD_DETECT then comment out
* SD_DETECT_PIN entirely and remove that wire from the the custom cable. * SD_DETECT_PIN entirely and remove that wire from the the custom cable.
*/ */
#define SD_DETECT_PIN P2_11 // J8-5 (moved from EXP2 P0.27) #define SD_DETECT_PIN P2_11 // J8-5 (moved from EXP2 P0.27)
#define SCK_PIN P1_22 // J8-2 (moved from EXP2 P0.7) #define SCK_PIN P1_22 // J8-2 (moved from EXP2 P0.7)
#define MISO_PIN P1_23 // J8-3 (moved from EXP2 P0.8) #define MISO_PIN P1_23 // J8-3 (moved from EXP2 P0.8)
#define MOSI_PIN P2_12 // J8-4 (moved from EXP2 P0.9) #define MOSI_PIN P2_12 // J8-4 (moved from EXP2 P0.9)
#define SS_PIN P0_28 // Chip select for SD card used by Marlin #define SS_PIN P0_28 // Chip select for SD card used by Marlin
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#define LPC_SOFTWARE_SPI // With a custom cable we need software SPI because the #define LPC_SOFTWARE_SPI // With a custom cable we need software SPI because the
// selected pins are not on a hardware SPI controller // selected pins are not on a hardware SPI controller
#endif #elif ENABLED(LPC_SD_LCD)
#ifdef LPC_SD_LCD
// use standard cable and header, SPI and SD detect sre shared with on-board SD card // use standard cable and header, SPI and SD detect sre shared with on-board SD card
// hardware SPI is used for both SD cards. The detect pin is shred between the // hardware SPI is used for both SD cards. The detect pin is shred between the
// LCD and onboard SD readers so we disable it. // LCD and onboard SD readers so we disable it.
#undef SD_DETECT_PIN #define SCK_PIN P0_07
#define SCK_PIN P0_07 #define MISO_PIN P0_08
#define MISO_PIN P0_08 #define MOSI_PIN P0_09
#define MOSI_PIN P0_09 #define SS_PIN P0_28 // Chip select for SD card used by Marlin
#define SS_PIN P0_28 // Chip select for SD card used by Marlin #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#endif #elif ENABLED(LPC_SD_ONBOARD)
#ifdef LPC_SD_ONBOARD
// The external SD card is not used. Hardware SPI is used to access the card. // The external SD card is not used. Hardware SPI is used to access the card.
#ifdef USB_SD_ONBOARD #if ENABLED(USB_SD_ONBOARD)
// When sharing the SD card with a PC we want the menu options to // When sharing the SD card with a PC we want the menu options to
// mount/unmount the card and refresh it. So we disable card detect. // mount/unmount the card and refresh it. So we disable card detect.
#define SHARED_SD_CARD #define SHARED_SD_CARD
#undef SD_DETECT_PIN
#else #else
#define SD_DETECT_PIN P0_27 #define SD_DETECT_PIN P0_27
#endif #endif
#define SCK_PIN P0_07 #define SCK_PIN P0_07
#define MISO_PIN P0_08 #define MISO_PIN P0_08
#define MOSI_PIN P0_09 #define MOSI_PIN P0_09
#define SS_PIN P0_06 // Chip select for SD card used by Marlin #define SS_PIN P0_06 // Chip select for SD card used by Marlin
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#endif #endif
/** /**
@ -286,6 +285,7 @@
#endif #endif
#endif #endif
#endif #endif
#if HAS_DRIVER(TMC2208) #if HAS_DRIVER(TMC2208)
// The shortage of pins becomes apparent. // The shortage of pins becomes apparent.
// Worst case you may have to give up the LCD // Worst case you may have to give up the LCD

View File

@ -363,23 +363,23 @@
#define ENET_TXD0 P1_00 // (78) J12-11 #define ENET_TXD0 P1_00 // (78) J12-11
#define ENET_TXD1 P1_01 // (79) J12-12 #define ENET_TXD1 P1_01 // (79) J12-12
//#define USB_SD_DISABLED //#define USB_SD_DISABLED
#define USB_SD_ONBOARD // Provide the onboard SD card to the host as a USB mass storage device #define USB_SD_ONBOARD // Provide the onboard SD card to the host as a USB mass storage device
//#define LPC_SD_LCD // Marlin uses the SD drive attached to the LCD //#define LPC_SD_LCD // Marlin uses the SD drive attached to the LCD
#define LPC_SD_ONBOARD // Marlin uses the SD drive on the control board #define LPC_SD_ONBOARD // Marlin uses the SD drive on the control board
#ifdef LPC_SD_LCD #if ENABLED(LPC_SD_LCD)
#define SCK_PIN P0_15 #define SCK_PIN P0_15
#define MISO_PIN P0_17 #define MISO_PIN P0_17
#define MOSI_PIN P0_18 #define MOSI_PIN P0_18
#define SS_PIN P1_23 // Chip select for SD card used by Marlin #define SS_PIN P1_23 // Chip select for SD card used by Marlin
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#endif
#ifdef LPC_SD_ONBOARD #elif ENABLED(LPC_SD_ONBOARD)
#ifdef USB_SD_ONBOARD
#if ENABLED(USB_SD_ONBOARD)
// When sharing the SD card with a PC we want the menu options to // When sharing the SD card with a PC we want the menu options to
// mount/unmount the card and refresh it. So we disable card detect. // mount/unmount the card and refresh it. So we disable card detect.
#define SHARED_SD_CARD #define SHARED_SD_CARD
@ -390,10 +390,11 @@
#define MOSI_PIN P0_09 #define MOSI_PIN P0_09
#define SS_PIN P0_06 // Chip select for SD card used by Marlin #define SS_PIN P0_06 // Chip select for SD card used by Marlin
#define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card #define ONBOARD_SD_CS P0_06 // Chip select for "System" SD card
#endif #endif
/** /**
* Fast PWMS * Fast PWMs
* *
* The LPC1768's hardware PWM controller has 6 channels. Each channel * The LPC1768's hardware PWM controller has 6 channels. Each channel
* can be setup to either control a dedicated pin directly or to generate * can be setup to either control a dedicated pin directly or to generate
@ -418,7 +419,7 @@
*/ */
/** /**
* special pins * Special pins
* P1_30 (37) - not 5V tolerant * P1_30 (37) - not 5V tolerant
* P1_31 (49) - not 5V tolerant * P1_31 (49) - not 5V tolerant
* P0_27 (57) - open collector * P0_27 (57) - open collector