/** * @brief USART configuration * @param None * @retval None */ void USART_Config(void) { /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); }
/** * @brief VCP_Init * Initializes the Media on the STM32 * @param None * @retval Result of the opeartion (USBD_OK in all cases) */ static uint16_t VCP_Init(void) { // BV: Not calling physical USART initialisation // Suggest we do not use this mechanism for any SPI configurations. But used some sort of serial commands. // Not sure if it affects the data but just in case we should set 8N1 to ensure full 8-bit data transfer is done. #if 0 NVIC_InitTypeDef NVIC_InitStructure; /* EVAL_COM1 default configuration */ /* EVAL_COM1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - Parity Odd - Hardware flow control disabled - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the USART Receive interrupt */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); /* Enable USART Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EVAL_COM1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); #endif return USBD_OK; }
/** * @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_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Output a message on Hyperterminal using printf function */ printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r"); /* Loop until the end of transmission */ /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) {} while (1) { } }
/** * @brief Initialize the IAP: Configure RCC, USART and GPIOs. * @param None * @retval None */ void IAP_Init(void) { USART_InitTypeDef USART_InitStructure; /* USART resources configuration (Clock, GPIO pins and USART registers) ----*/ /* USART configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the EVAL_COM1 Transmoit interrupt: this interrupt is generated when the EVAL_COM1 transmit data register is empty */ USART_ITConfig(EVAL_COM1, USART_IT_TXE, ENABLE); /* Enable the EVAL_COM1 Receive interrupt: this interrupt is generated when the EVAL_COM1 receive data register is not empty */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); while (1) { } }
/** * @brief Configures the USART Peripheral. * @param None * @retval None */ static void USART_Config(void) { USART_InitTypeDef USART_InitStructure; /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follows: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); }
/** * @brief Initialize COM1 interface for serial debug * @note COM1 interface is defined in stm3210g_eval.h file (under Utilities\STM32_EVAL\STM322xG_EVAL) * @param None * @retval None */ void DebugComPort_Init(void) { USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the EVAL_COM1 Transmoit interrupt: this interrupt is generated when the EVAL_COM1 transmit data register is empty */ USART_ITConfig(EVAL_COM1, USART_IT_TXE, ENABLE); /* Enable the EVAL_COM1 Receive interrupt: this interrupt is generated when the EVAL_COM1 receive data register is not empty */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /* Enable the USARTx Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
void comm_init (void) { USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Enable the USART Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = COM_USART_INT[COM1]; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); // RX in INT mode }
/** * @brief Configure USART peripheral * @param None * @retval None */ static void USART_Config(void) { /* High speed internal clock prescaler: 1*/ CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); /* EVAL COM (USARTx) configuration -----------------------------------------*/ /* USART configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - One Stop Bit - No parity - Receive and transmit enabled */ STM_EVAL_COMInit(COM1, (uint32_t)9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx)); /* Set Prescaler*/ USART_SetPrescaler(EVAL_COM1, 0x1); USART_IrDAConfig(EVAL_COM1, USART_IrDAMode_Normal); USART_IrDACmd(EVAL_COM1, ENABLE); }
void init_usart() { //while(1); //System_Setup(); /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // STM_EVAL_COMInit(COM1, &USART_InitStructure); printf("USART started... \n"); }
/******************************************************************************* * Function Name : USART_Config_Default. * Description : configure the EVAL_COM1 with default values. * Input : None. * Return : None. *******************************************************************************/ void USART_Config_Default(void) { /* EVAL_COM1 default configuration */ /* EVAL_COM1 configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - One Stop Bit - Parity Odd - Hardware flow control disabled - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the USART Receive interrupt */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); }
/** * @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_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Output a message on Hyperterminal using printf function */ printf("\n\r *********************** RTC Time Stamp Example ***********************\n\r"); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; /* Check on RTC init */ if (RTC_Init(&RTC_InitStructure) == ERROR) { printf("\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n\r"); } /* Configure the time register */ RTC_TimeRegulate(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n Power On Reset occurred....\n\r"); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n External Reset occurred....\n\r"); } printf("\r\n No need to configure RTC....\n\r"); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time/Date and TimeStamp Time/Date */ RTC_TimeShow(); RTC_DateShow(); RTC_TimeStampShow(); } /* Configure the external interrupt "TAMPER" and "Joystick SEL" buttons */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* Configure LED1 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDOn(LED1); /* Infinite loop */ while (1) { } }
void Board_main(void) { uint8_t i; uint16_t flash_flag = 0; uint16_t copy_file_flag = 0; /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { #if 0 /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); #else FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Enable); /* Flash 2 wait state */ /*FLASH_SetLatency(FLASH_Latency_2);*/ FLASH_SetLatency(FLASH_Latency_0); /*abin@ */ #endif /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); #if 0 /* PLLCLK = 8MHz * 9 = 72 MHz */ /*abin:note*/ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_8); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } #else RCC_PLLCmd(DISABLE); /* Select HSE as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x04) { } #endif } /* Enable GPIOA, GPIOB, and AFIO clocks */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO, ENABLE); /* Enable DMA1 ,DMA2 clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2, ENABLE); /* Enable ADC1 ADC2,and GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 |RCC_APB2Periph_ADC2| RCC_APB2Periph_GPIOC, ENABLE); /* 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(); #if ABIN_DEBUG USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Output a message on Hyperterminal using printf function */ //sys_printf("\n\r abin 8M is ok moify flash latency :USART Init end \n\r"); #endif /*------------------- Resources Initialization -----------------------------*/ /* GPIO Configuration */ GPIO_Config(); //sys_printf("\n\r abin mul2 :GPIO_Config \n\r"); #if ABIN_CPU_UPGRADE2HIGHSPEED_OPTION USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); if(USB_Plugin_State == 1) { //sys_printf("\n\r abin switch to high speed !!\n\r"); UpgradeToHighSpeed(); } #endif /* Interrupt Configuration */ InterruptConfig(); /* Configure the systick */ SysTick_Configuration(); /*------------------- Drivers Initialization -------------------------------*/ /* Initialize the Low Power application */ LowPower_Init(); /* Enable WKUP pin */ PWR_WakeUpPinCmd(ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); RTC_Init(); /* If HSE is not detected at program startup */ if(HSEStartUpStatus == ERROR) { /* Generate NMI exception */ SCB->ICSR |= SCB_ICSR_NMIPENDSET; } USB_Disconnect_Config(); GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);/*???abin@20100714*/ WakupPin_Init(); //sys_printf("\n\r abin before CheckPowerOnReason\n\r"); CheckPowerOnReason(); //sys_printf("\n\r abin after CheckPowerOnReason\n\r"); Board_ADC_Init(); /*init the flag*/ flash_flag = *(uint16_t *)FLASH_READY_ADDRESS; if( flash_flag != FLAG_FLASH_READY) { //sys_printf("\n\r abin ready to erase flash \n\r"); FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); //Erase the 32 page 32K for(i = 0;i< DATA_PAGES;i++) { //sys_printf("\n\r abin ready to erase aa"); FLASH_ErasePage(DATA_LOGGER_ADDRESS_START + i * 1024);/*数据在Page1...page32存放*/ } FLASH_ErasePage(FLASH_READY_ADDRESS); /*abin@20100715 没添加保护*/ FLASH_ProgramHalfWord(FLASH_READY_ADDRESS , FLAG_FLASH_READY); FLASH_ErasePage(REOCRD_COUNT_ADDRESS); FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , 0x0000); FLASH_Lock(); //sys_printf("\n\r abin mul2 :erase flash end!!!\n\r"); } //sys_printf("\n\r abin ready to erase flash end \n\r"); USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); if(USB_Plugin_State == 0) { record_count = *(uint16_t *)REOCRD_COUNT_ADDRESS; if(record_count >= 15428) { //Write the full flag //Do nothing.... while(1) { //sys_printf("\n\r sample end !!!!!!!!!!!!!!!!!!!!!\n\r"); Led_One_By_One(4); /*应该进入standy 模式 abin@20100715*/ } } else { //sys_printf("\n\r abin ready to add sample count \n\r"); FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); FLASH_ProgramHalfWord(DATA_LOGGER_ADDRESS_START + record_count * 2, GetTemperature()); //Erase first FLASH_ErasePage(REOCRD_COUNT_ADDRESS); //Update the count record_count = record_count + 1; FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , record_count); FLASH_Lock(); //sys_printf("\n\r abin add sample count :end\n\r"); } //sys_printf("\n\r %000\n\r"); GPIO_SetBits(GPIOA, GPIO_Pin_1); #if 0 Delay(25); #else Delay(5); #endif //sys_printf("\n\r %111\n\r"); } else { Enable_SDcard(); /* if there is usb connect, copy the data to sdcard. and start the mass storage */ copy_file_flag = *(uint16_t *)COPY_FILE_ADDRESS; if(copy_file_flag == FLAG_FILE_COPYED) { Write_Copy_File_Flag(FLAG_FILE_NO_COPYED); USB_Disconnect_Config(); GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN); Delay(10); GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN); /* Enable and GPIOD clock */ Mass_Storage_Start (); while( bDeviceState != CONFIGURED) { Led_Both(1); } USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); while( USB_Plugin_State == 1)/* U-DISK success ,then CPU Loop in here*/ { USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); Led_One_By_One(1); //sys_printf("\n\r abin :mul2 u disk !!!\n\r"); } PowerOff(); Write_Copy_File_Flag(FLAG_FILE_NO_COPYED); } else { Write_Copy_File_Flag(FLAG_FILE_COPYED); Led_Green_Flink(3); NAND_FAT(); CreateDataLoggerFile(); Write_Copy_File_Flag(FLAG_FILE_COPYED); //sys_printf("\n\r abin :mul2 NAND_FAT!!!\n\r"); } //sys_printf("\n\r abin :mul2 Disable_SDcard!!!\n\r"); Disable_SDcard(); BKP_WriteBackupRegister(BKP_POWER_ON, FLAG_POWER_OFF); PWR_EnterSTANDBYMode(); /* Generate a system reset */ //NVIC_SystemReset(); } //sys_printf("\n\r @111 \n\r"); /* Set the RTC Alarm after 60s */ RTC_SetAlarm(RTC_GetCounter()+ 3); //sys_printf("\n\r @222:RTC_GetCounter()=0x%x \n\r",RTC_GetCounter()); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); //sys_printf("\n\r @333\n\r"); PWR_EnterSTANDBYMode(); }
/** * @brief VCP_COMConfig * Configure the COM Port with default values or values received from host. * @param Conf: can be DEFAULT_CONFIG to set the default configuration or OTHER_CONFIG * to set a configuration received from the host. * @retval None. */ static uint16_t VCP_COMConfig(uint8_t Conf) { // BV: Not calling physical USART configuration // Suggest we do not use this mechanism for any SPI configurations. But used some sort of serial commands. // Not sure if it affects the data but just in case we should set 8N1 to ensure full 8-bit data transfer is done. #if 0 if (Conf == DEFAULT_CONFIG) { /* EVAL_COM1 default configuration */ /* EVAL_COM1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - Parity Odd - Hardware flow control disabled - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the USART Receive interrupt */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); } else { /* set the Stop bit*/ switch (linecoding.format) { case 0: USART_InitStructure.USART_StopBits = USART_StopBits_1; break; case 1: USART_InitStructure.USART_StopBits = USART_StopBits_1_5; break; case 2: USART_InitStructure.USART_StopBits = USART_StopBits_2; break; default : VCP_COMConfig(DEFAULT_CONFIG); return (USBD_FAIL); } /* set the parity bit*/ switch (linecoding.paritytype) { case 0: USART_InitStructure.USART_Parity = USART_Parity_No; break; case 1: USART_InitStructure.USART_Parity = USART_Parity_Even; break; case 2: USART_InitStructure.USART_Parity = USART_Parity_Odd; break; default : VCP_COMConfig(DEFAULT_CONFIG); return (USBD_FAIL); } /*set the data type : only 8bits and 9bits is supported */ switch (linecoding.datatype) { case 0x07: /* With this configuration a parity (Even or Odd) should be set */ USART_InitStructure.USART_WordLength = USART_WordLength_8b; break; case 0x08: if (USART_InitStructure.USART_Parity == USART_Parity_No) { USART_InitStructure.USART_WordLength = USART_WordLength_8b; } else { USART_InitStructure.USART_WordLength = USART_WordLength_9b; } break; default : VCP_COMConfig(DEFAULT_CONFIG); return (USBD_FAIL); } USART_InitStructure.USART_BaudRate = linecoding.bitrate; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); } #endif return USBD_OK; }
/******************************************************************************* * Function Name : USART_Config. * Description : Configure the EVAL_COM1 according to the line coding structure. * Input : None. * Return : Configuration status TRUE : configuration done with success FALSE : configuration aborted. *******************************************************************************/ bool USART_Config(void) { /* set the Stop bit*/ switch (linecoding.format) { case 0: USART_InitStructure.USART_StopBits = USART_StopBits_1; break; case 1: USART_InitStructure.USART_StopBits = USART_StopBits_1_5; break; case 2: USART_InitStructure.USART_StopBits = USART_StopBits_2; break; default : { USART_Config_Default(); return (FALSE); } } /* set the parity bit*/ switch (linecoding.paritytype) { case 0: USART_InitStructure.USART_Parity = USART_Parity_No; break; case 1: USART_InitStructure.USART_Parity = USART_Parity_Even; break; case 2: USART_InitStructure.USART_Parity = USART_Parity_Odd; break; default : { USART_Config_Default(); return (FALSE); } } /*set the data type : only 8bits and 9bits is supported */ switch (linecoding.datatype) { case 0x07: /* With this configuration a parity (Even or Odd) should be set */ USART_InitStructure.USART_WordLength = USART_WordLength_8b; break; case 0x08: if (USART_InitStructure.USART_Parity == USART_Parity_No) { USART_InitStructure.USART_WordLength = USART_WordLength_8b; } else { USART_InitStructure.USART_WordLength = USART_WordLength_9b; } break; default : { USART_Config_Default(); return (FALSE); } } USART_InitStructure.USART_BaudRate = linecoding.bitrate; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); return (TRUE); }
/** * @brief VCP_COMConfig * Configure the COM Port with default values or values received from host. * @param Conf: can be DEFAULT_CONFIG to set the default configuration or OTHER_CONFIG * to set a configuration received from the host. * @retval None. */ static uint16_t VCP_COMConfig(uint8_t Conf) { #if 0 if (Conf == DEFAULT_CONFIG) { /* EVAL_COM1 default configuration */ /* EVAL_COM1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - Parity Odd - Hardware flow control disabled - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Enable the USART Receive interrupt */ USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); } else { /* set the Stop bit*/ switch (linecoding.format) { case 0: USART_InitStructure.USART_StopBits = USART_StopBits_1; break; case 1: USART_InitStructure.USART_StopBits = USART_StopBits_1_5; break; case 2: USART_InitStructure.USART_StopBits = USART_StopBits_2; break; default : VCP_COMConfig(DEFAULT_CONFIG); return (USBD_FAIL); } /* set the parity bit*/ switch (linecoding.paritytype) { case 0: USART_InitStructure.USART_Parity = USART_Parity_No; break; case 1: USART_InitStructure.USART_Parity = USART_Parity_Even; break; case 2: USART_InitStructure.USART_Parity = USART_Parity_Odd; break; default : VCP_COMConfig(DEFAULT_CONFIG); return (USBD_FAIL); } /*set the data type : only 8bits and 9bits is supported */ switch (linecoding.datatype) { case 0x07: /* With this configuration a parity (Even or Odd) should be set */ USART_InitStructure.USART_WordLength = USART_WordLength_8b; break; case 0x08: if (USART_InitStructure.USART_Parity == USART_Parity_No) { USART_InitStructure.USART_WordLength = USART_WordLength_8b; } else { USART_InitStructure.USART_WordLength = USART_WordLength_9b; } break; default : VCP_COMConfig(DEFAULT_CONFIG); return (USBD_FAIL); } USART_InitStructure.USART_BaudRate = linecoding.bitrate; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure and enable the USART */ STM_EVAL_COMInit(COM1, &USART_InitStructure); } #endif return USBD_OK; }
/** * @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 LED1 mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* NVIC configuration */ NVIC_Configuration(); if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */ printf("\r\n\n RTC not yet configured...."); /* RTC Configuration */ RTC_Configuration(); printf("\r\n RTC configured...."); /* Adjust time by values entered by the user on the hyperterminal */ Time_Adjust(); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n\n Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n\n External Reset occurred...."); } printf("\r\n No need to configure RTC...."); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } #ifdef RTCClockOutput_Enable /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Disable the Tamper Pin */ BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */ /* Enable RTC Clock Output on Tamper Pin */ BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock); #endif /* Clear reset flags */ RCC_ClearFlag(); /* Display time in infinite loop */ Time_Show(); }
/** * @brief Display Init (LCD or/and USART) * @param None * @retval None */ static void Display_Init(void) { #ifdef PRINT_ON_USART USART_InitTypeDef USART_InitStructure; /* USARTx configured as follows: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); printf("\n\r ========================================\n"); printf("\n\r ==== Multiple RNG Generator Example ====\n"); printf("\n\r ======================================== \n\n\r"); printf("\n\r Press key button to generate 8 x 32bit random number\n"); #endif #ifdef PRINT_ON_LCD /* Initialize the LCD */ LCD_Init(); /* Display message on LCD ***************************************************/ #if defined (USE_STM324x9I_EVAL) /* Initialize the LCD Layers */ LCD_LayerInit(); /* Enable The Display */ LCD_DisplayOn(); /* Set LCD Background Layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* Clear the Background Layer */ LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Foreground Layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* Configure the transparency for foreground */ LCD_SetTransparency(100); #endif /* USE_STM324x9I_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Text size */ LCD_SetFont(&FONTSIZE); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(LINE(LINENUM), (uint8_t*)MESSAGE1); LCD_DisplayStringLine(LINE(0x16), (uint8_t*)" "); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_DisplayStringLine(LINE(0), (uint8_t*)MESSAGE2); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(LINE(3), (uint8_t*)MESSAGE3); LCD_DisplayStringLine(LINE(5), (uint8_t*)MESSAGE4); #endif }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Configure the system clocks */ RCC_Configuration(); /* Initialize Leds and Key Button mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(Button_KEY, Mode_EXTI); /* Configures the DMA Channel */ DMA_Configuration(); /* EVAL_COM1 configuration ---------------------------------------------------*/ /* EVAL_COM1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); USART_DMACmd(EVAL_COM1, USART_DMAReq_Rx, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the USARTy_DMA1_IRQn Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USARTy_DMA1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_Init(&NVIC_InitStructure); while (1) { if(LowPowerMode == 1) { STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); /* Request to enter WFI mode */ __WFI(); LowPowerMode = 0; } Delay(0xFFFFF); STM_EVAL_LEDToggle(LED1); } }
/** * @brief Main program. * @param None * @retval None */ void RTC_Calendar_Example(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Output a message on Hyperterminal using printf function */ printf("\n\r *********************** RTC Hardware Calendar Example ***********************\n\r"); #if defined (RTC_CLOCK_SOURCE_LSI) RCC_LSICmd(ENABLE); #endif if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; /* Check on RTC init */ if (RTC_Init(&RTC_InitStructure) == ERROR) { printf("\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n\r"); } /* Configure the time register */ RTC_TimeRegulate(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n Power On Reset occurred....\n\r"); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n External Reset occurred....\n\r"); } printf("\n\r No need to configure RTC....\n\r"); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time and Alarm */ RTC_TimeShow(); RTC_AlarmShow(); } /* Configure the external interrupt "KEY", "SEL" and "UP" buttons */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI); /* Configure LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* Turn LED2 ON */ STM_EVAL_LEDOn(LED2); /* RTC Alarm A Interrupt Configuration */ /* EXTI configuration *******************************************************/ EXTI_ClearITPendingBit(EXTI_Line17); EXTI_InitStructure.EXTI_Line = EXTI_Line17; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the RTC Alarm Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Infinite loop */ 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 */ /* Configure the system clocks */ RCC_Configuration(); /* Initialize Leds and Key Button mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* Configures the DMA Channel */ DMA_Configuration(); /* EVAL_COM1 configuration ---------------------------------------------------*/ /* EVAL_COM1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); USART_DMACmd(EVAL_COM1, USART_DMAReq_Rx, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the USARTy_DMA1_IRQn Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USARTy_DMA1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_Init(&NVIC_InitStructure); while (1) { if(LowPowerMode == 1) { STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); /* Request to enter WFI mode */ __WFI(); LowPowerMode = 0; } Delay(0xFFFFF); STM_EVAL_LEDToggle(LED1); } }
/** * @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, Key Button, LCD and COM port(USART) available on STM3210X-EVAL board ******************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Initialize the LCD */ #ifdef USE_STM32100B_EVAL STM32100B_LCD_Init(); #elif defined (USE_STM3210B_EVAL) STM3210B_LCD_Init(); #elif defined (USE_STM3210E_EVAL) STM3210E_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #elif defined (USE_STM32100E_EVAL) STM32100E_LCD_Init(); #endif /* Display message on STM3210X-EVAL LCD *************************************/ /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the LCD Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)MESSAGE1); LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)MESSAGE2); LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)MESSAGE3); /* Retarget the C library printf function to the USARTx, can be USART1 or USART2 depending on the EVAL board you are using ********************************/ printf("\n\r %s", MESSAGE1); printf(" %s", MESSAGE2); printf(" %s\n\r", MESSAGE3); /* Turn on leds available on STM3210X-EVAL **********************************/ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* Add your application code here */ /* Infinite loop */ 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_stm32l1xx_md.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize LEDs, Key Button, LCD and COM port(USART) available on STM32L1XX-EVAL board *****************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Initialize the LCD */ #ifdef USE_STM32L152_EVAL STM32L152_LCD_Init(); #endif /* Display message on STM32L1XX-EVAL LCD ************************************/ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); /* Retarget the C library printf function to the USARTx, can be USART2 or USART3 depending on the EVAL board you are using ********************************/ printf("\n\r %s", MESSAGE1); printf(" %s", MESSAGE2); printf(" %s\n\r", MESSAGE3); /* Turn on leds available on STM32L1XX-EVAL *********************************/ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); /* Add your application code here */ /* Infinite loop */ while (1) { /* Toggle LD1 */ STM_EVAL_LEDToggle(LED1); /* Insert 50 ms delay */ Delay(5); /* Toggle LD2 */ STM_EVAL_LEDToggle(LED2); /* Insert 50 ms delay */ Delay(5); } }