[2.0.x] LPC176x Serial cleanup (#11032)
This commit is contained in:
committed by
Scott Lahteine
parent
c1269c2ec1
commit
0312c42f9d
@@ -35,53 +35,52 @@ extern "C" {
|
||||
#include "LPC1768_PWM.h"
|
||||
|
||||
static __INLINE uint32_t SysTick_Config(uint32_t ticks) {
|
||||
if (ticks > SysTick_LOAD_RELOAD_Msk)
|
||||
return (1); /* Reload value impossible */
|
||||
if (ticks > SysTick_LOAD_RELOAD_Msk) return 1;
|
||||
|
||||
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
|
||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(0, 0, 0)); /* set Priority for Cortex-M3 System Interrupts */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; // Set reload register
|
||||
SysTick->VAL = 0; // Load the SysTick Counter Value
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_TICKINT_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
return (0); /* Function successful */
|
||||
SysTick_CTRL_TICKINT_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; // Enable SysTick IRQ and SysTick Timer
|
||||
|
||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(0, 0, 0)); // Set Priority for Cortex-M3 System Interrupts
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
extern void disk_timerproc(void);
|
||||
volatile uint32_t _millis;
|
||||
void SysTick_Handler(void) {
|
||||
++_millis;
|
||||
disk_timerproc(); /* Disk timer process */
|
||||
}
|
||||
}
|
||||
extern int isLPC1769();
|
||||
extern void disk_timerproc(void);
|
||||
volatile uint32_t _millis;
|
||||
|
||||
// runs after clock init and before global static constructors
|
||||
extern "C" void SystemPostInit() {
|
||||
_millis = 0; // initialise the millisecond counter value;
|
||||
SysTick_Config(SystemCoreClock / 1000); // start millisecond global counter
|
||||
GPIO_SetDir(4, 1UL << 28, 1);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
GPIO_SetValue(4, 1UL << 28);
|
||||
delay(100);
|
||||
GPIO_ClearValue(4, 1UL << 28);
|
||||
delay(100);
|
||||
void SysTick_Handler(void) {
|
||||
++_millis;
|
||||
disk_timerproc();
|
||||
}
|
||||
}
|
||||
|
||||
// detect 17x[4-8] (100MHz) or 17x9 (120MHz)
|
||||
static bool isLPC1769() {
|
||||
#define IAP_LOCATION 0x1FFF1FF1
|
||||
uint32_t command[1];
|
||||
uint32_t result[5];
|
||||
typedef void (*IAP)(uint32_t*, uint32_t*);
|
||||
IAP iap = (IAP) IAP_LOCATION;
|
||||
// Runs after clock init and before global static constructors
|
||||
void SystemPostInit() {
|
||||
_millis = 0; // Initialise the millisecond counter value;
|
||||
SysTick_Config(SystemCoreClock / 1000); // Start millisecond global counter
|
||||
|
||||
command[0] = 54;
|
||||
iap(command, result);
|
||||
// Runs before setup() need to configure LED_PIN and use to indicate succsessful bootloader execution
|
||||
#if PIN_EXISTS(LED)
|
||||
SET_DIR_OUTPUT(LED_PIN);
|
||||
WRITE_PIN_CLR(LED_PIN);
|
||||
|
||||
return ((result[1] & 0x00100000) != 0);
|
||||
//MKS-SBASE has 3 other LEDS the bootloader uses during flashing, clear them
|
||||
SET_DIR_OUTPUT(P1_19);
|
||||
WRITE_PIN_CLR(P1_19);
|
||||
SET_DIR_OUTPUT(P1_20);
|
||||
WRITE_PIN_CLR(P1_20);
|
||||
SET_DIR_OUTPUT(P1_21);
|
||||
WRITE_PIN_CLR(P1_21);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
TOGGLE(LED_PIN);
|
||||
delay(100);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extern uint32_t MSC_SD_Init(uint8_t pdrv);
|
||||
@@ -96,7 +95,6 @@ int main(void) {
|
||||
const uint32_t usb_timeout = millis() + 2000;
|
||||
while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
|
||||
delay(50);
|
||||
|
||||
#if PIN_EXISTS(LED)
|
||||
TOGGLE(LED_PIN); // Flash fast while USB initialisation completes
|
||||
#endif
|
||||
@@ -107,7 +105,7 @@ int main(void) {
|
||||
#if NUM_SERIAL > 1
|
||||
MYSERIAL1.begin(BAUDRATE);
|
||||
#endif
|
||||
SERIAL_PRINTF("\n\n%s (%dMhz) UART0 Initialised\n", isLPC1769() ? "LPC1769" : "LPC1768", SystemCoreClock / 1000000);
|
||||
SERIAL_PRINTF("\n\necho:%s (%dMhz) Initialised\n", isLPC1769() ? "LPC1769" : "LPC1768", SystemCoreClock / 1000000);
|
||||
SERIAL_FLUSHTX();
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user