• STM32cubeMX配置FreeRTOS-51、USB-U盘读写


    1-选USB-FS,Host_Only
    2-USB_HOST,Mass Storage Host Class配置为大容量存储设备,调试为3,512个words,即2K字节。
    3-FATFS,勾选USB Disk,CODE_PAGE设置Latin1改S-C-(DBCS),LFN为----STACK.
    4-工程堆栈全为1000。
    5-在main.c文件中 代码0中增加代码
    extern ApplicationTypeDef Appli_state;
    extern USBH_HandleTypeDef hUsbHostFS;
    extern char USBHPath[4]; // USBH logical drive path
     
    FATFS FatfsUDisk; // File system object for USB disk logical drive
    FIL myFile; // File object
     
    static void MSC_Application(void)
    {
        FRESULT fres; // FatFs function common result code
        uint32_t byteswrite;
        uint8_t str[] = "hello world!";
     
        /* Register the file system object to the FatFs module */
        if( f_mount(&FatfsUDisk, (TCHAR const*)USBHPath, 0) != FR_OK)
        {
            Error_Handler(); //FatFs Initialization Error
        }
        else
        {
            /* Create and Open a new text file object with write access */
            if(f_open(&myFile, "test.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
            {
                Error_Handler(); //'STM32.TXT' file Open for write Error
            }
            else
            {
                fres = f_write(&myFile, str, sizeof(str), (void *)&byteswrite);
                if(byteswrite == 0 || (fres != FR_OK))
                {
                    Error_Handler();
                }
                else
                {
                    f_close(&myFile); //Close the open text file
                }
            }
        }
    }
    6-在main.c代码3中中增加
       switch(Appli_state)
        {
            case APPLICATION_READY:
                MSC_Application();
                Appli_state = APPLICATION_DISCONNECT;
                break;
            case APPLICATION_DISCONNECT:
                f_mount(NULL, "", 0);
                break;
            default:
                break;
        }
    插上U盘后新建了tast文件内容hello word。

  • 相关阅读:
    Python匿名函数
    go实现自定义rpc框架 (核心:服务端&客户端、自定义io流、编解码、服务发现、负载均衡、支持多语言网关等)
    SQL注入与PreparedStatement对象
    c#设计模式-行为型模式 之 中介者模式
    uni-app vue3+ts+vite采坑说明
    读vue源码搞懂响应式原理
    LeetCode-86. 分隔链表-Java-medium
    【SpringBoot】Redission 的使用与介绍
    MS4344:24bit、192kHz 双通道数模转换电路
    微服务feign组件学习
  • 原文地址:https://blog.csdn.net/fanzhipeng7000/article/details/134430141