int main() { uint8_t output_state = 0; nrf_gpio_pin_dir_set(LED_PIN, NRF_GPIO_PIN_DIR_OUTPUT); int n = 0; initialise_monitor_handles(); printf("hello world!\n"); while(++n) { printf("round %d\n", n); nrf_delay_ms(1000); if (output_state == 1) nrf_gpio_pin_set(LED_PIN); else nrf_gpio_pin_clear(LED_PIN); output_state = (output_state + 1) & 1; nrf_delay_ms(100); } return 0; }
int main(void) { // initialize SystemInit(); initialise_monitor_handles(); init_systick(); /* Initialize the accelerometers */ init_accelerometers(); /* Initialize the LCD and Touch modules */ Delay(0x3FFFFF); LCD_Init(); Delay(0x3FFFFF); touch_init(); /* Clear the LCD, set text color to green and backlight to 100 */ LCD_Clear(BLACK); LCD_SetTextColor(GREEN); LCD_SetBackColor(LCD_COLOR_BLACK); LCD_BackLight(100); /* Add update_game to the timed_task array */ add_timed_task(update_game, 0.05); while(1) { /* Check if the timed task function has to be called */ update(); } }
void platform_init(void) { uint32_t data; SCS_DEMCR |= SCS_DEMCR_VC_MON_EN; #ifdef ENABLE_DEBUG void initialise_monitor_handles(void); initialise_monitor_handles(); #endif rcc_clock_setup_in_hse_8mhz_out_72mhz(); /* Enable peripherals */ rcc_periph_clock_enable(RCC_USB); rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOB); rcc_periph_clock_enable(RCC_AFIO); rcc_periph_clock_enable(RCC_CRC); /* Unmap JTAG Pins so we can reuse as GPIO */ data = AFIO_MAPR; data &= ~AFIO_MAPR_SWJ_MASK; data |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF; AFIO_MAPR = data; /* Setup JTAG GPIO ports */ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TDI_PIN); gpio_set_mode(TDO_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, TDO_PIN); gpio_set(NRST_PORT,NRST_PIN); gpio_set_mode(NRST_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, NRST_PIN); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_IDLE_RUN); /* Remap TIM2 TIM2_REMAP[1] * TIM2_CH1_ETR -> PA15 (TDI, set as output above) * TIM2_CH2 -> PB3 (TDO) */ data = AFIO_MAPR; data &= ~AFIO_MAPR_TIM2_REMAP_FULL_REMAP; data |= AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1; AFIO_MAPR = data; /* Relocate interrupt vector table here */ extern int vector_table; SCB_VTOR = (uint32_t)&vector_table; platform_timing_init(); cdcacm_init(); /* Don't enable UART if we're being debugged. */ if (!(SCS_DEMCR & SCS_DEMCR_TRCENA)) usbuart_init(); usbuart_init(); }
int main() { systickInit(); memoryInit(); #ifdef BLE ble_init(); #else NRF_CLOCK->TASKS_HFCLKSTART = 1UL; while(!NRF_CLOCK->EVENTS_HFCLKSTARTED); #endif #ifdef SEMIHOSTING initialise_monitor_handles(); #endif NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSTAT_SRC_Synth; NRF_CLOCK->TASKS_LFCLKSTART = 1UL; while(!NRF_CLOCK->EVENTS_LFCLKSTARTED); LED_INIT(); if ((NRF_POWER->GPREGRET & 0x80) && ((NRF_POWER->GPREGRET&(0x3<<1))==0)) { buttonInit(buttonShortPress); } else { buttonInit(buttonIdle); } if (NRF_POWER->GPREGRET & 0x20) { boottedFromBootloader = true; NRF_POWER->GPREGRET &= ~0x20; } pmInit(); if ((NRF_POWER->GPREGRET&0x01) == 0) { pmSetState(pmSysRunning); } LED_ON(); NRF_GPIO->PIN_CNF[RADIO_PAEN_PIN] |= GPIO_PIN_CNF_DIR_Output | (GPIO_PIN_CNF_DRIVE_S0H1<<GPIO_PIN_CNF_DRIVE_Pos); #ifndef BLE esbInit(); esbSetDatarate(DEFAULT_RADIO_RATE); esbSetChannel(DEFAULT_RADIO_CHANNEL); #endif mainloop(); // The main loop should never end // TODO see if we should shut-off the system there? while(1); return 0; }
int main(void) { int i; rcc_clock_setup_in_hse_8mhz_out_72mhz(); rcc_periph_clock_enable(RCC_GPIOC); rcc_periph_clock_enable(RCC_TIM3); rcc_periph_clock_enable(RCC_AFIO); gpio_primary_remap(0,AFIO_MAPR_TIM3_REMAP_FULL_REMAP ); gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL , GPIO9); timer_set_mode(TIM3, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); timer_set_prescaler(TIM3,36); timer_set_period(TIM3, 1000); timer_set_oc_mode(TIM3, TIM_OC4, TIM_OCM_PWM1); timer_enable_oc_output(TIM3, TIM_OC4); // timer_enable_preload(TIM3); //timer_continuous_mode(TIM3); timer_enable_counter(TIM3); #if defined(ENABLE_SEMIHOSTING) && (ENABLE_SEMIHOSTING) initialise_monitor_handles(); #endif uint16_t a = 0; while (1) { for(i=0; i< 1000; i++){ timer_set_oc_value(TIM3, TIM_OC4, i); delay(); } for(i=999; i >=0 ; i--){ timer_set_oc_value(TIM3, TIM_OC4, i); delay(); } //gpio_toggle(GPIOC, GPIO9); /* LED on/off */ //printf("hello world\n"); } }
void main() { setupLEDs(); setOutputPin(GPIOD, orangeLedPin, Bit_SET); initialise_monitor_handles(); setOutputPin(GPIOD, orangeLedPin, Bit_RESET); setOutputPin(GPIOD, blueLedPin, Bit_SET); bool testsPassed = runTests(); setOutputPin(GPIOD, blueLedPin, Bit_RESET); if (testsPassed) { setOutputPin(GPIOD, greenLedPin, Bit_SET); } else { setOutputPin(GPIOD, redLedPin, Bit_SET); } }
/* main C entry point */ int main(void) { //GPIO_InitTypeDef GPIO_InitStructure; char test[100]; int i=0; //RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; //TODO test /*-------------------------- GPIO Configuration ----------------------------*/ /* GPIOD Configuration: Pins 12, 13, 14 and 15 in output push-pull */ //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //GPIO_Init(GPIOD, &GPIO_InitStructure); //GPIO_ToggleBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_15); //INTTIM_Config(); // PC 8 en 9 zijn de leds initialise_monitor_handles(); sprintf(test, "Hello World\n"); printf("%s",test); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitTypeDef GPIO_INIT_C; GPIO_INIT_C.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; GPIO_INIT_C.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_INIT_C.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC,&GPIO_INIT_C); GPIO_SetBits(LEDPORT,LEDG | LEDB); for EVER { i++; } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM2_Init(); MX_USART2_UART_Init(); MX_USART6_UART_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT(&htim2); #ifdef DEBUG_TO_CONSOLE initialise_monitor_handles(); printf("start\n"); #endif UARTInit(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ UARTLoopDemo(); } /* USER CODE END 3 */ }
int main(void) { int counter = 0; //u16 rx_value = 0x42; u8 cyrfmfg_id[7]; clock_setup(); gpio_setup(); spi_setup(); CYRF_Reset(); #if SEMIHOSTING initialise_monitor_handles(); #endif cyrfmfg_id[0] = 0; cyrfmfg_id[1] = 0; cyrfmfg_id[2] = 0; cyrfmfg_id[3] = 0; cyrfmfg_id[4] = 0; cyrfmfg_id[5] = 0; /* Blink the LED (PA8) on the board with every transmitted byte. */ while (1) { /* LED on/off */ gpio_toggle(GPIOB, GPIO10); /* printf the value that SPI should send */ printf("Counter: %i SPI receiving mfgid: ... ", counter); /* blocking send of the byte out SPI1 */ CYRF_GetMfgData(cyrfmfg_id); cyrfmfg_id[6]=0; /* printf the byte just received */ printf(" SPI Received Byte: '0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X'\r\n", cyrfmfg_id[0], cyrfmfg_id[1], cyrfmfg_id[2], cyrfmfg_id[3], cyrfmfg_id[4], cyrfmfg_id[5]); counter++; } return 0; }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* GPIOC Periph clock enable */ RCC->AHBENR |= RCC_AHBENR_GPIOCEN; GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0) ; /* Configure PC8 and PC9 in output mode */ GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | ~GPIO_OTYPER_OT_9) ; // Ensure push pull mode selected--default GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8|GPIO_OSPEEDER_OSPEEDR9); //Ensure maximum speed setting (even though it is unnecessary) GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8|GPIO_PUPDR_PUPDR9); //Ensure all pull up pull down resistors are disabled initialise_monitor_handles(); uint32_t i = 0; while (1) { /* Set PC8 and PC9 */ GPIOC->BSRR = BSRR_VAL; delay(250000); /* Reset PC8 and PC9 */ GPIOC->BRR = BSRR_VAL; delay(250000); printf("Flash: %i\n", i++); } return 0; }
/** * @brief Board-specific initialization code. * @todo Add your board-specific code, if any. */ void boardInit(void) { DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_TIM2_STOP; DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_TIM3_STOP; DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_CAN_STOP; DBGMCU->APB2FZ |= DBGMCU_APB2_FZ_DBG_TIM1_STOP; DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_IWDG_STOP; DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_WWDG_STOP; DBGMCU->CR |= DBGMCU_CR_DBG_SLEEP; DBGMCU->CR |= DBGMCU_CR_DBG_STOP; /* Generate IRQ (PVD_IRQn) if VDD goes below 2.9v */ PWR->CR |= PWR_CR_PLS_LEV7; PWR->CR |= PWR_CR_PVDE; DEBUGEN( initialise_monitor_handles(); setbuf(stdout, NULL); )
int main(void) { if (DFU_AVAILABLE) { DFU_maybe_jump_to_bootloader(); } clock_setup(); tick_setup(1000); gpio_setup(); led_num(0); if (CDC_AVAILABLE) { console_setup(DEFAULT_BAUDRATE); } if (SEMIHOSTING) { initialise_monitor_handles(); } else if (VCDC_AVAILABLE) { retarget(STDOUT_FILENO, VIRTUAL_USART); retarget(STDERR_FILENO, VIRTUAL_USART); } else if (CDC_AVAILABLE) { retarget(STDOUT_FILENO, CONSOLE_USART); retarget(STDERR_FILENO, CONSOLE_USART); } led_num(1); { char serial[USB_SERIAL_NUM_LENGTH+1]; desig_get_unique_id_as_string(serial, USB_SERIAL_NUM_LENGTH+1); cmp_set_usb_serial_number(serial); } usbd_device* usbd_dev = cmp_usb_setup(); DAP_app_setup(usbd_dev, &on_dfu_request); if (CDC_AVAILABLE) { cdc_uart_app_setup(usbd_dev, &on_usb_activity, &on_usb_activity); } if (VCDC_AVAILABLE) { vcdc_app_setup(usbd_dev, &on_usb_activity, &on_usb_activity); } if (DFU_AVAILABLE) { dfu_setup(usbd_dev, &on_dfu_request); } tick_start(); /* Enable the watchdog to enable DFU recovery from bad firmware images */ iwdg_set_period_ms(1000); iwdg_start(); while (1) { iwdg_reset(); usbd_poll(usbd_dev); if (CDC_AVAILABLE) { cdc_uart_app_update(); } if (VCDC_AVAILABLE) { vcdc_app_update(); } // Handle DAP bool dap_active = DAP_app_update(); if (dap_active) { usb_timer = 1000; } else if (do_reset_to_dfu && DFU_AVAILABLE) { /* Blink 3 times to indicate reset */ int x; for (x=0; x < 3; x++) { iwdg_reset(); led_num(7); wait_ms(150); led_num(0); wait_ms(150); iwdg_reset(); } DFU_reset_and_jump_to_bootloader(); } if (usb_timer > 0) { usb_timer--; LED_ACTIVITY_OUT(1); } else { LED_ACTIVITY_OUT(0); } } return 0; }