|
|
|
@ -61,24 +61,22 @@ static void gpio_setup(void) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(void) |
|
|
|
|
{ |
|
|
|
|
int i, c = 0; |
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader
|
|
|
|
|
|
|
|
|
|
clock_setup(); |
|
|
|
|
gpio_setup(); |
|
|
|
|
usart_setup(); |
|
|
|
|
clock_setup(); // setup main clock
|
|
|
|
|
gpio_setup(); // setup main inputs/ouputs
|
|
|
|
|
usart_setup(); // setup USART (for printing)
|
|
|
|
|
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
|
|
|
|
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
|
|
|
|
|
|
|
|
|
/* blink the LED with every transmitted character */ |
|
|
|
|
while (1) { |
|
|
|
|
gpio_toggle(LED_PORT, LED_PIN); /* LED on/off */ |
|
|
|
|
printf("%c",c+'0'); |
|
|
|
|
c = (c == 9) ? 0 : c + 1; /* increment c */ |
|
|
|
|
for (i = 0; i < 8000000; i++) /* wait a bit */ |
|
|
|
|
__asm__("nop"); |
|
|
|
|
while (usart_received) { // echo every received character
|
|
|
|
|
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
|
|
|
|
printf("%c",usart_getchar()); // transmit receive character
|
|
|
|
|
} |
|
|
|
|
__asm__("wfi"); // go to sleep
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|