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:
@@ -47,7 +47,8 @@ int main(void)
|
||||
/* Blink the LED (PC12) on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO12); /* LED on/off */
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -24,7 +24,7 @@ void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOC clock. */
|
||||
/* Manually: */
|
||||
// RCC_APB2ENR |= IOPCEN;
|
||||
// RCC_APB2ENR |= RCC_APB2ENR_IOPCEN;
|
||||
/* Using API functions: */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
@@ -47,19 +47,24 @@ int main(void)
|
||||
while (1) {
|
||||
/* Manually: */
|
||||
// GPIOC_BSRR = GPIO12; /* LED off */
|
||||
// for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
// GPIOC_BRR = GPIO12; /* LED on */
|
||||
// for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
|
||||
/* Using API functions gpio_set()/gpio_clear(): */
|
||||
// gpio_set(GPIOC, GPIO12); /* LED off */
|
||||
// for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
// gpio_clear(GPIOC, GPIO12); /* LED on */
|
||||
// for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
|
||||
/* Using API function gpio_toggle(): */
|
||||
gpio_toggle(GPIOC, GPIO12); /* LED on/off */
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -69,13 +69,14 @@ int main(void)
|
||||
/* Blink the LED (PC12) on the board with every transmitted byte. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO12); /* LED on/off */
|
||||
usart_send_blocking(USART3, c + '0'); /* Send one byte on USART3. */
|
||||
usart_send_blocking(USART3, c + '0'); /* USART3: Send byte. */
|
||||
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
||||
if ((j++ % 80) == 0) { /* Newline after line full. */
|
||||
usart_send_blocking(USART3, '\r');
|
||||
usart_send_blocking(USART3, '\n');
|
||||
}
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("NOP");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -224,6 +224,8 @@ static void cdcacm_set_config(u16 wValue)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
|
||||
@@ -236,7 +238,8 @@ int main(void)
|
||||
usbd_init(&dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(cdcacm_set_config);
|
||||
|
||||
{int i; for (i=0;i<0x80000;i++);}
|
||||
for (i = 0; i < 0x800000; i++)
|
||||
__asm__("nop");
|
||||
gpio_clear(GPIOC, GPIO11);
|
||||
|
||||
while (1)
|
||||
|
||||
Reference in New Issue
Block a user