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:
parent
05f66cde4c
commit
ca53311bfc
|
@ -35,9 +35,11 @@ int main(void)
|
|||
while (1) {
|
||||
/* Manually: */
|
||||
GPIO3_DATA |= (1 << 0); /* LED off */
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
GPIO3_DATA &= ~(1 << 0); /* LED on */
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -27,7 +27,6 @@ void clock_setup(void)
|
|||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
|
@ -49,22 +48,28 @@ int main(void)
|
|||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO6); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
for (i = 0; i < 400000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
for (i = 0; i < 400000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO9); /* LED on/off */
|
||||
for (i = 0; i < 400000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO9); /* LED on/off */
|
||||
for (i = 0; i < 400000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
for (i = 0; i < 400000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO6); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
for (i = 0; i < 400000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -60,27 +60,30 @@ void gpio_setup(void)
|
|||
void adc_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
|
||||
|
||||
/* make shure it didnt run during config */
|
||||
/* Make shure it doesn't run during config. */
|
||||
adc_off(ADC1);
|
||||
|
||||
/* we configure everything for one single conversion */
|
||||
/* We configure everything for one single conversion. */
|
||||
adc_disable_scan_mode(ADC1);
|
||||
adc_set_single_conversion_mode(ADC1);
|
||||
adc_enable_discontinous_mode_regular(ADC1);
|
||||
adc_disable_external_trigger_regular(ADC1);
|
||||
adc_set_right_aligned(ADC1);
|
||||
/* we want read out the temperature sensor so we have to enable it */
|
||||
/* We want to read the temperature sensor, so we have to enable it. */
|
||||
adc_enable_temperature_sensor(ADC1);
|
||||
adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
|
||||
|
||||
adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
|
||||
|
||||
adc_on(ADC1);
|
||||
/* wait for adc starting up*/
|
||||
for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */
|
||||
|
||||
/* Wait for ADC starting up. */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
|
||||
adc_reset_calibration(ADC1);
|
||||
adc_calibration(ADC1);
|
||||
adc_calibration(ADC1);
|
||||
}
|
||||
|
||||
void my_usart_print_int(u32 usart, int value)
|
||||
|
@ -95,13 +98,12 @@ void my_usart_print_int(u32 usart, int value)
|
|||
}
|
||||
|
||||
while (value > 0) {
|
||||
buffer[nr_digits++] = "0123456789"[value%10];
|
||||
value = value/10;
|
||||
buffer[nr_digits++] = "0123456789"[value % 10];
|
||||
value /= 10;
|
||||
}
|
||||
|
||||
for (i=nr_digits; i>=0; i--) {
|
||||
for (i = nr_digits; i >= 0; i--)
|
||||
usart_send(usart, buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -124,19 +126,25 @@ int main(void)
|
|||
usart_send(USART1, '\r');
|
||||
usart_send(USART1, '\n');
|
||||
|
||||
/* Select the channel we want to convert. 16=temperature_sensor */
|
||||
/* Select the channel we want to convert. 16=temperature_sensor. */
|
||||
channel_array[0] = 16;
|
||||
adc_set_regular_sequence(ADC1, 1, channel_array);
|
||||
|
||||
/* If the ADC_CR2_ON bit is already set -> setting it another time starts the conversion */
|
||||
/*
|
||||
* If the ADC_CR2_ON bit is already set -> setting it another time
|
||||
* starts the conversion.
|
||||
*/
|
||||
adc_on(ADC1);
|
||||
|
||||
/* Waiting for end of conversion */
|
||||
/* Wait for end of conversion. */
|
||||
while (!(ADC_SR(ADC1) & ADC_SR_EOC));
|
||||
|
||||
temperature = ADC_DR(ADC1);
|
||||
|
||||
/* thats actually not the real temparature - you have to compute it like described in the datasheet */
|
||||
/*
|
||||
* That's actually not the real temperature - you have to compute it
|
||||
* as described in the datasheet.
|
||||
*/
|
||||
my_usart_print_int(USART1, temperature);
|
||||
|
||||
gpio_clear(GPIOB, GPIO6); /* LED2 on */
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue