/** * @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 Audio application Init. * @param None * @retval None */ static void Audio_InitApplication(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /* Initialize the LCD */ BSP_LCD_Init(); /* LCD Layer Initialization */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Selects the LCD Layer */ BSP_LCD_SelectLayer(1); /* Enables the display */ BSP_LCD_DisplayOn(); /* Initialize the LCD Log module */ LCD_LOG_Init(); #ifdef USE_USB_HS LCD_LOG_SetHeader((uint8_t *)" USB OTG HS Audio Host"); #else LCD_LOG_SetHeader((uint8_t *)" USB OTG FS Audio Host"); #endif LCD_UsrLog("USB Host library started.\n"); /* Start Audio Interface */ USBH_UsrLog("Starting Audio Demo"); AUDIO_MenuInit(); /* Initialize the microSD */ if(SD_StorageInit() == 0) { SD_StorageParse(); } }
/** * @brief Explores Wav Files. * @param None * @retval Returns 0 if OK, otherwise 1. */ uint8_t MTP_ExploreWavFile(void) { uint8_t ret = 1; uint32_t index; MTP_ObjectInfoTypedef objectinfo; MTP_Init(); if(USBH_MTP_IsReady(&hUSBHost) > 0) { LCD_UsrLog("\nAvailable wav files:\n"); /* Get Available WAV files number */ if((NumObs = MTP_GetWavObjectNumber()) > 0) { /* Get objects handlers */ if(MTP_GetWavObjectHandles() == 0) { ret = 0; for (index = 0; index < NumObs; index ++) { if( USBH_MTP_GetObjectInfo (&hUSBHost, WavHandles.Handler[index], &objectinfo) == USBH_OK) { LCD_DbgLog(" %lu- %s\n", index, objectinfo.Filename); } else { ret = 1; } } } } } else { LCD_ErrLog("MTP Device Not yet ready...\n"); } return ret; }
int main(void) { extern uint32_t SystemCoreClock; //HAL init, etc common_init(); //System clock config (200 MHz) SystemClock_Config(); //LCD, SDRAM, DMA2D init. lcd_init(); LCD_LOG_Init(); LCD_LOG_SetHeader( ( uint8_t* )"LCD LOG" ); LCD_UsrLog( "LOG is ready\n" ); LCD_UsrLog( "MCU runs at %lu MHz\n", SystemCoreClock / 1000000 ); LCD_UsrLog( "Define threads\n" ); //Init on BTN pressed if( BSP_PB_GetState( BUTTON_KEY ) ) { //KEY pressed LCD_UsrLog( "AF\n" ); LCD_UsrLog( "Done!\n" ); while(1) { //Do nothing } } else { //Normal mode } LCD_UsrLog( "Create threads\n" ); tasks_init(); LCD_UsrLog( "Starting OS kernel...\n" ); osKernelStart(); return 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 Audio Application Init. * @param None * @retval None */ static void AUDIO_InitApplication(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure the LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Initialize the LCD */ BSP_LCD_Init(); /* LCD Layer Initialization */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Select the LCD Layer */ BSP_LCD_SelectLayer(1); /* Enable the display */ BSP_LCD_DisplayOn(); /* Init the LCD Log module */ LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t *)"Audio Playback and Record Application"); LCD_UsrLog("USB Host library started.\n"); /* Start Audio interface */ USBH_UsrLog("Starting Audio Demo"); /* Init Audio interface */ AUDIO_PLAYER_Init(); /* Start Audio interface */ AUDIO_MenuInit(); }
/** * @brief MSC application Init. * @param None * @retval None */ static void MSC_InitApplication(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Initialize the LCD */ BSP_LCD_Init(); /* LCD Layer Initialization */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Selects the LCD Layer */ BSP_LCD_SelectLayer(1); /* Enables the display */ BSP_LCD_DisplayOn(); /* Init the LCD Log module */ LCD_LOG_Init(); #ifdef USE_USB_HS LCD_LOG_SetHeader((uint8_t *)" USB OTG HS MSC Host"); #else LCD_LOG_SetHeader((uint8_t *)" USB OTG FS MSC Host"); #endif LCD_UsrLog("USB Host library started.\n"); /* Start MSC Interface */ USBH_UsrLog("Starting MSC Demo"); Menu_Init(); }
/** * @brief Processes TFTP write request * @param to: pointer on the receive IP address * @param to_port: receive port number * @retval None */ static int IAP_tftp_process_write(struct udp_pcb *upcb, struct ip_addr *to, int to_port) { tftp_connection_args *args = NULL; /* This function is called from a callback, * therefore interrupts are disabled, * therefore we can use regular malloc */ args = mem_malloc(sizeof *args); if (!args) { #ifdef USE_LCD LCD_ErrLog("Memory error \n"); #endif IAP_tftp_cleanup_wr(upcb, args); return 0; } args->op = TFTP_WRQ; args->to_ip.addr = to->addr; args->to_port = to_port; /* the block # used as a positive response to a WRQ is _always_ 0!!! (see RFC1350) */ args->block = 0; args->tot_bytes = 0; /* set callback for receives on this UDP PCB (Protocol Control Block) */ udp_recv(upcb, IAP_wrq_recv_callback, args); total_count =0; /* init flash */ FLASH_If_Init(); /* erase user flash area */ FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS); Flash_Write_Address = USER_FLASH_FIRST_PAGE_ADDRESS; /* initiate the write transaction by sending the first ack */ IAP_tftp_send_ack_packet(upcb, to, to_port, args->block); #ifdef USE_LCD LCD_UsrLog(" State: Programming... \n"); #endif return 0; }
/** * @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 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; /* 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" ); */ LCD_UsrLog("> USB Host library started.\n"); } }
/** * @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 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 AUDIO Device"); #else LCD_LOG_SetHeader(" USB OTG FS AUDIO 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 - 48, USER_INFORMATION1); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); /* Information panel */ LCD_SetTextColor(Green); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 32, USER_INFORMATION2); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); }
/** * @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 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 Audio application Init. * @param None * @retval None */ static void Audio_InitApplication(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Initialize the LCD */ BSP_LCD_Init(); /* Initialize the LCD Log module */ LCD_LOG_Init(); #ifdef USE_USB_HS LCD_LOG_SetHeader((uint8_t *)" USB OTG HS Audio Host"); #else LCD_LOG_SetHeader((uint8_t *)" USB OTG FS Audio Host"); #endif LCD_UsrLog("USB Host library started.\n"); /* Start Audio Interface */ USBH_UsrLog("Starting Audio Demo"); AUDIO_MenuInit(); /* Initialize the microSD */ if(SD_StorageInit() == 0) { SD_StorageParse(); } }
/** * @brief MTP application Init. * @param None * @retval None */ static void MTP_InitApplication(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Initialize the LCD */ BSP_LCD_Init(); /* Init the LCD Log module */ LCD_LOG_Init(); #ifdef USE_USB_HS LCD_LOG_SetHeader((uint8_t *)" USB OTG HS MTP Host"); #else LCD_LOG_SetHeader((uint8_t *)" USB OTG FS MTP Host"); #endif LCD_UsrLog("USB Host library started.\n"); /* Start MTP Interface */ USBH_UsrLog("Starting MTP Demo"); /* Init Audio interface */ AUDIO_Init(); /* Start MTP Interface */ MTP_MenuInit(); }
/** * @brief DUALCORE application Init. * @param None * @retval None */ static void DUAL_InitApplication(void) { /* Configure KEY Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure the LEDs */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Initialize the LCD */ BSP_LCD_Init(); /* LCD Layer Initialisation */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /*Selects the LCD Layer*/ BSP_LCD_SelectLayer(1); /*Enables the display*/ BSP_LCD_DisplayOn(); /*Init the LCD Log module*/ LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t *)" USB OTG DualCore Host"); LCD_UsrLog("USB Host library started.\n"); /* Start DualCore Interface */ USBH_UsrLog("Initializing hardware...."); DUAL_MenuInit(); }
/** * @brief HID application Init. * @param None * @retval None */ static void HID_InitApplication(void) { /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /* Initialize the LCD */ BSP_LCD_Init(); /* LCD Layer Initialization */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Select the LCD Layer */ BSP_LCD_SelectLayer(1); /* Enable the display */ BSP_LCD_DisplayOn(); /* Initialize the LCD Log module */ LCD_LOG_Init(); #ifdef USE_USB_HS LCD_LOG_SetHeader((uint8_t *)" USB OTG HS HID Host"); #else LCD_LOG_SetHeader((uint8_t *)" USB OTG FS HID Host"); #endif LCD_UsrLog("USB Host library started.\n"); /* Start HID Interface */ USBH_UsrLog("Starting HID Demo"); HID_MenuInit(); }
/** * @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 USBD_USR_DeviceResumed * Displays the message on LCD on device resume Event * @param None * @retval None */ void USBD_USR_DeviceResumed(void) { LCD_UsrLog("> USB Device in Idle Mode.\n"); /* Users can do their application actions here for the USB-Reset */ }
/** * @brief Displays disk content. * @param path: Pointer to root path * @param recu_level: Disk content level * @retval Operation result */ FRESULT Explore_Disk(char *path, uint8_t recu_level) { FRESULT res = FR_OK; FILINFO fno; DIR dir; char *fn; char tmp[14]; uint8_t line_idx = 0; #if _USE_LFN static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ fno.lfname = lfn; fno.lfsize = sizeof lfn; #endif res = f_opendir(&dir, path); if(res == FR_OK) { while(USBH_MSC_IsReady(&hUSBHost)) { res = f_readdir(&dir, &fno); if(res != FR_OK || fno.fname[0] == 0) { break; } if(fno.fname[0] == '.') { continue; } #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif strcpy(tmp, fn); line_idx++; if(line_idx > 9) { line_idx = 0; LCD_UsrLog("> Press [Key] To Continue.\n"); /* KEY Button in polling */ while(BSP_PB_GetState(BUTTON_KEY) != RESET) { /* Wait for User Input */ } } if(recu_level == 1) { LCD_DbgLog(" |__"); } else if(recu_level == 2) { LCD_DbgLog(" | |__"); } if((fno.fattrib & AM_MASK) == AM_DIR) { strcat(tmp, "\n"); LCD_UsrLog((void *)tmp); Explore_Disk(fn, 2); } else { strcat(tmp, "\n"); LCD_DbgLog((void *)tmp); } if(((fno.fattrib & AM_MASK) == AM_DIR)&&(recu_level == 2)) { Explore_Disk(fn, 2); } } f_closedir(&dir); LCD_UsrLog("> Select an operation to Continue.\n" ); } return res; }
/** * @brief Processes traffic received on UDP port 69 * @param args: pointer on tftp_connection arguments * @param upcb: pointer on udp_pcb structure * @param pbuf: pointer on packet buffer * @param addr: pointer on the receive IP address * @param port: receive port number * @retval None */ static void IAP_tftp_recv_callback(void *arg, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_opcode op; struct udp_pcb *upcb_tftp_data; err_t err; #ifdef USE_LCD uint32_t i; char filename[40],message[40], *ptr; #endif /* create new UDP PCB structure */ upcb_tftp_data = udp_new(); if (!upcb_tftp_data) { /* Error creating PCB. Out of Memory */ #ifdef USE_LCD LCD_ErrLog("Can not create pcb \n"); #endif return; } /* bind to port 0 to receive next available free port */ /* NOTE: This is how TFTP works. There is a UDP PCB for the standard port * 69 which al transactions begin communication on, however, _all_ subsequent * transactions for a given "stream" occur on another port */ err = udp_bind(upcb_tftp_data, IP_ADDR_ANY, 0); if (err != ERR_OK) { /* Unable to bind to port */ #ifdef USE_LCD LCD_ErrLog("Can not create pcb \n"); #endif return; } op = IAP_tftp_decode_op(pkt_buf->payload); if (op != TFTP_WRQ) { /* remove PCB */ #ifdef USE_LCD LCD_ErrLog("Bad TFTP opcode \n"); #endif udp_remove(upcb_tftp_data); } else { #ifdef USE_LCD ptr = pkt_buf->payload; ptr = ptr +2; /*extract file name info */ i= 0; while (*(ptr+i)!=0x0) { i++; } strncpy(filename, ptr, i+1); LCD_UsrLog("IAP using TFTP \n"); sprintf(message, "File: %s",filename); LCD_UsrLog("%s\n", message); LCD_UsrLog(" State: Erasing...\n"); #endif /* Start the TFTP write mode*/ IAP_tftp_process_write(upcb_tftp_data, addr, port); } pbuf_free(pkt_buf); }
/** * @brief Processes data transfers after a TFTP write request * @param _args: used as pointer on TFTP connection args * @param upcb: pointer on udp_pcb structure * @param pkt_buf: pointer on a pbuf stucture * @param ip_addr: pointer on the receive IP_address structure * @param port: receive port address * @retval None */ static void IAP_wrq_recv_callback(void *_args, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_connection_args *args = (tftp_connection_args *)_args; uint32_t data_buffer[128]; uint16_t count=0; #ifdef USE_LCD char message[40]; #endif if (pkt_buf->len != pkt_buf->tot_len) { #ifdef USE_LCD LCD_ErrLog("Invalid data length\n"); #endif return; } /* Does this packet have any valid data to write? */ if ((pkt_buf->len > TFTP_DATA_PKT_HDR_LEN) && (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1))) { /* copy packet payload to data_buffer */ pbuf_copy_partial(pkt_buf, data_buffer, pkt_buf->len - TFTP_DATA_PKT_HDR_LEN, TFTP_DATA_PKT_HDR_LEN); total_count += pkt_buf->len - TFTP_DATA_PKT_HDR_LEN; count = (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)/4; if (((pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)%4)!=0) count++; /* Write received data in Flash */ FLASH_If_Write(&Flash_Write_Address, data_buffer ,count); /* update our block number to match the block number just received */ args->block++; /* update total bytes */ (args->tot_bytes) += (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN); /* This is a valid pkt but it has no data. This would occur if the file being written is an exact multiple of 512 bytes. In this case, the args->block value must still be updated, but we can skip everything else. */ } else if (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1)) { /* update our block number to match the block number just received */ args->block++; } /* Send the appropriate ACK pkt*/ IAP_tftp_send_ack_packet(upcb, addr, port, args->block); /* If the last write returned less than the maximum TFTP data pkt length, * then we've received the whole file and so we can quit (this is how TFTP * signals the EndTransferof a transfer!) */ if (pkt_buf->len < TFTP_DATA_PKT_LEN_MAX) { IAP_tftp_cleanup_wr(upcb, args); pbuf_free(pkt_buf); #ifdef USE_LCD sprintf(message, "%d bytes ",(int)total_count); LCD_UsrLog("Tot bytes Received:, %s\n", message); LCD_UsrLog(" State: Prog Finished \n"); LCD_UsrLog("Reset the board \n"); #endif } else { pbuf_free(pkt_buf); return; } }
/** * @brief Files operations: Read/Write and compare * @param None * @retval none */ void MSC_File_Operations(void) { uint16_t bytesread; /* Register the file system object to the FatFs module */ if(f_mount(&USBH_fatfs, "", 0 ) != FR_OK ) { LCD_ErrLog("Cannot Initialize FatFs! \n"); } else { LCD_UsrLog ("INFO : FatFs Initialized \n"); if(f_open(&MyFile, "0:USBHost.txt",FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { LCD_ErrLog("Cannot Open 'USBHost.txt' file \n"); } else { LCD_UsrLog ("INFO : 'USBHost.txt' opened for write \n"); res= f_write (&MyFile, wtext, sizeof(wtext), (void *)&bytesWritten); f_close(&MyFile); if((bytesWritten == 0) || (res != FR_OK)) /*EOF or Error*/ { LCD_ErrLog("Cannot Write on the 'USBHost.txt' file \n"); } else { if(f_open(&MyFile, "0:USBHost.txt", FA_READ) != FR_OK) { LCD_ErrLog("Cannot Open 'USBHost.txt' file for read.\n"); } else { LCD_UsrLog ("INFO : Text written on the 'USBHost.txt' file \n"); res = f_read(&MyFile, rtext, sizeof(rtext), (void *)&bytesread); if((bytesread == 0) || (res != FR_OK)) /*EOF or Error*/ { LCD_ErrLog("Cannot Read from the 'USBHost.txt' file \n"); } else { LCD_UsrLog("Read Text : \n"); LCD_DbgLog((char *)rtext); LCD_DbgLog("\n"); } f_close(&MyFile); } /* Compare read data with the expected data */ if((bytesread == bytesWritten)) { LCD_UsrLog ("INFO : FatFs data compare SUCCES"); LCD_UsrLog("\n"); } else { LCD_ErrLog("FatFs data compare ERROR"); LCD_ErrLog("\n"); } } } } }
/** * @brief Displays disk content * @param path: pointer to root path * @param recu_level: explorer level * @retval None */ static uint8_t Explore_Disk(char* path , uint8_t recu_level) { FRESULT res; FILINFO fno; DIR dir; char *fn; char tmp[14]; res = f_opendir(&dir, path); if (res == FR_OK) { /* USER Button in polling */ LCD_UsrLog("To see the disk root content:\n" ); LCD_UsrLog("Press Key...\n"); while((BSP_PB_GetState (BUTTON_KEY) != SET)) { Toggle_Leds(); } while((BSP_PB_GetState (BUTTON_KEY) != RESET)) { Toggle_Leds(); } while(Appli_state == APPLICATION_START) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) { break; } if (fno.fname[0] == '.') { continue; } fn = fno.fname; strcpy(tmp, fn); line_idx++; if(line_idx > 12) { line_idx = 0; LCD_UsrLog("Press Key to continue...\n"); /* USER Button in polling */ while((Appli_state == APPLICATION_START) && \ (BSP_PB_GetState (BUTTON_KEY) != SET)) { Toggle_Leds(); } } if(recu_level == 1) { LCD_DbgLog(" |__"); } else if(recu_level == 2) { LCD_DbgLog(" | |__"); } if((fno.fattrib & AM_MASK) == AM_DIR) { strcat(tmp, "\n"); LCD_UsrLog((void *)tmp); } else { strcat(tmp, "\n"); LCD_DbgLog((void *)tmp); } if(((fno.fattrib & AM_MASK) == AM_DIR)&&(recu_level == 1)) { Explore_Disk(fn, 2); } } } f_closedir(&dir); return res; }
/** * @brief Explore_Disk * Displays disk content * @param path: pointer to root path * @retval None */ static uint8_t Explore_Disk (char* path , uint8_t recu_level) { FRESULT res; FILINFO fno; DIR dir; char *fn; char tmp[14]; res = f_opendir(&dir, path); if (res == FR_OK) { while(HCD_IsDeviceConnected(&USB_OTG_Core)) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) { break; } if (fno.fname[0] == '.') { continue; } fn = fno.fname; strcpy(tmp, fn); line_idx++; if (line_idx > 9) { line_idx = 0; LCD_SetTextColor(Green); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, " "); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, "Press Key to continue..."); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); /*Key B3 in polling*/ while((HCD_IsDeviceConnected(&USB_OTG_Core)) && \ (STM_EVAL_PBGetState (BUTTON_USER) == RESET)) { Toggle_Leds(); } } if (recu_level == 1) { LCD_DbgLog(" |__"); } else if(recu_level == 2) { LCD_DbgLog(" | |__"); } if ((fno.fattrib & AM_MASK) == AM_DIR) { strcat(tmp, "\n"); LCD_UsrLog((void *)tmp); } else { strcat(tmp, "\n"); LCD_DbgLog((void *)tmp); } if (((fno.fattrib & AM_MASK) == AM_DIR)&&(recu_level == 1)) { Explore_Disk(fn, 2); } } } return res; }
/** * @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 Configure the RTC peripheral by selecting the clock source. * @param None * @retval None */ void RTC_Config(void) { /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/ /* The RTC Clock may varies due to LSI frequency dispersion. */ /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); SynchPrediv = 0xFF; AsynchPrediv = 0x7F; #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */ /* Enable the LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); SynchPrediv = 0xFF; AsynchPrediv = 0x7F; #else #error Please select the RTC Clock source inside the main.c file #endif /* RTC_CLOCK_SOURCE_LSI */ /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Write to the first RTC Backup Data Register */ RTC_WriteBackupRegister(RTC_BKP_DR0, FIRST_DATA); /* Display the new RCC BDCR and RTC TAFCR Registers */ LCD_UsrLog ("RTC Reconfig \n"); LCD_UsrLog ("RCC BDCR = 0x%x\n", RCC->BDCR); LCD_UsrLog ("RTC TAFCR = 0x%x\n", RTC->TAFCR); /* Set the Time */ RTC_TimeStructure.RTC_Hours = 0x08; RTC_TimeStructure.RTC_Minutes = 0x00; RTC_TimeStructure.RTC_Seconds = 0x00; /* Set the Date */ RTC_DateStructure.RTC_Month = RTC_Month_March; RTC_DateStructure.RTC_Date = 0x18; RTC_DateStructure.RTC_Year = 0x11; RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Friday; /* Calendar Configuration */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); /* Set Current Time and Date */ RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure); /* Configure the RTC Wakeup Clock source and Counter (Wakeup event each 1 second) */ RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16); RTC_SetWakeUpCounter(0x7FF); /* Enable the Wakeup Interrupt */ RTC_ITConfig(RTC_IT_WUT, ENABLE); /* Enable Wakeup Counter */ RTC_WakeUpCmd(ENABLE); /* Backup SRAM ***************************************************************/ /* Enable BKPRAM Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE); /* Write to Backup SRAM with 32-Bit Data */ for (i = 0x0; i < 0x1000; i += 4) { *(__IO uint32_t *) (BKPSRAM_BASE + i) = i; } /* Check the written Data */ for (i = 0x0; i < 0x1000; i += 4) { if ((*(__IO uint32_t *) (BKPSRAM_BASE + i)) != i) { errorindex++; } } if(errorindex) { LCD_ErrLog ("BKP SRAM Number of errors = %d\n", errorindex); } else { LCD_UsrLog ("BKP SRAM write OK \n"); } /* Enable the Backup SRAM low power Regulator to retain it's content in VBAT mode */ PWR_BackupRegulatorCmd(ENABLE); /* Wait until the Backup SRAM low power Regulator is ready */ while(PWR_GetFlagStatus(PWR_FLAG_BRR) == RESET) { } /* RTC Backup Data Registers **************************************************/ /* Write to RTC Backup Data Registers */ WriteToBackupReg(FIRST_DATA); }
/** * @brief DHCP_Process_Handle * @param None * @retval None */ void DHCP_Process(struct netif *netif) { struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; uint32_t IPaddress = 0; switch (DHCP_state) { case DHCP_START: { netif->ip_addr.addr = 0; netif->netmask.addr = 0; netif->gw.addr = 0; IPaddress = 0; DHCP_state = DHCP_WAIT_ADDRESS; dhcp_start(netif); #ifdef USE_LCD LCD_UsrLog (" State: Looking for DHCP sever ...\n"); #endif } break; case DHCP_WAIT_ADDRESS: { /* Read the new IP address */ IPaddress = netif->ip_addr.addr; if (IPaddress !=0) { DHCP_state = DHCP_ADDRESS_ASSIGNED; /* Stop DHCP */ dhcp_stop(netif); #ifdef USE_LCD uint8_t iptab[4]; uint8_t iptxt[20]; iptab[0] = (uint8_t)(IPaddress >> 24); iptab[1] = (uint8_t)(IPaddress >> 16); iptab[2] = (uint8_t)(IPaddress >> 8); iptab[3] = (uint8_t)(IPaddress); sprintf((char*)iptxt, "%d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); LCD_UsrLog ("IP address assigned by a DHCP server: %s\n", iptxt); #else BSP_LED_On(LED1); #endif } else { /* DHCP timeout */ if (netif->dhcp->tries > MAX_DHCP_TRIES) { DHCP_state = DHCP_TIMEOUT; /* Stop DHCP */ dhcp_stop(netif); /* Static address used */ IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 ); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(netif, &ipaddr , &netmask, &gw); #ifdef USE_LCD uint8_t iptxt[20]; sprintf((char*)iptxt, "%d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); LCD_UsrLog ("DHCP timeout !!\n"); LCD_UsrLog ("Static IP address : %s\n", iptxt); #else BSP_LED_On(LED1); #endif } } }
/** * @brief USBD_USR_DeviceDisonnected * Displays the message on LCD on device disconnection Event * @param None * @retval Staus */ void USBD_USR_DeviceDisconnected (void) { LCD_UsrLog("> USB Device Disconnected.\n"); }