/******************************************************************************* * 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 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_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* Configure the external interrupt "WAKEUP", "KEY" and "TAMPER" buttons */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_WAKEUP , BUTTON_MODE_GPIO); /* Initialize the LCD */ STM322xG_LCD_Init(); /* Configure the LCD Log Module */ LCD_LOG_Init(); LCD_LOG_SetHeader("RTC Backup Domain Example"); LCD_LOG_SetFooter (" Copyright (c) STMicroelectronics" ); /* Display the default RCC BDCR and RTC TAFCR Registers */ LCD_UsrLog ("Entry Point \n"); LCD_UsrLog ("RCC BDCR = 0x%x\n", RCC->BDCR); LCD_UsrLog ("RTC TAFCR = 0x%x\n", RTC->TAFCR); /* Enable the PWR APB1 Clock Interface */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the RTC Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* EXTI configuration *******************************************************/ EXTI_ClearITPendingBit(EXTI_Line22); EXTI_InitStructure.EXTI_Line = EXTI_Line22; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); if(RTC_ReadBackupRegister(RTC_BKP_DR0) != FIRST_DATA) { LCD_UsrLog ("RTC Config PLZ Wait. \n"); /* RTC Configuration */ RTC_Config(); /* Adjust Current Time */ Time_Adjust(); /* Adjust Current Date */ Date_Adjust(); } else { /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); RTC_ClearITPendingBit(RTC_IT_WUT); EXTI_ClearITPendingBit(EXTI_Line22); /* Backup SRAM ***************************************************************/ /* Enable BKPSRAM Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE); /* 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 Content OK \n"); } /* RTC Backup Data Registers **************************************************/ /* Check if RTC Backup DRx registers data are correct */ if (CheckBackupReg(FIRST_DATA) == 0x00) { /* OK, RTC Backup DRx registers data are correct */ LCD_UsrLog ("OK, RTC Backup DRx registers data are correct. \n"); } else { /* Error, RTC Backup DRx registers data are not correct */ LCD_ErrLog ("RTC Backup DRx registers data are not correct\n"); } } /* Infinite loop */ Calendar_Show(); 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 */ /* 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) { } }