Example #1
0
/**
  * @brief  Storage drives initialization
  * @param  None 
  * @retval None
  */
void k_StorageInit(void)
{
  /* Link the USB Host disk I/O driver */
   FATFS_LinkDriver(&USBH_Driver, USBDISK_Drive);
  
  /* Link the micro SD disk I/O driver */
   FATFS_LinkDriver(&SD_Driver, mSDDISK_Drive);  

  /* Create USB background task */
  osThreadDef(STORAGE_Thread, StorageThread, osPriorityBelowNormal, 0, 2 * configMINIMAL_STACK_SIZE);
  osThreadCreate (osThread(STORAGE_Thread), NULL);
  
  /* Create Storage Message Queue */
  osMessageQDef(osqueue, 10, uint16_t);
  StorageEvent = osMessageCreate (osMessageQ(osqueue), NULL);
  
  /* Init Host Library */
  USBH_Init(&hUSB_Host, USBH_UserProcess, 0);
  
  /* Add Supported Class */
  USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
  
  /* Start Host Process */
  USBH_Start(&hUSB_Host);
  
  /* Enable SD Interrupt mode */
  BSP_SD_Init();
  BSP_SD_ITConfig();
  
  if(BSP_SD_IsDetected())
  {
    osMessagePut ( StorageEvent, MSDDISK_CONNECTION_EVENT, 0);
  }
}
Example #2
0
/**
  * @brief  SD Card Configuration.
  * @param  None
  * @retval None
  */
static void SDCard_Config(void)
{
  uint32_t counter = 0;
  
  if(FATFS_LinkDriver(&SD_Driver, SD_Path) == 0)
  {
    /* Initialize the SD mounted on adafruit 1.8" TFT shield */
    if(BSP_SD_Init() != MSD_OK)
    {
      TFT_DisplayErrorMessage(BSP_SD_INIT_FAILED);
    }  
    
    /* Check the mounted device */
    if(f_mount(&SD_FatFs, (TCHAR const*)"/", 0) != FR_OK)
    {
      TFT_DisplayErrorMessage(FATFS_NOT_MOUNTED);
    }  
    else
    {
      /* Initialize the Directory Files pointers (heap) */
      for (counter = 0; counter < MAX_BMP_FILES; counter++)
      {
        pDirectoryFiles[counter] = malloc(11); 
      }
    }
  }
}
Example #3
0
void MX_FATFS_Init(void) 
{
  /*## FatFS: Link the SD driver ###########################*/
  retSD = FATFS_LinkDriver(&SD_Driver, SD_Path);

  /* USER CODE BEGIN Init */
  /* additional user code for init */     
  if(!retSD)
  {
	  if(f_mount(&SDFatFS, (TCHAR const*)SD_Path, 0) != FR_OK)
		  strToUART("mount failure\n");
	  else
	  {
		  strToUART("mount success\n");
		  if(f_open(&hello, "hello.txt", FA_READ) == FR_OK)
		  {
			  strToUART("opened hello.txt\n");
			  volatile char * str;
			  //int readcount;
			  TCHAR * buffer[10];
			  str = f_gets((char*)buffer, hello.fsize, &hello);
			  strToUART(str);
			  f_close(&hello);
		  }
		  else	strToUART("could not open hello.txt\n");

	  }
  }
  /* USER CODE END Init */
}
Example #4
0
/**
  * @brief  Initializes the SD Storage.
  * @param  None
  * @retval Status
  */
uint8_t SD_StorageInit(void)
{
  /*Initializes the SD card device*/
  BSP_SD_Init();
  
  /* Check if the SD card is plugged in the slot */
  if(BSP_SD_IsDetected() == SD_PRESENT )
  {
    /* Link the SD Card disk I/O driver */
    if(FATFS_LinkDriver(&SD_Driver, SD_Path) == 0)
    {
      if((f_mount(&SD_FatFs, (TCHAR const*)SD_Path, 0) != FR_OK))
      {
        /* FatFs Initialization Error */
        LCD_ErrLog("Cannot Initialize FatFs! \n");
        return 1;
      }
      else
      {
        LCD_DbgLog ("INFO : FatFs Initialized! \n");
      }
    }  
  }
  else
  {
    LCD_ErrLog("SD card NOT plugged \n");
    return 1;
  }
  return 0;
}
Example #5
0
void startup_task (void *pvParameters)
{

   (void) pvParameters;
   MX_GPIO_Init();

   /* Init Device Library */
   USBD_Init(&hUsbDeviceFS, &VCP_Desc, 0);
   /* Add Supported Class */
   USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC);
   /* Add CDC Interface Class */
   USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
   /* Start Device Process */
   USBD_Start(&hUsbDeviceFS);

   xdev_out(putchar);


   MX_SDIO_SD_Init();
   FATFS_LinkDriver(&SD_Driver, SD_Path);
   fsInit();


   vTaskDelete(NULL);
}
Example #6
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /*Initialize the IO module*/
  BSP_IO_Init ();
  
  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);  
  
  /*##-1- Link the USB Host disk I/O driver ##################################*/
  if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
  {
    /*##-2- Init Host Library ################################################*/
    USBH_Init(&hUSB_Host, USBH_UserProcess, 0);
    
    /*##-3- Add Supported Class ##############################################*/
    USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
    
    /*##-4- Start Host Process ###############################################*/
    USBH_Start(&hUSB_Host);
    
    /*##-5- Run Application (Blocking mode) ##################################*/
    while (1)
    {
      /* USB Host Background task */
      USBH_Process(&hUSB_Host);
      
      /* Mass Storage Application State Machine */
      switch(Appli_state)
      {
      case APPLICATION_START:
        MSC_Application();
        Appli_state = APPLICATION_IDLE;
        break;
         
      case APPLICATION_IDLE:
      default:
        break;      
      }
    }
  }

  /* Infinite loop */
  while (1)
  {
  }
    
}
Example #7
0
void MX_FATFS_Init() {
    /*## FatFS: Link the SD driver ###########################*/
    retSD = FATFS_LinkDriver(&SD_Driver, SD_Path);

    /* USER CODE BEGIN Init */
    /* additional user code for init */
    /* USER CODE END Init */
}
Example #8
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 168 MHz */
  SystemClock_Config(); 
    
  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /*##-1- LCD Initialization #################################################*/ 
  /* Initialize the LCD */
  BSP_LCD_Init();
 
  /* Enable the LCD */
  BSP_LCD_DisplayOn();

  /* Clear the LCD Background layer */
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /*##-2- Touch screen initialization ########################################*/
  Touchscreen_Calibration();
  BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
 
  /*##-3- Link the SD Card disk I/O driver ###################################*/
  if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0) 
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }
  
  /* Create a FAT file system (format) on the logical drive */
  f_mkfs((TCHAR const*)SDPath, 0, 0);
  
  /*##-4- Register the file system object to the FatFs module ################*/
  if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }  
  
  /*##-5- Draw the menu ######################################################*/
  Draw_Menu();  

  /* Infinite loop */  
  while (1)
  { 
  /*##-6- Configure the touch screen and Get the position ####################*/    
    GetPosition();
  }
}
Example #9
0
void MX_FATFS_Init(void) 
{
  /*## FatFS: Link the USER driver ###########################*/
  retUSER = FATFS_LinkDriver(&USER_Driver, USER_Path);

  /* USER CODE BEGIN Init */
  /* additional user code for init */     
  /* USER CODE END Init */
}
extern void application_init(void)
{
  /*##-1- Link the USB Host disk I/O driver ##################################*/
  if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) != 0)
  {
    Error_Handler();
  }
  
  TickTock_Init();
}
Example #11
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{  
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /* Configure LED3 and LED4 */
  BSP_LED_Init(LED3); 
  BSP_LED_Init(LED4); 
  
  /* Configure USER Button */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /* Initialize LCD driver */
  LCD_Config();
  
  /* Link the USB Host disk I/O driver */
  USBDISK_Driver_Num = FATFS_LinkDriver(&USBH_Driver, "");
  
  /* Init Host Library */
  if (USBH_Init(&hUSB_Host, USBH_UserProcess, 0) != USBH_OK)
  {
    /* USB Initialization Error */
    Error_Handler();
  }

  /* Add Supported Class */
  USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
  
  /* Start Host Process */
  if (USBH_Start(&hUSB_Host) != USBH_OK)
  {
    /* USB Initialization Error */
    Error_Handler();
  }

  /* Infinite loop */
  while (1)
  {
    if (Appli_state == APPLICATION_START)
    {
      MSC_Application();
    }
    Toggle_Leds();
    USBH_Process(&hUSB_Host);
  }
}
Example #12
0
uint8_t MX_FATFS_Init(void) 
{
	uint8_t retSD = true;    /* Return value for SD */
	MX_SDIO_SD_Init();
	
    /*## FatFS: Link the SD driver ###########################*/
    retSD = FATFS_LinkDriver(&SD_Driver, SDPath);
	if(retSD != 0)
	{
		printf("FatFs Link Driver Err\r\n");
        retSD = false;
	}
    else
    {
        retSD = true;
    }
    
    store_manage_init();
//    
//    /*##-1- Register the file system object to the FatFs module ##############*/
//    if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
//    {
//        #ifdef Debug_FatFs_Driver
//            /* FatFs Initialization Error */
//            printf("f_mount Err in fatfs_shell\r\n"); 
//        #endif
//        retSD = false;
//        /*##-2- Create a FAT file system (format) on the logical drive #########*/
//        /* WARNING: Formatting the uSD card will delete all content on the device */
//        if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
//        {
//            /* FatFs Format Error */
//            #ifdef Debug_FatFs_Driver
//                printf("FatFs Format Err in fatfs_shell\r\n");
//            #endif
//            retSD = false;
//        }
//        #ifdef Debug_FatFs_Driver
//        else
//        {
//            printf("FatFs Format OK\r\n");
//        }
//        #endif
//    }
//    #ifdef Debug_FatFs_Driver
//    else
//    {
//        printf("Register FS OK\r\n");
//    }
//    #endif
    
    return retSD;
}
Example #13
0
void MX_FATFS_Init(void) 
{
  /*## FatFS: Link the USER driver ###########################*/
  retUSER = FATFS_LinkDriver(&USER_Driver, USER_Path);

  /* USER CODE BEGIN Init */
  /* additional user code for init */
	HAL_Error_Handler(f_mount(&mynewdiskFatFs, USER_Path, 0));
	printf("drive number:%d path:%s successfully mounted\r\n",retUSER,USER_Path);
	MX_FATFS_Speedtest();
  /* USER CODE END Init */
}
boolean_t LBF_FatFS_Init (void)
{

boolean_t Success = TRUE;

    Success &= (FATFS_LinkDriver(&DataFlash_DISK_Driver, DataFlash_DISK_Path) == 0);
    if (Success)
    {
       Success &= (f_mount(&DataFlash_DISK_FatFs, (TCHAR const*)DataFlash_DISK_Path, 0) == FR_OK);
    }
    return Success;

}
Example #15
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
void FDrive_Init(void)
{
    if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == FR_OK) 
    {
        USBH_StatusTypeDef res = USBH_Init(&handleUSBH, USBH_UserProcess, 0);
        res = USBH_RegisterClass(&handleUSBH, USBH_MSC_CLASS);
        res = USBH_Start(&handleUSBH);
    }
    else
    {
        // —юда попадаем, если usbh driver не удалось инициализировать
    }
}
Example #16
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
void FDrive_Init(void)
{
    if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == FR_OK) 
    {
        USBH_StatusTypeDef res = USBH_Init(&handleUSBH, USBH_UserProcess, 0);
        res = USBH_RegisterClass(&handleUSBH, USBH_MSC_CLASS);
        res = USBH_Start(&handleUSBH);
    }
    else
    {
        LOG_ERROR("Can not %s", __FUNCTION__);
    }
}
Example #17
0
void SD_Init(void){	
	FRESULT res;                                          /* FatFs function common result code */
  uint32_t byteswritten;                     /* File write/read counts */
  uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */
                                 
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) 
  {
    if(f_mount(&SDFatFs,(TCHAR const*)SDPath, 0) != FR_OK)
    {
      Error_Handler();
    }
    else
    {
        if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS  | FA_WRITE) != FR_OK) 
        {
          Error_Handler();
        }
        else
        {
					f_puts("First string in my file\n", &MyFile);
					/*
          res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
          if((byteswritten == 0) || (res != FR_OK))
          {
            Error_Handler();
          }
          else
          {
						*/
            f_close(&MyFile);
           BSP_LED_On(LED0);
				BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
       //   }
        }
		}
	}
		 FATFS_UnLinkDriver(SDPath);
}
void SD_init() {
  char SDPath[4]; /* SD card logical drive path */
  if (FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
  {
    if (f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK)
    {
    } else {
      Error_Handler();
    }
  } else {
      Error_Handler();
    
  }
}
Example #19
0
/**
  * @brief  Storage drives initialization
  * @param  None 
  * @retval None
  */
STORAGE_RETURN kStorage_Init(void)
{
  /* Link the micro SD disk I/O driver */
  if(FATFS_LinkDriver(&SD_Driver, mSDDISK_Drive)!=0)
  {
    return KSTORAGE_ERROR_LINK;
  }
  /* Register the file system object to the FatFs module */
  if(f_mount(&mSDDISK_FatFs, (TCHAR const*)mSDDISK_Drive, 0) != FR_OK)
  {
    /* FatFs Initialization Error */
    return KSTORAGE_ERROR_MOUNT;
  }
  return KSTORAGE_NOERROR;
}
Example #20
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /* Configure the BSP */
  BSP_Config();

  /* Initialize the LwIP stack */
  lwip_init();

  /* Configure the Network interface */
  Netif_Config();

  /* Initialize the TFTP server */
  tftpd_init();

  /* Notify user about the network interface config */
  User_notification(&gnetif);

  /* Link the SD Card disk I/O driver */
  FATFS_LinkDriver(&SD_Driver, SD_Path);

  /* Infinite loop */
  while (1)
  {
    /* Read a received packet from the Ethernet buffers and send it
    to the lwIP for handling */
    ethernetif_input(&gnetif);

    /* Handle timeouts */
    sys_check_timeouts();

#ifdef USE_DHCP
    /* handle periodic timers for LwIP */
    DHCP_Periodic_Handle(&gnetif);
#endif
  }
}
Example #21
0
bool mountSDCard()
{
    if (isDriverLink){
        FATFS_UnLinkDriver(SDPath);
        isDriverLink = false;
    }

    if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
    {
        isDriverLink = true;
        if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK)
        {
            return true;
        }
    }
    return false;
}
Example #22
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* System interrupt init*/
  /* Sets the priority grouping field */
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_I2S2_Init();
  MX_I2S3_Init();
  MX_SPI1_Init();
  MX_SPI4_Init();
  MX_TIM3_Init();
  MX_USART2_UART_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /*## FatFS: Link the USER disk I/O driver ###############################*/
  USER_DriverNum = FATFS_LinkDriver(&USER_Driver, USER_Path);

  /* USER CODE BEGIN 3 */
  dabstick_loop(); // endless
  return 0;
  /* USER CODE END 3 */

}
Example #23
0
/**
  * @brief  User Process
  * @param  phost: Host Handle
  * @param  id: Host Library user message ID
  * @retval None
  */
static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
{  
  switch(id)
  { 
  case HOST_USER_SELECT_CONFIGURATION:
    break;
    
  case HOST_USER_DISCONNECTION:
    Appli_state = APPLICATION_DISCONNECT;
    if(USBH_GetActiveClass(phost) == AC_CLASS)
    {
      Audio_ChangeSelectMode(AUDIO_SELECT_MENU); 
    }
    break;
    
  case HOST_USER_CONNECTION:
    break;
    
  case HOST_USER_CLASS_ACTIVE:
    switch(USBH_GetActiveClass(phost))
    {
    case USB_MSC_CLASS:
      Appli_state = APPLICATION_MSC;
      /* Link the USB disk I/O driver */
      FATFS_LinkDriver(&USBH_Driver, USBDISKPath);
      break;
      
    case AC_CLASS:
      Appli_state = APPLICATION_AUDIO;
      /* Init SD Storage */
      if (SD_StorageInit() == 0)
      {
        SD_StorageParse();
      }
      break;
      
    case USB_HID_CLASS:
      Appli_state = APPLICATION_HID;    
      break;      
    }
    break;
  }
}
Example #24
0
/**
  * @brief  Storage drives initialization
  * @param  None 
  * @retval None
  */
void k_StorageInit(void)
{
  /* Link the USB Host disk I/O driver */
   FATFS_LinkDriver(&USBH_Driver, USBDISK_Drive);
  
  /* Init Host Library */
  USBH_Init(&hUSB_Host, USBH_UserProcess, 0);
  
    /* Create USB background task */
  osThreadDef(STORAGE_Thread, StorageThread, osPriorityLow, 0, 64);
  osThreadCreate (osThread(STORAGE_Thread), NULL);
  
  /* Create Storage Message Queue */
  osMessageQDef(osqueue, 10, uint16_t);
  StorageEvent = osMessageCreate (osMessageQ(osqueue), NULL);
  
  /* Add Supported Class */
  USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
  
  /* Start Host Process */
  USBH_Start(&hUSB_Host);
}
Example #25
0
int main(void) {
	HAL_Init();

	led_all_init();
	SystemClock_Config();

	if (BSP_ACCELERO_Init() != ACCELERO_OK) {
		Error_Handler();
	}
	BSP_ACCELERO_Click_ITConfig();
	TIM_LED_Config();

	isLooping = 1;
	ledState = LEDS_OFF;

	BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);

	// Link the USB Host disk I/O driver
	if (FATFS_LinkDriver(&USBH_Driver, usbDrivePath) == 0) {
		USBH_Init(&hUSBHost, usbUserProcess, 0);
		USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
		USBH_Start(&hUSBHost);

		while (1) {
			switch (appState) {
			case APP_START:
				startApp();
				break;
			case APP_IDLE:
			default:
				break;
			}
			USBH_Process(&hUSBHost);
		}
	}

	while (1) {
	}
}
Example #26
0
int mount_fs()
{
  FRESULT err;
  filesystem_info fatfs_info;
  FATFS_LinkDriver(&SFLASHDISK_Driver, SFLASHPath);

  err = f_mount(&SFLASHFatFs, (TCHAR const *)SFLASHPath, 0);
  check_file_result(err, "Fail to mount filesystem.");

  fatfs_info = fatfs_get_info((uint8_t *)SFLASHPath);
  if (fatfs_info.total_space == 0)
  {
    helper_log("Filesystem total space is %d, need format", fatfs_info.total_space);
    helper_log("Start formatting filesystem...");
    err = f_mkfs((TCHAR const *)SFLASHPath, 0, _MAX_SS);
    check_file_result(err, "Fail to format filesystem.");
    fatfs_info = fatfs_get_info((uint8_t *)SFLASHPath);
  }
  helper_log("filesystem total space is %dKB, free space is %dKB", fatfs_info.total_space, fatfs_info.free_space);
  is_fs_mounted = true;
  return FR_OK;
}
/**
  * @brief  Start task
  * @param  pvParameters not used
  * @retval None
  */
static void StartThread(void const *argument)
{
  osEvent event;
  
  /* Link the USB Host disk I/O driver */
  if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
  {
    /* Init Host Library */
    USBH_Init(&hUSB_Host, USBH_UserProcess, 0);
    
    /* Add Supported Class */
    USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
    
    /* Start Host Process */
    USBH_Start(&hUSB_Host);
    
    for( ;; )
    {
      event = osMessageGet(AppliEvent, osWaitForever);
      
      if(event.status == osEventMessage)
      {
        switch(event.value.v)
        {
        case CONNECTION_EVENT:
          MSC_Application();
          break;
          
        case DISCONNECTION_EVENT:
          f_mount(NULL, (TCHAR const*)"", 0);
          break;
          
        default:
          break;
        }
      }
    }
  }
}
Example #28
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  FRESULT res;                                          /* FatFs function common result code */
  uint32_t byteswritten, bytesread;                     /* File write/read counts */
  uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */
  uint8_t rtext[100];                                   /* File read buffer */

  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Initialize IO expander */
  BSP_IO_Init();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /* ###########################################################################
     When the uSD Card is used; the Camera module must be unplugged, this is due
     to the shared pins between the two devices. 
  
     Otherwise, you have to set camera sensor in Power Down mode, by calling the
     BSP_CAMERA_PwrDown() available under stm32446e_eval_camera.c BSP driver */
  
      BSP_IO_Init();
      
     /* Assert the camera RSTI pin */ 
     /* Camera power down sequence */
     BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT);
     /* Assert the camera RSTI pin (active low) */
     BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET);
  
  /*##-1- Link the SD disk I/O driver ########################################*/
  if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) 
  {
    /*##-2- Register the file system object to the FatFs module ##############*/
    if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
    {
      /* FatFs Initialization Error */
      Error_Handler();
    }
    else
    {
      /*##-3- Create a FAT file system (format) on the logical drive #########*/
      if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
      {     
        Error_Handler();
      }
      else
      {
        /*##-4- Create and Open a new text file object with write access #####*/
        if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) 
        {
          /* 'STM32.TXT' file Open for write Error */
          Error_Handler();
        }
        else
        {
          /*##-5- Write data to the text file ################################*/
          res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
          
          if((byteswritten == 0) || (res != FR_OK))
          {
            /* 'STM32.TXT' file Write or EOF Error */
            Error_Handler();
          }
          else
          {
            /*##-6- Close the open text file #################################*/
            f_close(&MyFile);
            
            /*##-7- Open the text file object with read access ###############*/
            if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK)
            {
              /* 'STM32.TXT' file Open for read Error */
              Error_Handler();
            }
            else
            {
              /*##-8- Read data from the text file ###########################*/
              res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
              
              if((bytesread == 0) || (res != FR_OK))
              {
                /* 'STM32.TXT' file Read or EOF Error */
                Error_Handler();
              }
              else
              {
                /*##-9- Close the open text file #############################*/
                f_close(&MyFile);
                
                /*##-10- Compare read data with the expected data ############*/
                if ((bytesread != byteswritten))
                {                
                  /* Read data is different from the expected data */
                  Error_Handler(); 
                }
                else
                {
                  /* Success of the demo: no error occurrence */
                  BSP_LED_On(LED1);
                }
              }
            }
          }
        }
      }
    }
  }
  
  /*##-11- Unlink the SD disk I/O driver ####################################*/
  FATFS_UnLinkDriver(SDPath);
  
  /* Infinite loop */
  while (1)
  {
  }
}
Example #29
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint8_t  sdram_status = SDRAM_OK;
  uint8_t  lcd_status = LCD_OK;
  uint32_t ts_status  = TS_OK;

  p_bmp_converted_pixel_data = (uint8_t *)CONVERTED_FRAME_BUFFER;

  /* STM32F4xx HAL library initialization:
  - Configure the Flash prefetch, instruction and Data caches
  - Configure the Systick to generate an interrupt each 1 msec
  - Set NVIC Group Priority to 4
  - Global MSP (MCU Support Package) initialization
  */
  HAL_Init();

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  /*##-1- Initialize the SDRAM */
  sdram_status = BSP_SDRAM_Init();
  if(sdram_status != SDRAM_OK)
  {
    Error_Handler();
  }

  /*##-2- LCD Initialization #################################################*/
  /* Initialize the LCD DSI */
  lcd_status = BSP_LCD_Init() ;
  if(lcd_status != LCD_OK)
  {
    Error_Handler();
  }

  lcd_status = BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE);
  if(lcd_status != LCD_OK)
  {
    Error_Handler();
  }
  BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_BACKGROUND, LCD_FB_START_ADDRESS);

  /* Clear the LCD Background layer */
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /*##-3- Touch screen initialization ########################################*/
  BSP_TS_ResetTouchData(&TS_State);

  /* If calibration is not yet done, proceed with calibration */
  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);
    }
  } /* of if (TouchScreen_IsCalibrationDone() == 0) */



  /*##-4- Link the SD Card disk I/O driver ###################################*/

  /* Clear the LCD and display waiting message */
  BSP_LCD_Clear(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetFont(&Font12);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 - 27, (uint8_t*)"Please WAIT few seconds", CENTER_MODE);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 - 12, (uint8_t*)"Creating FAT file system on SD card", CENTER_MODE);

  if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0)
  {
    /* FatFs Initialization Error */
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t*)"FAT FS Error !!", CENTER_MODE);
    Error_Handler();
  }

/*##-4- Register the file system object to the FatFs module ################*/
  if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
    {
    /* FatFs Initialization Error */
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t*)"FAT FS Error !!", CENTER_MODE);
    Error_Handler();
   }
  /* Create a FAT file system (format) on the logical drive */
  if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
  {
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t*)"FAT FS Error !!", CENTER_MODE);
    Error_Handler();
  }

  /*##-5- Draw the menu ######################################################*/
  Draw_Menu();

  /* Infinite loop */
  while (1)
  {
  /*##-6- Configure the touch screen and Get the position ####################*/
    GetPosition();
  }
}
Example #30
0
/**
  * @brief  Start task
  * @param  pvParameters not used
  * @retval None
  */
static void StartThread(void const *argument)
{
  FRESULT res;                                          /* FatFs function common result code */
  uint32_t byteswritten, bytesread;                     /* File write/read counts */
  uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */
  uint8_t rtext[100];                                   /* File read buffer */
  
  /*##-1- Link the RAM disk I/O driver #######################################*/
  if(FATFS_LinkDriver(&SDRAMDISK_Driver, RAMDISKPath) == 0)
  {
    /*##-2- Register the file system object to the FatFs module ##############*/
    if(f_mount(&RAMDISKFatFs, (TCHAR const*)RAMDISKPath, 0) != FR_OK)
    {
      /* FatFs Initialization Error */
      Error_Handler();
    }
    else
    {
      /*##-3- Create a FAT file system (format) on the logical drive #########*/
      if(f_mkfs((TCHAR const*)RAMDISKPath, 0, 0) != FR_OK)
      {
        /* FatFs Format Error */
        Error_Handler();
      }
      else
      {
        /*##-4- Create and Open a new text file object with write access #####*/
        if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) 
        {
          /* 'STM32.TXT' file Open for write Error */
          Error_Handler();
        }
        else
        {
          /*##-5- Write data to the text file ################################*/
          res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
          
          if((byteswritten == 0) || (res != FR_OK))
          {
            /* 'STM32.TXT' file Write or EOF Error */
            Error_Handler();
          }
          else
          {
            /*##-6- Close the open text file #################################*/
            f_close(&MyFile);
            
            /*##-7- Open the text file object with read access ###############*/
            if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK)
            {
              /* 'STM32.TXT' file Open for read Error */
              Error_Handler();
            }
            else
            {
              /*##-8- Read data from the text file ###########################*/
              res = f_read(&MyFile, rtext, sizeof(rtext), (void *)&bytesread);
              
              if((bytesread == 0) || (res != FR_OK))
              {
                /* 'STM32.TXT' file Read or EOF Error */
                Error_Handler();
              }
              else
              {
                /*##-9- Close the open text file #############################*/
                f_close(&MyFile);
                
                /*##-10- Compare read data with the expected data ############*/
                if((bytesread != byteswritten))
                {                
                  /* Read data is different from the expected data */
                  Error_Handler();
                }
                else
                {
                  /* Success of the demo: no error occurrence */
                  BSP_LED_On(LED1);
                }
              }
            }
          }
        }
      }
    }
  }
  
  /*##-11- Unlink the RAM disk I/O driver ####################################*/
  FATFS_UnLinkDriver(RAMDISKPath);
  
  /* Infinite Loop */
  for( ;; )
  {
  }
}