Use __asm__("nop") in the loop-based delays.
Since we recently switched from -O0 to -Os, an increase in the loop count
as well as the addition of __asm__("nop") is required (so that the loop
doesn't get optimized/removed).
The real fix is to add a proper timer-based delay function, of course.
Also, fix a bunch of cosmetic issues and typos.
This commit is contained in:
@@ -54,13 +54,17 @@ int main(void)
|
||||
/* Blink the LEDs on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO6); /* LED on/off */
|
||||
for (i = 0; i < 800000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOA, GPIO7); /* LED on/off */
|
||||
for (i = 0; i < 800000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOB, GPIO0); /* LED on/off */
|
||||
for (i = 0; i < 800000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOB, GPIO1); /* LED on/off */
|
||||
for (i = 0; i < 800000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -454,7 +454,8 @@ int main(void)
|
||||
d3 =- 1;
|
||||
if (j3 == 19)
|
||||
j3 = 20;
|
||||
for (i = 0; i < 15000; i++) __asm("nop");
|
||||
for (i = 0; i < 15000; i++)
|
||||
__asm__("nop");
|
||||
j++;
|
||||
if (j == 100) {
|
||||
j = 0;
|
||||
|
||||
@@ -25,7 +25,7 @@ void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock. For LED gpio's */
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable clocks for GPIO port B (for GPIO_USART1_TX) and USART1. */
|
||||
@@ -36,11 +36,9 @@ void clock_setup(void)
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
|
||||
/* Setup GPIO6 (in GPIO port A) to 'output push-pull' for led use. */
|
||||
/* Setup GPIO6 (in GPIO port A) to 'output push-pull' for LED use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL,
|
||||
GPIO6);
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_USART1_REMAP;
|
||||
|
||||
@@ -78,13 +76,14 @@ int main(void)
|
||||
/* Blink the LED (PC12) on the board with every transmitted byte. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO6); /* LED on/off */
|
||||
usart_send_blocking(USART1, c + '0'); /* Send one byte on USART3. */
|
||||
usart_send_blocking(USART1, c + '0'); /* Send a byte. */
|
||||
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
||||
if ((j++ % 80) == 0) { /* Newline after line full. */
|
||||
usart_send_blocking(USART1, '\r');
|
||||
usart_send_blocking(USART1, '\n');
|
||||
}
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -26,7 +26,7 @@ void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock. For LED gpio's */
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable clocks for GPIO port B (for GPIO_USART1_TX) and USART1. */
|
||||
@@ -37,7 +37,6 @@ void clock_setup(void)
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
|
||||
/* Enable the USART1 interrupt. */
|
||||
nvic_enable_irq(NVIC_USART1_IRQ);
|
||||
|
||||
@@ -69,14 +68,11 @@ void usart_setup(void)
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
|
||||
gpio_set(GPIOA, GPIO6 | GPIO7);
|
||||
|
||||
/* Setup GPIO6 and 7 (in GPIO port A) for led use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL,
|
||||
GPIO6 | GPIO7);
|
||||
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6 | GPIO7);
|
||||
}
|
||||
|
||||
void usart1_isr(void)
|
||||
@@ -85,7 +81,6 @@ void usart1_isr(void)
|
||||
|
||||
/* Check if we were called because of RXNE. */
|
||||
if ((USART_SR(USART1) & USART_SR_RXNE) != 0) {
|
||||
|
||||
/* Indicate that we got data. */
|
||||
gpio_toggle(GPIOA, GPIO6);
|
||||
|
||||
@@ -98,29 +93,26 @@ void usart1_isr(void)
|
||||
|
||||
/* Check if we were called because of TXE. */
|
||||
if ((USART_SR(USART1) & USART_SR_TXE) != 0) {
|
||||
|
||||
/* Indicate that we are sending out data. */
|
||||
gpio_toggle(GPIOA, GPIO7);
|
||||
|
||||
/* Put data into the transmit register */
|
||||
/* Put data into the transmit register. */
|
||||
usart_send(USART1, data);
|
||||
|
||||
/* Disable the TXE interrupt as we don't need it anymore */
|
||||
/* Disable the TXE interrupt as we don't need it anymore. */
|
||||
USART_CR1(USART1) &= ~USART_CR1_TXEIE;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/* Wait forever and do nothing. */
|
||||
while (1) {
|
||||
__asm("nop");
|
||||
}
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user