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) { } } }