/** * @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 LEDs LD3, LD4 and USER Button mounted on STM32VLDISCOVERY board */ STM32vldiscovery_LEDInit(LED3); STM32vldiscovery_LEDInit(LED4); STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); /* Turn on LD3 */ STM32vldiscovery_LEDOn(LED3); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* Configure the SysTick to generate an interrupt each 250 ms */ SysTick_Configuration(); while (1) { } }
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); } }
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 */ /* Configure the system clocks */ RCC_Configuration(); /* Initialize LEDs LD3 and LD4 and USER Button mounted on STM32VLDISCOVERY Board */ STM32vldiscovery_LEDInit(LED3); STM32vldiscovery_LEDInit(LED4); STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* Test if Key Button GPIO Pin level is low (Key push-button on STM32 Discovery Board pressed) */ if (STM32vldiscovery_PBGetState(BUTTON_USER) != 0x00) { /* Key is pressed */ /* Turn on LED1 */ STM32vldiscovery_LEDOn(LED3); /* Disable the Serial Wire Jtag Debug Port SWJ-DP */ GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); /* Configure PA.13 (JTMS/SWDAT), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; GPIO_Init(GPIOB, &GPIO_InitStructure); while (1) { /* Toggle JTMS/SWDAT pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_13))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTCK/SWCLK pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_14, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_14))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTDI pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_15, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_15))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTDO pin */ GPIO_WriteBit(GPIOB, GPIO_Pin_3, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_3))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTRST pin */ GPIO_WriteBit(GPIOB, GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_4))); /* Insert delay */ Delay(0x5FFFF); } } else { /* Turn on LD4 */ STM32vldiscovery_LEDOn(LED4); while (1) { } } }
/** * @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) {} }