zoukankan      html  css  js  c++  java
  • 【iCore4 双核心板_ARM】例程十九:USBD_MSC实验——虚拟U盘

    实验步骤:

    1、将SD卡插在SD卡槽中。

    2、将跳线冒跳至USB_OTG,将USB_OTG通过Micor USB线与USB主机(电脑)相连。

    3、烧写程序,我的电脑中将出现一个磁盘。

    实验现象:

    核心代码:

    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();
    
      /* USER CODE BEGIN Init */
    
      /* USER CODE END Init */
    
      /* Configure the system clock */
      SystemClock_Config();
    
      /* USER CODE BEGIN SysInit */
    
      /* USER CODE END SysInit */
    
      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_USB_DEVICE_Init();
    
      /* USER CODE BEGIN 2 */
    
      /* USER CODE END 2 */
    
      /* Infinite loop */
      /* USER CODE BEGIN WHILE */
      while (1)
      {
      /* USER CODE END WHILE */
    
      /* USER CODE BEGIN 3 */
            LED_RED_ON;
            LED_GREEN_OFF;
            LED_BLUE_OFF;
            HAL_Delay(500);
            LED_RED_OFF;
            LED_GREEN_ON;
            LED_BLUE_OFF;
            HAL_Delay(500);
            LED_RED_OFF;
            LED_GREEN_OFF;
            LED_BLUE_ON;
            HAL_Delay(500);        
      }
      /* USER CODE END 3 */
    
    }
    /*******************************************************************************
    * Function Name  : STORAGE_Read_HS
    * Description    : 
    * Input          : None.
    * Output         : None.
    * Return         : None.
    *******************************************************************************/
    int8_t STORAGE_Read_HS (uint8_t lun, 
                            uint8_t *buf, 
                            uint32_t blk_addr,                       
                            uint16_t blk_len)
    {
      /* USER CODE BEGIN 13 */ 
        uint32_t timeout = 10000;
        
        if(BSP_SD_ReadBlocks((uint32_t*)buf, blk_addr, blk_len, timeout) == USBD_OK){
                while(BSP_SD_GetCardState()!= MSD_OK)
                {
                    if (timeout-- == 0)
                    {
                        return -1;
                    }
                }
        }    
      return (USBD_OK);
      /* USER CODE END 13 */ 
    }
    
    /*******************************************************************************
    * Function Name  : STORAGE_Write_HS
    * Description    :
    * Input          : None.
    * Output         : None.
    * Return         : None.
    *******************************************************************************/
    int8_t STORAGE_Write_HS (uint8_t lun, 
                             uint8_t *buf, 
                             uint32_t blk_addr,
                             uint16_t blk_len)
    {
      /* USER CODE BEGIN 14 */ 
        uint32_t timeout = 10000;
        
        if(BSP_SD_WriteBlocks((uint32_t*)buf, blk_addr, blk_len, timeout) == USBD_OK){
                while(BSP_SD_GetCardState()!= MSD_OK)
                {
                    if (timeout-- == 0)
                    {
                        return -1;
                    }
                }
        }        
      return (USBD_OK);
      /* USER CODE END 14 */ 
    }

    源代码下载链接:

    链接:http://pan.baidu.com/s/1dFvm5rj 密码:tys0

    iCore4链接:

  • 相关阅读:
    vnc安装
    centos下安装图形界面
    granfana telegraf influx安装与使用
    jenkins安装与使用
    yum使用手册
    Python模块--并发相关threading、multiprocessing、Queue、gevent
    Python模块--logging
    Python模块--psutil
    python模块--Beautifulsoup
    Python模块--Pexpect
  • 原文地址:https://www.cnblogs.com/xiaomagee/p/7510075.html
Copyright © 2011-2022 走看看