/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* GPIO configuration */ GPIO_Configuration(); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); /* Check if the Power On Reset flag is set */ if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { /* Clear reset flags */ RCC_ClearFlag(); /* Turn on led connected to GPIO_LED Pin8 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_8); /* Check if Backup data registers are programmed */ if(CheckBackupReg(0x3210) == 0x00) { /* Backup data registers values are correct */ /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); } else { /* Backup data registers values are not correct or they are not yet programmed (when the first time the program is executed) */ /* Write data to Backup data registers */ WriteToBackupReg(0x3210); /* Turn on led connected to GPIO_LED Pin7 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_7); } } /* Turn on led connected to GPIO_LED Pin9 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_9); 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 Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); /* Check if the Power On Reset flag is set */ if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { /* Clear reset flags */ RCC_ClearFlag(); /* Turn on LED3 */ STM_EVAL_LEDOn(LED3); /* Check if Backup data registers are programmed */ if(CheckBackupReg(0x3210) == 0x00) { /* Backup data registers values are correct */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* Backup data registers values are not correct or they are not yet programmed (when the first time the program is executed) */ /* Write data to Backup data registers */ WriteToBackupReg(0x3210); /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } } /* Turn on LED4 */ STM_EVAL_LEDOn(LED4); while (1) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); /* Check if the Power On Reset flag is set */ if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { /* Clear reset flags */ RCC_ClearFlag(); /* Turn on LED3 */ STM_EVAL_LEDOn(LED3); /* Check if Backup data registers are programmed */ if(CheckBackupReg(0x3210) == 0x00) { /* Backup data registers values are correct */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* Backup data registers values are not correct or they are not yet programmed (when the first time the program is executed) */ /* Write data to Backup data registers */ WriteToBackupReg(0x3210); /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } } /* Turn on LED4 */ STM_EVAL_LEDOn(LED4); while (1) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); /* Tamper pin active on low level */ BKP_TamperPinLevelConfig(BKP_TamperPinLevel_Low); /* Enable Tamper interrupt */ BKP_ITConfig(ENABLE); /* Enable Tamper pin */ BKP_TamperPinCmd(ENABLE); /* Write data to Backup DRx registers */ WriteToBackupReg(0xA53C); /* Check if the written data are correct */ if(CheckBackupReg(0xA53C) == 0x00) { /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } while (1) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Initialize four LEDs mounted on GD32107C-EVAL board */ LED_Init(); /* Enable PWR and BKP clock */ RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_PWR | RCC_APB1PERIPH_BKP, ENABLE); /* Enable write access to the registers in Backup domain */ PWR_BackupAccess_Enable(ENABLE); /* Clear the bit flag of Tamper Event */ BKP_ClearBitState(); /* Check if the POR/PDR reset flag is set */ if(RCC_GetBitState(RCC_FLAG_POPDRST) != RESET) { /* Clear the RCC all reset flags */ RCC_ClearBitState(); /* Turn on LED4 */ GPIO_SetBits(GPIOE, GPIO_PIN_0); /* Check if Backup data registers has been written */ if(CheckBackupReg(0x1226) == 0x00) { /* Backup data registers values are correct */ /* Turn on LED2 */ GPIO_SetBits(GPIOC, GPIO_PIN_0); } else { /* Backup data registers values are not correct or they are not written*/ /* Write data to Backup data registers */ WriteToBackupReg(0x1226); /* Turn on LED3 */ GPIO_SetBits(GPIOC, GPIO_PIN_2); } } /* Turn on LED5 */ GPIO_SetBits(GPIOE, GPIO_PIN_1); while (1) { } }
/** * @brief Configure the RTC peripheral by selecting the clock source. * @param None * @retval None */ void RTC_Config(void) { /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/ /* The RTC Clock may varies due to LSI frequency dispersion. */ /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); SynchPrediv = 0xFF; AsynchPrediv = 0x7F; #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */ /* Enable the LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); SynchPrediv = 0xFF; AsynchPrediv = 0x7F; #else #error Please select the RTC Clock source inside the main.c file #endif /* RTC_CLOCK_SOURCE_LSI */ /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Write to the first RTC Backup Data Register */ RTC_WriteBackupRegister(RTC_BKP_DR0, FIRST_DATA); /* Display the new RCC BDCR and RTC TAFCR Registers */ LCD_UsrLog ("RTC Reconfig \n"); LCD_UsrLog ("RCC BDCR = 0x%x\n", RCC->BDCR); LCD_UsrLog ("RTC TAFCR = 0x%x\n", RTC->TAFCR); /* Set the Time */ RTC_TimeStructure.RTC_Hours = 0x08; RTC_TimeStructure.RTC_Minutes = 0x00; RTC_TimeStructure.RTC_Seconds = 0x00; /* Set the Date */ RTC_DateStructure.RTC_Month = RTC_Month_March; RTC_DateStructure.RTC_Date = 0x18; RTC_DateStructure.RTC_Year = 0x11; RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Friday; /* Calendar Configuration */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); /* Set Current Time and Date */ RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure); /* Configure the RTC Wakeup Clock source and Counter (Wakeup event each 1 second) */ RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16); RTC_SetWakeUpCounter(0x7FF); /* Enable the Wakeup Interrupt */ RTC_ITConfig(RTC_IT_WUT, ENABLE); /* Enable Wakeup Counter */ RTC_WakeUpCmd(ENABLE); /* Backup SRAM ***************************************************************/ /* Enable BKPRAM Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE); /* Write to Backup SRAM with 32-Bit Data */ for (i = 0x0; i < 0x1000; i += 4) { *(__IO uint32_t *) (BKPSRAM_BASE + i) = i; } /* Check the written Data */ for (i = 0x0; i < 0x1000; i += 4) { if ((*(__IO uint32_t *) (BKPSRAM_BASE + i)) != i) { errorindex++; } } if(errorindex) { LCD_ErrLog ("BKP SRAM Number of errors = %d\n", errorindex); } else { LCD_UsrLog ("BKP SRAM write OK \n"); } /* Enable the Backup SRAM low power Regulator to retain it's content in VBAT mode */ PWR_BackupRegulatorCmd(ENABLE); /* Wait until the Backup SRAM low power Regulator is ready */ while(PWR_GetFlagStatus(PWR_FLAG_BRR) == RESET) { } /* RTC Backup Data Registers **************************************************/ /* Write to RTC Backup Data Registers */ WriteToBackupReg(FIRST_DATA); }
/** * @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 */ /* NVIC configuration */ NVIC_Configuration(); /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Disable Tamper pin */ BKP_TamperPinCmd(DISABLE); /* Disable Tamper interrupt */ BKP_ITConfig(DISABLE); /* Tamper pin active on low level */ BKP_TamperPinLevelConfig(BKP_TamperPinLevel_Low); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); /* Enable Tamper interrupt */ BKP_ITConfig(ENABLE); /* Enable Tamper pin */ BKP_TamperPinCmd(ENABLE); /* Write data to Backup DRx registers */ WriteToBackupReg(0xA53C); /* Check if the written data are correct */ if(CheckBackupReg(0xA53C) == 0x00) { /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } while (1) { } }