void usart1_isr(void) { static uint8_t data = 'A'; /* Check if we were called because of RXNE. */ if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) && ((USART_SR(USART1) & USART_SR_RXNE) != 0)) { /* Indicate that we got data. */ gpio_toggle(GPIOA, GPIO6); /* Retrieve the data from the peripheral. */ data = usart_recv(USART1); /* Enable transmit interrupt so it sends back the data. */ USART_CR1(USART1) |= USART_CR1_TXEIE; } /* Check if we were called because of TXE. */ if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) && ((USART_SR(USART1) & USART_SR_TXE) != 0)) { /* Indicate that we are sending out data. */ gpio_toggle(GPIOA, GPIO7); /* Put data into the transmit register. */ usart_send(USART1, data); /* Disable the TXE interrupt as we don't need it anymore. */ USART_CR1(USART1) &= ~USART_CR1_TXEIE; } }
void app_demo_timer_cb(void *ctx) { uint16_t *timer = (uint16_t *)ctx; if (timer != NULL) { if (++(*timer) == 100) { *timer = 0; } if (timer == &(app.timer_b)) { if (*timer == 0) { gpio_toggle(GPIO_LED_B); } sched_set(&(app.sched), TASK_ID_LED_B, 50000, app_demo_timer_cb, (void *)&(app.timer_b)); } else if (timer == &(app.timer_g)) { if (*timer == 0) { gpio_toggle(GPIO_LED_G); } sched_set(&(app.sched), TASK_ID_LED_G, 25000, app_demo_timer_cb, (void *)&(app.timer_g)); } } }
void tim2_isr(void) { if (timer_get_flag(TIM2, TIM_SR_CC1IF)) { /* Clear compare interrupt flag. */ timer_clear_flag(TIM2, TIM_SR_CC1IF); /* * Get current timer value to calculate next * compare register value. */ compare_time = timer_get_counter(TIM2); /* Calculate and set the next compare value. */ frequency = frequency_sequence[frequency_sel++]; new_time = compare_time + frequency; timer_set_oc_value(TIM2, TIM_OC1, new_time); if (frequency_sel == 18) frequency_sel = 0; /* Toggle LED to indicate compare event. */ gpio_toggle(GPIOD, GPIO12); gpio_toggle(GPIOD, GPIO13); } }
int main(void) { int i; int j = 0; rcc_clock_setup_pll(&rcc_clock_config[RCC_CLOCK_VRANGE1_HSI_PLL_32MHZ]); rcc_periph_clock_enable(RCC_GPIOB); printf("hi guys!\n"); /* green led for ticking */ gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN); rcc_periph_clock_enable(RCC_GPIOA); gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1); gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5); adc_power_init(); while (1) { adc_power_task_up(); gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ __asm__("NOP"); } adc_power_task_down(); gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ __asm__("NOP"); } } return 0; }
int main(void){ volatile int i; gpio_setup(); /* Blink the LED (PC12) on the board. */ while (1) { /* Manually: */ // GPIOC_BSRR = GPIO12; /* LED off */ // for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */ // GPIOC_BRR = GPIO12; /* LED on */ // for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */ /* Using API functions gpio_set()/gpio_clear(): */ // gpio_set(GPIOC, GPIO12); /* LED off */ // for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */ // gpio_clear(GPIOC, GPIO12); /* LED on */ // for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */ /* Using API function gpio_toggle(): */ gpio_toggle(GPIOB, GPIO2); /* LED on/off */ gpio_toggle(GPIOB, GPIO5); /* LED on/off */ for (i = 0; i < 80000; i++); /* Wait (needs -O0 CFLAGS). */ } return 0; }
int main( void ) { #ifdef DEBUG debug(); #endif prvSetupHardware(); gpio_toggle(GPIOB, GPIO9); /* LED on/off */ /* Start the blink task. */ xTaskCreate( prvBlinkTask, ( signed portCHAR * ) "Flash", \ configMINIMAL_STACK_SIZE, NULL, mainBLINK_TASK_PRIORITY, NULL ); gpio_toggle(GPIOB, GPIO10); /* LED on/off */ /* Start the usart task. */ xTaskCreate( prvUsartTask, ( signed portCHAR * ) "USART", \ configMINIMAL_STACK_SIZE, NULL, mainBLINK_TASK_PRIORITY, NULL ); /* Start the scheduler. */ vTaskStartScheduler(); /* Will only get here if there was not enough heap space to create the idle task. */ return -1; }
int main(void) { int i, j; clock_setup(); gpio_setup(); usart_setup(); printf("\nStandard I/O Example.\n"); /* Blink the LED (PD12) on the board with every transmitted byte. */ while (1) { int delay = 0; char local_buf[32]; gpio_toggle(GPIOA, GPIO5); /* LED on/off */ do { printf("Enter the delay constant for blink : "); fflush(stdout); fgets(local_buf, 32, stdin); delay = atoi(local_buf); if (delay <= 0) { printf("Error: expected a delay > 0\n"); } } while (delay <= 0); printf("Blinking with a delay of %d\n", delay); for (j = 0; j < 1000; j++) { gpio_toggle(GPIOA, GPIO5); for (i = 0; i < delay; i++) { /* Wait a bit. */ __asm__("NOP"); } } } return 0; }
/* Private functions ---------------------------------------------------------*/ void TIM2_IRQHandler() { if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET){ gpio_toggle(GPIOA, GPIO_Pin_0); gpio_toggle(GPIOA, GPIO_Pin_1); TIM_ClearITPendingBit(TIM2, TIM_IT_Update); } }
/*----------------------------------------------------------------------------*/ void blink_error(int count) { while(count>0) { gpio_toggle(ERROR_LED); timer_wait(TIMER_S/2); gpio_toggle(ERROR_LED); timer_wait(TIMER_S/2); count--; } }
int main(void) { int i; int iserr = 1; clock_setup(); gpio_setup(); usart_setup(); /* Blink the LED (PD12) on the board with every transmitted byte. */ while (1) { gpio_toggle(GPIOD, GPIO12); /* LED on/off */ /* encode the plaintext message into ciphertext */ crypto_set_key(CRYPTO_KEY_128BIT, key); crypto_set_iv(iv); /* only in CBC or CTR mode */ crypto_set_datatype(CRYPTO_DATA_32BIT); crypto_set_algorithm(ENCRYPT_DES_ECB); crypto_start(); crypto_process_block((uint32_t *)plaintext, (uint32_t *)ciphertext, 8 / sizeof(uint32_t)); crypto_stop(); /* decode the previously encoded message from ciphertext to plaintext2 */ crypto_set_key(CRYPTO_KEY_128BIT, key); crypto_set_iv(iv); /* only in CBC or CTR mode */ crypto_set_datatype(CRYPTO_DATA_32BIT); crypto_set_algorithm(DECRYPT_DES_ECB); crypto_start(); crypto_process_block((uint32_t *)ciphertext, (uint32_t *)plaintext2, 8 / sizeof(uint32_t)); crypto_stop(); /* compare the two plaintexts if they are same */ iserr = 0; for (i = 0; i < 8; i++) { if (plaintext[i] != plaintext2[i]) { iserr = true; } } if (iserr) { gpio_toggle(GPIOD, GPIO12); /* something went wrong. */ } } return 0; }
void sys_tick_handler(void) { temp32++; /* We call this handler every 1ms so 1000ms = 1s on/off. */ if (temp32 == 1000) { gpio_toggle(GPIOB, GPIO4); /* LED green on/off */ gpio_toggle(GPIOB, GPIO5); /* LED red on/off */ temp32 = 0; } }
void led_toggle(unsigned led) { switch (led) { case LED_ACTIVITY: gpio_toggle(BOARD_PORT_LEDS, BOARD_PIN_LED_ACTIVITY); break; case LED_BOOTLOADER: gpio_toggle(BOARD_PORT_LEDS, BOARD_PIN_LED_BOOTLOADER); break; } }
int main(void) { int i; gpio_setup(); /* Blink the LED (PC8) on the board. */ while (1) { /* Manually: */ // GPIOC_BSRR = GPIO8; /* LED off */ // for (i = 0; i < 800000; i++) /* Wait a bit. */ // __asm__("nop"); // GPIOC_BRR = GPIO8; /* LED on */ // for (i = 0; i < 800000; i++) /* Wait a bit. */ // __asm__("nop"); /* Using API functions gpio_set()/gpio_clear(): */ // gpio_set(GPIOC, GPIO8); /* LED off */ // for (i = 0; i < 800000; i++) /* Wait a bit. */ // __asm__("nop"); // gpio_clear(GPIOC, GPIO8); /* LED on */ // for (i = 0; i < 800000; i++) /* Wait a bit. */ // __asm__("nop"); /* Using API function gpio_toggle(): */ gpio_toggle(GPIOC, GPIO8); /* LED on/off */ for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); } return 0; }
int main(void) { int counter = 0; uint16_t rx_value = 0x42; clock_setup(); gpio_setup(); usart_setup(); spi_setup(); /* Blink the LED (PA8) on the board with every transmitted byte. */ while (1) { /* LED on/off */ gpio_toggle(GPIOA, GPIO8); /* printf the value that SPI should send */ printf("Counter: %i SPI Sent Byte: %i", counter, (uint8_t) counter); /* blocking send of the byte out SPI1 */ spi_send(SPI1, (uint8_t) counter); /* Read the byte that just came in (use a loopback between MISO and MOSI * to get the same byte back) */ rx_value = spi_read(SPI1); /* printf the byte just received */ printf(" SPI Received Byte: %i\r\n", rx_value); counter++; } return 0; }
int main(void) { int counter = 0; float fcounter = 0.0; double dcounter = 0.0; clock_setup(); gpio_setup(); usart_setup(); /* * Write Hello World, an integer, float and double all over * again while incrementing the numbers. */ while (1) { gpio_toggle(GPIOC, GPIO12); printf("Hello World! %i %f %f\r\n", counter, fcounter, dcounter); counter++; fcounter += 0.01; dcounter += 0.01; } return 0; }
int main(void) { int i; int j = 0; clock_setup(); usart_setup(); printf("hi guys!\n"); adc_setup(); dac_setup(); gpio_set_mode(LED_DISCOVERY_USER_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_DISCOVERY_USER_PIN); while (1) { uint16_t input_adc0 = read_adc_naiive(0); uint16_t target = input_adc0 / 2; dac_load_data_buffer_single(target, RIGHT12, CHANNEL_2); dac_software_trigger(CHANNEL_2); uint16_t input_adc1 = read_adc_naiive(1); printf("tick: %d: adc0= %u, target adc1=%d, adc1=%d\n", j++, input_adc0, target, input_adc1); gpio_toggle(LED_DISCOVERY_USER_PORT, LED_DISCOVERY_USER_PIN); /* LED on/off */ for (i = 0; i < 1000000; i++) /* Wait a bit. */ __asm__("NOP"); } return 0; }
int main(void) { int i, j = 0, c = 0; clock_setup(); gpio_setup(); usart_setup(); /* Blink the LED (PE10) on the board with every transmitted byte. */ while (1) { gpio_toggle(GPIO_PE10); /* LED on/off */ usart_send_blocking(USART1, c + '0'); /* USART1: Send byte. */ usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */ 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(USART1, '\r'); usart_send_blocking(USART1, '\n'); usart_send_blocking(USART2, '\r'); usart_send_blocking(USART2, '\n'); usart_send_blocking(USART3, '\r'); usart_send_blocking(USART3, '\n'); } for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__ ("nop"); } return 0; }
void tim2_isr(void) { gpio_toggle(GPIOB, GPIO8); /* LED1 on/off. */ if (timer_get_flag(TIM2, TIM_SR_UIF)) timer_clear_flag(TIM2, TIM_SR_UIF); /* Clear interrrupt flag. */ timer_get_flag(TIM2, TIM_SR_UIF); /* Reread to force the previous write */ }
int main(void) { int i; int j = 0; clock_setup(); usart_setup(); printf("hi guys!\n"); adc_setup(); dac_setup(); /* green led for ticking */ gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN); while (1) { uint16_t input_adc0 = read_adc_naiive(0); uint16_t target = input_adc0 / 2; dac_load_data_buffer_single(target, RIGHT12, CHANNEL_2); dac_software_trigger(CHANNEL_2); uint16_t input_adc1 = read_adc_naiive(1); printf("tick: %d: adc0= %u, target adc1=%d, adc1=%d\n", j++, input_adc0, target, input_adc1); /* LED on/off */ gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); for (i = 0; i < 1000000; i++) { /* Wait a bit. */ __asm__("NOP"); } } return 0; }
static void set_servos(uint32_t pos1_us, uint32_t pos2_us) { gpio_toggle(GPIOC, GPIO13); /* LED on/off */ servo_set_position(SERVO_CH1, pos1_us); servo_set_position(SERVO_CH2, pos2_us); delay(45000000); }
int main(void) { int i; int j = 0; clock_setup(); usart_setup(); printf("hi guys!\n"); adc_setup(); /* green led for ticking */ gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN); while (1) { //uint16_t input_adc0 = read_adc_naiive(0); //uint16_t target = input_adc0 / 2; //uint16_t input_adc1 = ((uint16_t)((read_adc_naiive(18) - 760) / 25) + 25); int i; for (i = 0; i < 0x13; i++) { uint16_t input_adc1 = read_adc_naiive(i); printf("tick: %d: adc1_%02X=%d\n", j++, i, input_adc1); } uint32_t reg = ADC_CCR; printf("reg = 0x%08X\r\n", reg); /* LED on/off */ gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); for (i = 0; i < 1000000; i++) { /* Wait a bit. */ __asm__("NOP"); } } return 0; }
int main(void) { clock_init(); gpio_init(); led_dim_init(); //again GPIO9 is the pin where the LED is connected // gpio_set(GPIOC, GPIO12); gpio_set(GPIOC, GPIO8); delay(800000); // let pan-til "look around a little" while (1) { led_set_dim_value(LED_CH1, LED_ON); delay(800000); led_set_dim_value(LED_CH1, LED_DIM); delay(800000); led_set_dim_value(LED_CH1, LED_OFF); delay(800000); delay(800000); delay(800000); led_set_dim_value(LED_CH1, LED_DIM); delay(800000); gpio_toggle(GPIOC, GPIO8); } return 0; }
int main(void) { int i; struct color colors[COLOR_COUNT]; clock_setup(); gpio_setup(); reset_colors(colors, COLOR_COUNT); init_colors(colors, COLOR_COUNT); while (1) { gpio_toggle(GPIOC, GPIO12); /* LED on/off */ send_colors(colors, COLOR_COUNT); step_colors(colors, COLOR_COUNT); for (i = 0; i < 1000000; i++) /* Wait a bit. */ __asm__("nop"); } return 0; }
void frc2_interrupt_handler(void) { /* FRC2 needs the match register updated on each timer interrupt */ timer_set_frequency(FRC2, freq_frc2); frc2_count++; gpio_toggle(gpio_frc2); }
void usart2_isr(void) { static u8 data = 'A'; /* Check if we were called because of RXNE. */ if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) && ((USART_SR(USART2) & USART_SR_RXNE) != 0)) { /* Indicate that we got data. */ gpio_toggle(GPIOD, GPIO12); /* Retrieve the data from the peripheral. */ data = usart_recv(USART2); /* Enable transmit interrupt so it sends back the data. */ usart_enable_tx_interrupt(USART2); } /* Check if we were called because of TXE. */ if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) && ((USART_SR(USART2) & USART_SR_TXE) != 0)) { /* Put data into the transmit register. */ usart_send(USART2, data); /* Disable the TXE interrupt as we don't need it anymore. */ usart_disable_tx_interrupt(USART2); } }
void usart2_isr(void) { /* Check if we were called because of RXNE. */ if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) && ((USART_SR(USART2) & USART_SR_RXNE) != 0)) { /* Indicate that we got data. */ gpio_toggle(GPIOA, GPIO8); /* Retrieve the data from the peripheral. */ ring_write_ch(&output_ring, usart_recv(USART2)); /* Enable transmit interrupt so it sends back the data. */ USART_CR1(USART2) |= USART_CR1_TXEIE; } /* Check if we were called because of TXE. */ if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) && ((USART_SR(USART2) & USART_SR_TXE) != 0)) { int32_t data; data = ring_read_ch(&output_ring, NULL); if (data == -1) { /* Disable the TXE interrupt, it's no longer needed. */ USART_CR1(USART2) &= ~USART_CR1_TXEIE; } else { /* Put data into the transmit register. */ usart_send(USART2, data); } } }
int main(void) { int i; clock_setup(); button_setup(); gpio_setup(); /* Blink the LED (PD12) on the board. */ while (1) { gpio_toggle(GPIOD, GPIO12); /* Upon button press, blink more slowly. */ if (gpio_get(GPIOA, GPIO0)) { for (i = 0; i < 3000000; i++) { /* Wait a bit. */ __asm__("nop"); } } for (i = 0; i < 3000000; i++) { /* Wait a bit. */ __asm__("nop"); } } return 0; }
int main(void) { #if defined(BOOTLOADER8K) SCB_VTOR = (uint32_t) 0x08002000; #endif int i; clock_setup(); gpio_setup(); /* Blink the LED on the board. */ while (1) { gpio_toggle(LED_GPIO, LED_PIN); /* Upon button press, blink more slowly. */ if (gpio_get(BUTTON_GPIO, BUTTON_PIN)) { for (i = 0; i < 2000000; i++) { /* Wait a bit. */ __asm__("nop"); } } for (i = 0; i < 2000000; i++) { /* Wait a bit. */ __asm__("nop"); } } return 0; }
int main(void) { int i; clock_setup(); gpio_setup(); button_setup(); /* Blink the LED (PC9) on the board. */ while (1) { gpio_toggle(GPIOC, GPIO9); /* Upon button press, blink more slowly. */ exti_line_state = GPIOA_IDR; if ((exti_line_state & (1 << 0)) != 0) { for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); } for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); } return 0; }
int main(void) { int i; gpio_setup(); /* Blink the LED (PC8) on the board. */ while (1) { /* Manually: */ /* GPIOA_BSRR = GPIO5; */ /* LED off */ /* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */ /* __asm__("nop"); */ /* GPIOA_BRR = GPIO5; */ /* LED on */ /* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */ /* __asm__("nop"); */ /* Using API functions gpio_set()/gpio_clear(): */ /* gpio_set(GPIOA, GPIO5); */ /* LED off */ /* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */ /* __asm__("nop"); */ /* gpio_clear(GPIOA, GPIO5); */ /* LED on */ /* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */ /* __asm__("nop"); */ /* Using API function gpio_toggle(): */ gpio_toggle(GPIOA, GPIO5); /* LED on/off */ for (i = 0; i < 1000000; i++) { /* Wait a bit. */ __asm__("nop"); } } return 0; }