void cpu_deinit_all() { //** ADC_DeInit(LPC_ADC); CAN_DeInit(LPC_CAN1); CAN_DeInit(LPC_CAN2); EMAC_DeInit(); EXTI_DeInit(); I2C_DeInit(LPC_I2C0); I2C_DeInit(LPC_I2C1); I2C_DeInit(LPC_I2C2); I2S_DeInit(LPC_I2S); NVIC_DeInit(); NVIC_SCBDeInit(); PWM_DeInit(LPC_PWM1); QEI_DeInit(LPC_QEI); //** RIT_DeInit(LPC_RIT); RTC_DeInit(LPC_RTC); SPI_DeInit(LPC_SPI); SSP_DeInit(LPC_SSP0); SSP_DeInit(LPC_SSP1); UART_DeInit(LPC_UART0); UART_DeInit((LPC_UART_TypeDef *) LPC_UART1); //** UART_DeInit(LPC_UART2); //** UART_DeInit(LPC_UART3); TIM_DeInit(LPC_TIM0); TIM_DeInit(LPC_TIM1); //** TIM_DeInit(LPC_TIM2); //** TIM_DeInit(LPC_TIM3); }
unsigned int RTC_cfg(void) { unsigned int ret; RTC_DateTypeDef RTC_DateStruct; RTC_TimeTypeDef RTC_TimeStruct; ret = 0; if (RTC_ReadBackupRegister(RTC_BKP_DR1) != 0xA5A5) { ret = 1; /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Reset Backup Domain */ RTC_DeInit(); /* Enable LSE */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} /* Select LSE as RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* Enable RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); /* Adjust time */ RTC_DateStruct.RTC_Year = 13; RTC_DateStruct.RTC_Month = 05; RTC_DateStruct.RTC_Date = 29; RTC_DateStruct.RTC_WeekDay = 3; RTC_TimeStruct.RTC_Hours = 11; RTC_TimeStruct.RTC_Minutes = 0; RTC_TimeStruct.RTC_Seconds = 0; RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct); RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct); RTC_WriteBackupRegister(RTC_BKP_DR1, 0xA5A5); } else { /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); while (RTC_GetFlagStatus(RTC_FLAG_RSF) == RESET); } return ret; }
int main(void) { time_t then, now; cpu_init(DEFAULT_CPU_FREQ); #ifdef CONSOLE_SERIAL serial_stdio(CONSOLE_PORT); #endif #ifdef CONSOLE_SEMIHOSTING semihosting_stdio(CONSOLE_PORT) #endif #ifdef CONSOLE_USB usb_serial_stdio(NULL); getch(); #endif puts("\033[H\033[2JSTR91x A/D Converter Test (" __DATE__ " " __TIME__ ")\n"); puts(revision); printf("\nCPU Freq:%u Hz Compiler:%s %s %s\n\n", (unsigned int) SystemCoreClock, __COMPILER__, __VERSION__, __ABI__); // Turn on peripheral clocks SCU_APBPeriphClockConfig(__RTC, ENABLE); SCU_APBPeriphClockConfig(__ADC, ENABLE); SCU_APBPeriphClockConfig(__GPIO4, ENABLE); // Configure RTC RTC_DeInit(); // Reset RTC // Configure P4.6 as analog input 6 GPIO_DeInit(GPIO4); // Reset GPIO4 GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE); // Configure A/D converter ADC_DeInit(); // Reset A/D converter ADC_Cmd(ENABLE); // Power on A/D converter ADC_PrescalerConfig(0x2); // Conversion clock is 24 MHz // Sample analog input 6 once a second then = 0; for (;;) { now = time(NULL); if (now == then) continue; then = now; printf("The value of A/D input 6 is %04X\n", SampleADC(ADC_Channel_6)); } }
OSStatus platform_rtc_init(void) { #ifdef MICO_ENABLE_MCU_RTC RTC_InitTypeDef RTC_InitStruct; RTC_DeInit( ); RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24; /* RTC ticks every second */ RTC_InitStruct.RTC_AsynchPrediv = 0x7F; RTC_InitStruct.RTC_SynchPrediv = 0xFF; RTC_Init( &RTC_InitStruct ); #ifdef USE_RTC_BKP /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); PWR_BackupRegulatorCmd(ENABLE); #endif /* 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); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* RTC configuration -------------------------------------------------------*/ /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); #ifdef USE_RTC_BKP if (RTC_ReadBackupRegister(RTC_BKP_DR0) != USE_RTC_BKP) { /* set it to 12:20:30 08/04/2013 monday */ platform_rtc_set_time(&default_rtc_time); RTC_WriteBackupRegister(RTC_BKP_DR0, USE_RTC_BKP); } #else //#ifdef RTC_ENABLED /* application must have mico_application_default_time structure declared somewhere, otherwise it wont compile */ /* write default application time inside rtc */ platform_rtc_set_time(&mico_default_time); //#endif /* RTC_ENABLED */ #endif return kNoErr; #else return kUnsupportedErr; #endif }
/** * @brief Configure the RTC peripheral by selecting the clock source. * @param None * @retval None */ static void RTC_Config(void) { RTC_InitTypeDef RTC_InitStructure; RTC_TimeTypeDef RTC_TimeStruct; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* 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); RTC_DeInit(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = 0x7F; RTC_InitStructure.RTC_SynchPrediv = 0xFF; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); /* Set the time to 00h 00mn 00s AM */ RTC_TimeStruct.RTC_H12 = RTC_H12_AM; RTC_TimeStruct.RTC_Hours = 0x00; RTC_TimeStruct.RTC_Minutes = 0x00; RTC_TimeStruct.RTC_Seconds = 0x00; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); }
platform_result_t platform_rtc_init( void ) { #ifdef WICED_ENABLE_MCU_RTC RTC_InitTypeDef RTC_InitStruct; RTC_DeInit( ); RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24; /* RTC ticks every second */ RTC_InitStruct.RTC_AsynchPrediv = 0x7F; RTC_InitStruct.RTC_SynchPrediv = 0xFF; RTC_Init( &RTC_InitStruct ); /* 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); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* RTC configuration -------------------------------------------------------*/ /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* write default application time inside rtc */ platform_rtc_set_time( &default_rtc_time ); return PLATFORM_SUCCESS; #else return PLATFORM_FEATURE_DISABLED; #endif }
/** * @brief RTC Tamper Configuration.. * @param None * @retval None */ static void RTC_Config(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Reset Backup Domain */ RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); /* 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); RTC_DeInit(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = 0x7F; RTC_InitStructure.RTC_SynchPrediv = 0xFF; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); /* Set the time to 00h 00mn 00s AM */ RTC_TimeStruct.RTC_H12 = RTC_H12_AM; RTC_TimeStruct.RTC_Hours = 0x00; RTC_TimeStruct.RTC_Minutes = 0x00; RTC_TimeStruct.RTC_Seconds = 0x00; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* EXTI configuration *******************************************************/ EXTI_ClearITPendingBit(EXTI_Line19); EXTI_InitStructure.EXTI_Line = EXTI_Line19; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable RTC_IRQn */ NVIC_InitStructure.NVIC_IRQChannel = TAMPER_STAMP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* determines the number of active pulse for the specific level */ RTC_TamperFilterConfig(RTC_TamperFilter_2Sample); /* Determines the frequency at which each of the tamper inputs are sampled */ RTC_TamperSamplingFreqConfig(RTC_TamperSamplingFreq_RTCCLK_Div32768); RTC_TamperPullUpCmd(DISABLE); /* Select the tamper 21 with High level */ RTC_TamperTriggerConfig(RTC_Tamper_1, RTC_TamperTrigger_HighLevel ); /* Clear tamper 1 falg */ RTC_ClearFlag(RTC_FLAG_TAMP1F); }