static void prvSetupHardware( void ) { /* Ensure that all 4 interrupt priority bits are used as the pre-emption priority. */ NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); /* Set up the LED outputs and the button inputs. */ STM32vldiscovery_LEDInit( LED3 ); STM32vldiscovery_LEDInit( LED4 ); STM32vldiscovery_PBInit( BUTTON_USER, BUTTON_MODE_EXTI ); /* Start with the LEDs off. */ STM32vldiscovery_LEDOff( LED3 ); STM32vldiscovery_LEDOff( LED4 ); }
/** * @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_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Configure all unused GPIO port pins in Analog Input mode (floating input trigger OFF), this will reduce the power consumption and increase the device immunity against EMI/EMC *************************************************/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, DISABLE); /* Initialize Leds LD3 and LD4 mounted on STM32VLDISCOVERY board */ STM32vldiscovery_LEDInit(LED3); STM32vldiscovery_LEDInit(LED4); while (1) { /* Turn on LD2 and LD3 */ STM32vldiscovery_LEDOn(LED3); STM32vldiscovery_LEDOn(LED4); /* Insert delay */ Delay(0xAFFFF); /* Turn off LD3 and LD4 */ STM32vldiscovery_LEDOff(LED3); STM32vldiscovery_LEDOff(LED4); /* Insert delay */ Delay(0xAFFFF); } }
static void vLEDTimerCallback( xTimerHandle xTimer ) { /* The timer has expired - so no button pushes have occurred in the last five seconds - turn the LED off. NOTE - accessing the LED port should use a critical section because it is accessed from multiple tasks, and the button interrupt - in this trivial case, for simplicity, the critical section is omitted. */ STM32vldiscovery_LEDOff( LED4 ); }
int main(void) { /* Enable GPIOx Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Initialise LEDs LD3&LD4, both off */ STM32vldiscovery_LEDInit(LED3); STM32vldiscovery_LEDInit(LED4); STM32vldiscovery_LEDOff(LED3); STM32vldiscovery_LEDOff(LED4); /* Initialise USER Button */ STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } /* Enable access to the backup register => LSE can be enabled */ PWR_BackupAccessCmd(ENABLE); /* Enable LSE (Low Speed External Oscillation) */ RCC_LSEConfig(RCC_LSE_ON); /* Check the LSE Status */ while(1) { if(LSE_Delay < LSE_FAIL_FLAG) { /* check whether LSE is ready, with 4 seconds timeout */ Delay (500); LSE_Delay += 0x10; if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) { /* Set flag: LSE PASS */ LSE_Delay |= LSE_PASS_FLAG; /* Turn Off Led4 */ STM32vldiscovery_LEDOff(LED4); /* Disable LSE */ RCC_LSEConfig(RCC_LSE_OFF); break; } } /* LSE_FAIL_FLAG = 0x80 */ else if(LSE_Delay >= LSE_FAIL_FLAG) { if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { /* Set flag: LSE FAIL */ LSE_Delay |= LSE_FAIL_FLAG; /* Turn On Led4 */ STM32vldiscovery_LEDOn(LED4); } /* Disable LSE */ RCC_LSEConfig(RCC_LSE_OFF); break; } } /* main while */ while(1) { if(0 == STM32vldiscovery_PBGetState(BUTTON_USER)) { if(KeyState == 1) { if(0 == STM32vldiscovery_PBGetState(BUTTON_USER)) { /* USER Button released */ KeyState = 0; /* Turn Off LED4 */ STM32vldiscovery_LEDOff(LED4); } } } else if(STM32vldiscovery_PBGetState(BUTTON_USER)) { if(KeyState == 0) { if(STM32vldiscovery_PBGetState(BUTTON_USER)) { /* USER Button released */ KeyState = 1; /* Turn ON LED4 */ STM32vldiscovery_LEDOn(LED4); Delay(1000); /* Turn OFF LED4 */ STM32vldiscovery_LEDOff(LED4); /* BlinkSpeed: 0 -> 1 -> 2, then re-cycle */ BlinkSpeed ++ ; } } } count++; Delay(100); /* BlinkSpeed: 0 */ if(BlinkSpeed == 0) { if(4 == (count % 8)) STM32vldiscovery_LEDOn(LED3); if(0 == (count % 8)) STM32vldiscovery_LEDOff(LED3); } /* BlinkSpeed: 1 */ if(BlinkSpeed == 1) { if(2 == (count % 4)) STM32vldiscovery_LEDOn(LED3); if(0 == (count % 4)) STM32vldiscovery_LEDOff(LED3); } /* BlinkSpeed: 2 */ if(BlinkSpeed == 2) { if(0 == (count % 2)) STM32vldiscovery_LEDOn(LED3); else STM32vldiscovery_LEDOff(LED3); } /* BlinkSpeed: 3 */ else if(BlinkSpeed == 3) BlinkSpeed = 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_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Initialize LED3 and USER Button mounted on STM32 Discovery board */ STM32vldiscovery_LEDInit(LED3); STM32vldiscovery_LEDInit(LED4); STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); /* Configure SysTick to generate an interrupt each 250ms */ SysTick_Configuration(); /* 1 bits for pre-emption priority and 3 bits for subpriority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Set Button EXTI Interrupt priority to 0 (highest) */ NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0)); /* Set SysTick interrupt vector Preemption Priority to 1 */ NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),1,0)); /* Check if the system has resumed from IWDG reset */ if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET) { /* IWDGRST flag set */ /* Turn on LD3 */ STM32vldiscovery_LEDOn(LED3); /* Clear reset flags */ RCC_ClearFlag(); } else { /* IWDGRST flag is not set */ /* Turn off LD3 */ STM32vldiscovery_LEDOff(LED3); } /* IWDG timeout equal to 280 ms (the timeout may vary due to LSI frequency dispersion) */ /* Enable write access to IWDG_PR and IWDG_RLR registers */ IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); /* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz */ IWDG_SetPrescaler(IWDG_Prescaler_32); /* Set counter reload value to 349 */ IWDG_SetReload(349); /* Reload IWDG counter */ IWDG_ReloadCounter(); /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ IWDG_Enable(); while (1) {} }