/** * @brief USBD_USR_DeviceReset * Displays the message on LCD on device Reset Event * @param speed : device speed * @retval None */ void USBD_USR_DeviceReset(uint8_t speed ) { switch (speed) { case USB_OTG_SPEED_HIGH: LCD_LOG_SetFooter (" USB Device Library v1.1.0 [HS]" ); break; case USB_OTG_SPEED_FULL: LCD_LOG_SetFooter (" USB Device Library v1.1.0 [FS]" ); break; default: LCD_LOG_SetFooter (" USB Device Library v1.1.0 [??]" ); } }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if(startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); #ifdef USE_STM3210C_EVAL STM3210C_LCD_Init(); #else STM322xG_LCD_Init(); #endif LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS HID Host"); #else LCD_LOG_SetHeader(" USB OTG FS HID Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.0.0" ); } }
static uint8_t Image_Browser (char* path) { FRESULT res; uint8_t ret = 1; FILINFO fno; DIR dir; char *fn; uint8_t key = 0; res = f_opendir(&dir, path); if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; if (fno.fname[0] == '.') continue; fn = fno.fname; if (fno.fattrib & AM_DIR) { continue; } else { if((strstr(fn, "bmp")) || (strstr(fn, "BMP"))) { res = f_open(&file, fn, FA_OPEN_EXISTING | FA_READ); Show_Image(); USB_OTG_BSP_mDelay(100); ret = 0; // while((HCD_IsDeviceConnected(&USB_OTG_Core)))// && \ //// (STM_EVAL_PBGetState (BUTTON_KEY) == SET)) // { // Toggle_Leds(); // } while(key != '1') { SerialKeyPressed((uint8_t*)&key); Toggle_Leds(); } key = 0; f_close(&file); } } } } #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS MSC Host"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Host"); #endif LCD_LOG_SetFooter (" USB Host Library v2.1.0" ); LCD_UsrLog("> Disk capacity : %d Bytes\n", USBH_MSC_Param.MSCapacity * \ USBH_MSC_Param.MSPageLength); USBH_USR_ApplicationState = USH_USR_FS_READLIST; return ret; }
/** * @brief USBD_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBD_USR_Init(void) { /* Initialize LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ #if defined (USE_STM322xG_EVAL) STM322xG_LCD_Init(); #elif defined(USE_STM324xG_EVAL) STM324xG_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #else #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)" #endif LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS DFU Device"); #else LCD_LOG_SetHeader(" USB OTG FS DFU Device"); #endif LCD_UsrLog("> USB device library started.\n"); LCD_LOG_SetFooter (" USB Device Library v1.1.0" ); /* Information panel */ LCD_SetTextColor(Green); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION1); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); }
/** * @brief Displays the message on LCD on device lib initialization * @param None * @retval None */ void USBD_USR_Init(void) { /* Initialize LEDs */ STM_EVAL_LEDInit(LED4); /* Init LCD */ STM32f4_Discovery_LCD_Init(); LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS MSC Device"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Device"); #endif LCD_UsrLog("> USB device library started.\n"); LCD_LOG_SetFooter (" USB Device Library v1.1.0" ); /* Information panel */ LCD_SetTextColor(Green); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, USER_INFORMATION1); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION2); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); }
/** * @brief LCD Log demo * @param None * @retval None */ void Log_demo(void) { JOYState_TypeDef JoyState = JOY_NONE; uint8_t i = 0; /* Wait For User inputs */ while(CheckForUserInput() == 0); BSP_JOY_Init(JOY_MODE_GPIO); /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Log Example"); LCD_LOG_SetFooter((uint8_t *)"Use Joystick to scroll up/down"); /* Output User logs */ for (i = 0; i < 10; i++) { LCD_UsrLog ("This is Line %d \n", i); } HAL_Delay(2000); /* Clear Old logs */ LCD_LOG_ClearTextZone(); /* Output new user logs */ for (i = 0; i < 30; i++) { LCD_UsrLog ("This is Line %d \n", i); } /* Check for joystick user input for scroll (back and forward) */ while (1) { JoyState = BSP_JOY_GetState(); switch(JoyState) { case JOY_UP: LCD_LOG_ScrollBack(); break; case JOY_DOWN: LCD_LOG_ScrollForward(); break; default: break; } if(CheckForUserInput() > 0) { return; } HAL_Delay (10); } }
/** * @brief Image browser * @param path: pointer to root path * @retval None */ static uint8_t Image_Browser(char *path) { FRESULT res; uint8_t ret = 1; FILINFO fno; DIR dir; char *fn; res = f_opendir(&dir, path); if (res != FR_OK) { Error_Handler(); } else { for (;;) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; if (fno.fname[0] == '.') continue; fn = fno.fname; if (fno.fattrib & AM_DIR) { continue; } else { if((strstr(fn, "bmp")) || (strstr(fn, "BMP"))) { res = f_open(&file, fn, FA_OPEN_EXISTING | FA_READ); Show_Image(); USBH_Delay(100); ret = 0; while((Appli_state == APPLICATION_START) && \ (BSP_PB_GetState (BUTTON_KEY) != SET)) { Toggle_Leds(); } f_close(&file); } } } } /* LCD Log initialization */ LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t *)"LTDC Application"); LCD_LOG_SetFooter ((uint8_t *)" USB Host Library V3.2.0" ); USBH_USR_ApplicationState = USH_USR_FS_READLIST; f_closedir(&dir); return ret; }
/** * @brief Program entry point * @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_stm32fxxx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32fxxx.c file */ /* Initialize the LCD */ STM32f4_Discovery_LCD_Init(); LCD_LOG_Init(); LCD_LOG_SetHeader(" Binary image template "); LCD_UsrLog("> Systick template example started.\n"); LCD_LOG_SetFooter (" Binary image template " ); /* Configure the LEDs */ STM_EVAL_LEDInit(LED4); /* Set the Vector Table base location at the application start address (this is already done in system_stm32fxxx.c file) */ //#ifdef STM32F2XX // /* Set the Vector Table base location at 0xC000 */ // NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000); //#elif defined(STM32F4XX) // /* Set the Vector Table base location at 0xC000 */ // NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000); //#elif defined(STM32F10X_CL) // /* Set the Vector Table base location at 0x8000 */ // NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000); //#endif /* STM32F2XX */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); while (1) { /* Toggle all leds */ STM_EVAL_LEDToggle(LED4); /* Insert 200 ms delay */ Delay(200); /* Toggle all leds */ STM_EVAL_LEDToggle(LED4); /* Insert 200 ms delay */ Delay(200); } }
/** * @brief Initializes the STM324x9I-EVAL's LCD and LEDs resources. * @param None * @retval None */ static void BSP_Config(void) { #ifdef USE_LCD uint8_t lcd_status = LCD_OK; #endif /* USE_LCD */ /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Init MFX IO Expander */ BSP_IO_Init(); /* Enable MFX IO Expander interrupt for ETH MII pin */ BSP_IO_ConfigPin(MII_INT_PIN, IO_MODE_IT_FALLING_EDGE); #ifdef USE_LCD /* Initialize and start the LCD display in mode 'lcd_mode' * Using LCD_FB_START_ADDRESS as frame buffer displayed contents. * This buffer is modified by the BSP (draw fonts, objects depending on BSP calls). */ /* Set Portrait orientation if needed, by default orientation is set to Landscape */ /* Initialize DSI LCD */ // BSP_LCD_InitEx(LCD_ORIENTATION_PORTRAIT); /* uncomment if Portrait orientation is needed */ BSP_LCD_Init(); /* Uncomment if default config (landscape orientation) is needed */ while(lcd_status != LCD_OK); BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_SetFont(&LCD_DEFAULT_FONT); /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Webserver Application Netconn API"); LCD_LOG_SetFooter((uint8_t *)"STM32469I-EVAL board"); LCD_UsrLog ((char *)" State: Ethernet Initialization ...\n"); #endif /* USE_LCD */ }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if(startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* Initialize the LCD */ LCD_Init(); LCD_LayerInit(); /* Set LCD background layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* Set LCD transparency */ LCD_SetTransparency(0); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* LCD Log initialization */ LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader("PDF Create"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.1.0" ); } }
/** * @brief LCD configuration. * @param None * @retval None */ static void LCD_Config(void) { /* LCD Initialization */ BSP_LCD_Init(); /* LCD Layers Initialization */ BSP_LCD_LayerDefaultInit(LCD_FOREGROUND_LAYER, (LCD_FRAME_BUFFER + BUFFER_OFFSET)); /* Configure the transparency for foreground : Increase the transparency */ BSP_LCD_SetTransparency(LCD_BACKGROUND_LAYER, 0); BSP_LCD_SelectLayer(LCD_FOREGROUND_LAYER); /* LCD Log initialization */ LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t *)"LTDC Application"); LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter ((uint8_t *)" USB Host Library V3.2.0" ); }
/** * @brief LCD Log demo * @param None * @retval None */ void Log_demo(void) { uint8_t i = 0; /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t*)"This is the header"); LCD_LOG_SetFooter((uint8_t*)"This is the footer"); /* Wait For User inputs */ while(CheckForUserInput() == 0); /* Output User logs */ for (i = 0; i < 10; i++) { LCD_UsrLog ("This is Line %d \n", i); HAL_Delay(100); } HAL_Delay(1500); /* Clear Old logs */ LCD_LOG_ClearTextZone(); /* Output new user logs */ for (i = 0; i < 30; i++) { LCD_UsrLog ("This is Line %d \n", i); HAL_Delay(100); } /* Check for joystick user input for scroll (back and forward) */ while (1) { if(CheckForUserInput() > 0) { return; } HAL_Delay (10); } }
/** * @brief Configurates the BSP. * @param None * @retval None */ static void BSP_Config(void) { /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Set Systick Interrupt to the highest priority */ HAL_NVIC_SetPriority(SysTick_IRQn, 0x0, 0x0); /* Init IO Expander */ BSP_IO_Init(); /* Enable IO Expander interrupt for ETH MII pin */ BSP_IO_ConfigPin(MII_INT_PIN, IO_MODE_IT_FALLING_EDGE); #ifdef USE_LCD /* Initialize the LCD */ BSP_LCD_Init(); /* Initialize the LCD Layers */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(1); BSP_LCD_SetFont(&LCD_DEFAULT_FONT); /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Ethernet IAP Application"); LCD_LOG_SetFooter((uint8_t *)"STM324x9I-EVAL board"); LCD_UsrLog (" State: Ethernet Initialization ...\n"); #endif }
/** * @brief Initializes the STM324xG-EVAL's LCD and LEDs resources. * @param None * @retval None */ static void BSP_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable PB14 to IT mode: Ethernet Link interrupt */ __HAL_RCC_GPIOB_CLK_ENABLE(); GPIO_InitStructure.Pin = GPIO_PIN_14; GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStructure.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable EXTI Line interrupt */ HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0x5, 0x0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Set Systick Interrupt to the highest priority */ HAL_NVIC_SetPriority(SysTick_IRQn, 0x0, 0x0); #ifdef USE_LCD /* Initialize the STM324xG-EVAL's LCD */ BSP_LCD_Init(); /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Ethernet IAP Application"); LCD_LOG_SetFooter((uint8_t *)"STM324xG-EVAL board"); LCD_UsrLog(" State: Ethernet Initialization ...\n"); #endif }
/** * @brief Initializes the STM32756G-EVAL's LCD and LEDs resources. * @param None * @retval None */ static void BSP_Config(void) { /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Init MFX */ BSP_IO_Init(); /* Enable MFX interrupt for ETH MII pin */ BSP_IO_ConfigPin(MII_INT_PIN, IO_MODE_IT_FALLING_EDGE); #ifdef USE_LCD /* Initialize the LCD */ BSP_LCD_Init(); /* Initialize the LCD Layers */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(1); BSP_LCD_SetFont(&LCD_DEFAULT_FONT); /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Webserver Application Socket API"); LCD_LOG_SetFooter((uint8_t *)"STM32756G-EVAL board"); LCD_UsrLog (" State: Ethernet Initialization ...\n"); #endif }
/** * @brief Initializes the LCD and LEDs resources. * @param None * @retval None */ static void BSP_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable PB14 to IT mode: Ethernet Link interrupt */ __GPIOB_CLK_ENABLE(); GPIO_InitStructure.Pin = GPIO_PIN_14; GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStructure.Pull = GPIO_NOPULL ; HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable EXTI Line interrupt */ HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0xF, 0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); /* Initialize LEDs */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); #ifdef USE_LCD /* Initialize the LCD */ BSP_LCD_Init(); BSP_LCD_SetFont(&LCD_DEFAULT_FONT); /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Webserver Application"); LCD_LOG_SetFooter((uint8_t *)"STM324xG-EVAL board"); LCD_UsrLog (" State: Ethernet Initialization ...\n"); #endif }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if (startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); STM32f4_Discovery_LCD_Init(); LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS MSC Host"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.1.0" ); } }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if(startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED1); // STM_EVAL_LEDInit(LED2); // STM_EVAL_LEDInit(LED3); // STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); #if defined (USE_STM322xG_EVAL) STM322xG_LCD_Init(); #elif defined(USE_STM324xG_EVAL) STM324xG_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #else #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)" #endif LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS MSC Host"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.1.0" ); } }
/** * @brief LCD Log demo * @param None * @retval None */ void Log_demo(void) { TS_ActionTypeDef ts_action = TS_ACT_NONE; uint8_t ts_status = TS_OK; uint8_t i = 0; /* Wait For User inputs */ while (CheckForUserInput() == 0); if (TouchScreen_IsCalibrationDone() == 0) { ts_status = Touchscreen_Calibration(); if(ts_status == TS_OK) { BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen calibration success.", CENTER_MODE); } else { BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"ERROR : touchscreen not yet calibrated.", CENTER_MODE); ts_status = TS_ERROR; } } /* of if (TouchScreen_IsCalibrationDone() == 0) */ /* Initialize LCD Log module */ LCD_LOG_Init(); /* Show Header and Footer texts */ LCD_LOG_SetHeader((uint8_t *)"Log Example"); LCD_LOG_SetFooter((uint8_t *)"Use touch up/down to scroll"); /* Output User logs */ for (i = 0; i < 10; i++) { LCD_UsrLog ("This is Line %d \n", i); } HAL_Delay(1000); /* Clear Old logs */ LCD_LOG_ClearTextZone(); /* Output new user logs */ for (i = 0; i < 30; i++) { LCD_UsrLog ("This is Line %d \n", i); } if(ts_status == TS_OK) { /* Set touchscreen in Interrupt mode and program EXTI accordingly on falling edge of TS_INT pin */ ts_status = BSP_TS_ITConfig(); BSP_TEST_APPLI_ASSERT(ts_status != TS_OK); Touchscreen_DrawBackground_Circle_Buttons(32); BSP_LCD_SetFont(&Font12); } /* Check for joystick user input for scroll (back and forward) */ while (1) { ts_action = (TS_ActionTypeDef) TouchScreen_GetTouchPosition(); switch (ts_action) { case TS_ACT_SCROLL_UP: LCD_LOG_ScrollBack(); break; case TS_ACT_SCROLL_DOWN: LCD_LOG_ScrollForward(); break; default: break; } if (CheckForUserInput() > 0) { return; } HAL_Delay (10); } }
int main(void) { char s[] = "1442936700,0,1,4,#2346W,3,#0800O#1900C#0900O#1800C"; // for str_processing test RCC_ClocksTypeDef RCC_Clocks; /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); /* Initialize the timer for dht11 */ tim_init(TIM2); /* Initialize the SRAM ****************************************************/ PSRAM_Init(); /* Initialize the LCD *****************************************************/ LCD_Init(); LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t*)" Ethernet test"); LCD_LOG_SetFooter ((uint8_t*)" localtime: "); /* Add your application code here */ /* Configure ethernet (GPIOs, clocks, MAC, DMA) */ ETH_BSP_Config(); /* Initilaize the LwIP stack */ LwIP_Init(); schedule_init(&schedule_got,schedule_string); // schedule string store in schedule_string DNS_Init(); //while(!schedule_got); // wait until string got LCD_DisplayStringLine(Line2, (uint8_t*)schedule_string); LCD_DisplayStringLine(Line3, (uint8_t*)"0"); /* Main Loop */ //process ste str form internet Str_Split(s, Init_time); // s is temp string RTC_Config(); Time_Date_Setting(Init_time->year, Init_time->mon, Init_time->day, Init_time->hour +3, Init_time->min, Init_time->sec); while (1) { uint8_t year, mon, day; uint8_t hour, min, sec; RTC_TimeTypeDef RTC_TimeStruct_main; RTC_DateTypeDef RTC_DateStruct_main; RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct_main); RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct_main); year = RTC_DateStruct_main.RTC_Year; mon = RTC_DateStruct_main.RTC_Month; day = RTC_DateStruct_main.RTC_Date; hour = RTC_TimeStruct_main.RTC_Hours; min = RTC_TimeStruct_main.RTC_Minutes; sec = RTC_TimeStruct_main.RTC_Seconds; //detect whether it is time to turn on Motor and LED, then execute it. Soak(day, hour, min ); Water(day, hour, min, sec); Light(mon, day, hour, min); //detect over /* check if any packet received */ if (ETH_CheckFrameReceived()) { /* process received ethernet packet */ LwIP_Pkt_Handle(); } /* handle periodic timers for LwIP */ LwIP_Periodic_Handle(LocalTime); } }
/** * @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 files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDOn(LED1); /* Initialize the LCD */ LCD_Init(); LCD_Clear(Black); LCD_SetTextColor(White); LCD_LOG_SetHeader((uint8_t*)"STM32 Camera Demo"); LCD_LOG_SetFooter ((uint8_t*)" Copyright (c) STMicroelectronics" ); /* ADC configuration */ ADC_Config(); /* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */ OV2640_HW_Init(); /* Read the OV9655/OV2640 Manufacturer identifier */ OV9655_ReadID(&OV9655_Camera_ID); OV2640_ReadID(&OV2640_Camera_ID); if(OV9655_Camera_ID.PID == 0x96) { Camera = OV9655_CAMERA; sprintf((char*)abuffer, "OV9655 Camera ID 0x%x", OV9655_Camera_ID.PID); ValueMax = 2; } else if(OV2640_Camera_ID.PIDH == 0x26) { Camera = OV2640_CAMERA; sprintf((char*)abuffer, "OV2640 Camera ID 0x%x", OV2640_Camera_ID.PIDH); ValueMax = 2; } else { LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LINE(4), (uint8_t*)"Check the Camera HW and try again"); while(1); } LCD_SetTextColor(LCD_COLOR_YELLOW); LCD_DisplayStringLine(LINE(4), (uint8_t*)abuffer); LCD_SetTextColor(LCD_COLOR_WHITE); Delay(200); /* Initialize demo */ ImageFormat = (ImageFormat_TypeDef)Demo_Init(); /* Configure the Camera module mounted on STM324xG-EVAL/STM324x7I-EVAL boards */ Demo_LCD_Clear(); LCD_DisplayStringLine(LINE(4), (uint8_t*)"Camera Init.. "); Camera_Config(); sprintf((char*)abuffer, " Image selected: %s", ImageForematArray[ImageFormat]); LCD_DisplayStringLine(LINE(4),(uint8_t*)abuffer); /* Enable DMA2 stream 1 and DCMI interface then start image capture */ DMA_Cmd(DMA2_Stream1, ENABLE); DCMI_Cmd(ENABLE); /* Insert 100ms delay: wait 100ms */ Delay(200); DCMI_CaptureCmd(ENABLE); LCD_ClearLine(LINE(4)); Demo_LCD_Clear(); if(ImageFormat == BMP_QQVGA) { /* LCD Display window */ LCD_SetDisplayWindow(179, 239, 120, 160); LCD_WriteReg(LCD_REG_3, 0x1038); LCD_WriteRAM_Prepare(); } else if(ImageFormat == BMP_QVGA) { /* LCD Display window */ LCD_SetDisplayWindow(239, 319, 240, 320); LCD_WriteReg(LCD_REG_3, 0x1038); LCD_WriteRAM_Prepare(); } while(1) { /* Blink LD1, LED2 and LED4 */ STM_EVAL_LEDToggle(LED1); STM_EVAL_LEDToggle(LED2); STM_EVAL_LEDToggle(LED3); STM_EVAL_LEDToggle(LED4); /* Insert 100ms delay */ Delay(10); /* Get the last ADC3 conversion result data */ uhADCVal = ADC_GetConversionValue(ADC3); /* Change the Brightness of camera using "Brightness Adjustment" register: For OV9655 camera Brightness can be positively (0x01 ~ 0x7F) and negatively (0x80 ~ 0xFF) adjusted For OV2640 camera Brightness can be positively (0x20 ~ 0x40) and negatively (0 ~ 0x20) adjusted */ if(Camera == OV9655_CAMERA) { OV9655_BrightnessConfig(uhADCVal); } if(Camera == OV2640_CAMERA) { OV2640_BrightnessConfig(uhADCVal/2); } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { //RCC_Config(); //GPIO_Config(); //RCC_MCO1Config(RCC_MCO1Source_PLLCLK,RCC_MCO1Div_1); uint8_t tmpreg; LIS302DL_InitTypeDef LIS302DL_InitStruct; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); //NVIC_SetPriority(SysTick_IRQn, -1); /* MEMS configuration and set int1/int2 pins*/ LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE; LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100; LIS302DL_InitStruct.Axes_Enable = LIS302DL_XYZ_ENABLE; LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3; LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL; LIS302DL_Init(&LIS302DL_InitStruct); //Set INT1/INT2 pins tmpreg = 0x40; LIS302DL_Write(&tmpreg, LIS302DL_CTRL_REG3_ADDR, 1); //Initialize the touchscreen TSC_Init(); /* Initialize LEDs and push-buttons mounted on STM324xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); //STM_EVAL_LEDInit(LED3); //STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ STM324xG_LCD_Init(); //STM_EVAL_LEDOn(LED1); LCD_Clear(Black); LCD_SetTextColor(White); LCD_LOG_SetHeader("STM32 Camera Demo"); LCD_LOG_SetFooter (" Copyright (c) STMicroelectronics" ); /* ADC configuration */ ADC_Config(); /* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */ //OV9655_HW_Init(); OV9712_HW_Init(); /* Read the OV9655/OV2640 Manufacturer identifier */ //OV9655_ReadID(&OV9655_Camera_ID); OV9712_ReadID(&OV9712_Camera_ID); //while(1); if(OV9655_Camera_ID.PID == 0x96) { Camera = OV9712_CAMERA; sprintf((char*)buffer, "OV9655 Camera ID 0x%x", OV9655_Camera_ID.PID); ValueMax = 2; } else if(OV9712_Camera_ID.PIDH == 0x97) { Camera = OV9712_CAMERA; sprintf((char*)buffer, "OV9712 Camera ID 0x%x", OV9712_Camera_ID.PIDH); ValueMax = 2; } else { LCD_SetTextColor(LCD_COLOR_RED); sprintf((char*)buffer, "OV Camera ID 0x%02x%02x", OV9655_Camera_ID.Version, OV9712_Camera_ID.PIDH); LCD_DisplayStringLine(LINE(4), buffer); while(1); } LCD_SetTextColor(LCD_COLOR_YELLOW); LCD_DisplayStringLine(LINE(4), (uint8_t*)buffer); LCD_SetTextColor(LCD_COLOR_WHITE); Delay(200); /* Initialize demo */ ImageFormat = (ImageFormat_TypeDef)BMP_QVGA; /* Configure the Camera module mounted on STM324xG-EVAL board */ Demo_LCD_Clear(); LCD_DisplayStringLine(LINE(4), "Camera Init.. "); Camera_Config(); sprintf((char*)buffer, " Image selected: %s", ImageForematArray[ImageFormat]); LCD_DisplayStringLine(LINE(4),(uint8_t*)buffer); LCD_ClearLine(LINE(4)); Demo_LCD_Clear(); if(ImageFormat == BMP_QQVGA) { /* LCD Display window */ LCD_SetDisplayWindow(60, 80, 160, 120); ReverseLCD(); LCD_WriteRAM_Prepare(); } else if(ImageFormat == BMP_QVGA) { /* LCD Display window */ LCD_SetDisplayWindow(0, 0, 320, 240); ReverseLCD(); LCD_WriteRAM_Prepare(); } { int i, j; for (j = 0; j < 16; j++) { LCD_SetDisplayWindow(0, (240 / 16) * j, 320, (240 / 16)); LCD_WriteRAM_Prepare(); for (i = 0; i < 320 * 240 / 16; i++) { LCD_WriteRAM(0x0003 << j); } } } /* Enable DMA2 stream 1 and DCMI interface then start image capture */ DMA_Cmd(DMA2_Stream1, ENABLE); DCMI_Cmd(ENABLE); /* Insert 100ms delay: wait 100ms */ //Delay(200); DCMI_CaptureCmd(ENABLE); while(1) { OV9655_BrightnessConfig(0x7F);// //static int step = 0; int i, block, begin; unsigned short *p; if (!bShot) { begin = (datablock - 11 + 48) % 48; for (block = begin; block < begin + 11; block++) { p = (unsigned short *)(0x20000000 + (320 * 240 * 2 / 16) * ((block) % 12)); LCD_SetDisplayWindow(0, (block % 16) * (240 / 16), 320, (240 / 16)); //LCD_SetCursor(0, (block % 16) * (240 / 16)); LCD_WriteRAM_Prepare(); for (i = 0; i < 320 * 240 / 16; i++) { LCD_WriteRAM(*p++); } } } if (TSC_TouchDet()) { int x, y; TP_GetAdXY(&x, &y); if (x > 300 && x < 2800 && y > 300 && y < 2800) { if (x < 1550 && y < 1550) { uint32_t StartSector = 0, EndSector = 0, Address = 0, SectorCounter = 0; int m; //拍照bShot bShot = 1; while(datablock % 16); DMA_Cmd(DMA2_Stream1, DISABLE); DCMI_Cmd(DISABLE); //STM_EVAL_LEDOn(LED2); DMA_ClearFlag(DMA2_Stream1, 0x2F7D0F7D); DMA_ClearFlag(DMA2_Stream1, 0x0F7D0F7D); DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1); datablock = 0; DMA2_Stream1->M0AR = 0x20000000 + 9600 * (datablock % 12); DMA_SetCurrDataCounter(DMA2_Stream1, (320 * 240 * 2 / 4) / 16); DCMI_Cmd(ENABLE); DMA_Cmd(DMA2_Stream1, ENABLE); { unsigned long *p, *q; while(datablock < 4); //等待准备好前4块数据,就将这4块数据导入到0x10000000+0x50000之后。 q = (unsigned long *)(0x20000000); p = (unsigned long *)(0x10000000 + 0x5000); while (q < (unsigned long *)(0x20000000 + 4 * (320 * 240 * 2 / 16))) { *p = *q; p++; q++; } } while(datablock < 16); //等待全部采集完成。 STM_EVAL_LEDOn(LED2); //LED2亮表示采集完成。 LCD_SetDisplayWindow(0, 0, 320, 240); LCD_WriteRAM_Prepare(); LCD_Clear(Black); //RAM位置 /* 序号 地址 大小 1: 0x10005000+9600*0 9600 2: 0x10005000+9600*1 9600 3: 0x10005000+9600*2 9600 4: 0x10005000+9600*3 9600 5: 0x20000000+9600*5 9600 6: 0x20000000+9600*6 9600 7: 0x20000000+9600*7 9600 8: 0x20000000+9600*8 9600 9: 0x20000000+9600*9 9600 10: 0x20000000+9600*10 9600 11: 0x20000000+9600*11 9600 12: 0x20000000+9600*0 9600 13: 0x20000000+9600*1 9600 14: 0x20000000+9600*2 9600 15: 0x20000000+9600*3 9600 */ for (m = 0; m < 16; m++) //显示保存的图片 { unsigned short *q; if (m < 4) { q = (unsigned short *)(0x10000000 + 0x5000 + m * (320 * 240 * 2 / 16)); } else { q = (unsigned short *)(0x20000000 + (m % 12) * (320 * 240 * 2 / 16)); } LCD_SetDisplayWindow(0, m * (240 / 16), 320, (240 / 16)); LCD_WriteRAM_Prepare(); for (i = 0; i < 320 * 240 / 16; i++) { LCD_WriteRAM(*q++); } } /* Erase the user Flash area ***********/ FLASH_Unlock(); /* Clear pending flags (if any) */ FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); /* Get the number of the start and end sectors */ StartSector = GetSector(FLASH_USER_START_ADDR); EndSector = GetSector(FLASH_USER_END_ADDR); for (SectorCounter = StartSector; SectorCounter < EndSector; SectorCounter += 8) { /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word */ if (FLASH_EraseSector(SectorCounter, VoltageRange_3) != FLASH_COMPLETE) { /* Error occurred while sector erase. User can add here some code to deal with this error */ while (1) { } } } for (m = 0; m < 16; m++) //保存图片到flash { unsigned long *q; Address = FLASH_USER_START_ADDR + m * (320 * 240 * 2 / 16); if (m < 4) { q = (unsigned long *)(0x10000000 + 0x5000 + m * (320 * 240 * 2 / 16)); } else { q = (unsigned long *)(0x20000000 + (m % 12) * (320 * 240 * 2 / 16)); } while (Address < FLASH_USER_START_ADDR + (m + 1) *(320 * 240 * 2 / 16)) { if (FLASH_ProgramWord(Address, *q) == FLASH_COMPLETE) { Address = Address + 4; q++; } else { /* Error occurred while writing data in Flash memory. User can add here some code to deal with this error */ while (1) { } } } } STM_EVAL_LEDOff(LED2); LCD_SetDisplayWindow(0, 0, 320, 240); LCD_WriteRAM_Prepare(); LCD_Clear(Black); for (m = 0; m < 16; m++) //显示flash中的图片 { unsigned short *q; q = (unsigned short *)(FLASH_USER_START_ADDR + m * (320 * 240 * 2 / 16)); LCD_SetDisplayWindow(0, m * (240 / 16), 320, (240 / 16)); LCD_WriteRAM_Prepare(); for (i = 0; i < 320 * 240 / 16; i++) { LCD_WriteRAM(*q++); } } /* Lock the Flash to disable the flash control register access (recommended to protect the FLASH memory against possible unwanted operation) *********/ FLASH_Lock(); } else if (x >= 1550 && y < 1550) { //righttop STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); bShot = 0; datablock = 0; DMA_Cmd(DMA2_Stream1, ENABLE); DCMI_Cmd(ENABLE); } else if (x < 1550 && y >= 1550) { //righttop //DMA_Cmd(DMA2_Stream1, ENABLE); //DCMI_Cmd(ENABLE); } else if (x >= 1550 && y >= 1550) { //righttop //DMA_Cmd(DMA2_Stream1, ENABLE); //DCMI_Cmd(ENABLE); } } } //Delay(10); } }