[GD32E503 Evaluation] Realizing USB disk function based on uCOSIII project 1
[Copy link]
Preface:
When driving the LCD screen, we need to use fonts, pictures and other data. For example, if we want to display Chinese characters, the process is as follows: Make a font library to generate a .bin file, for example, generate a gb2312.bin file through the font library, and write the gb2312.bin file to the flash. The MCU parses the Chinese characters, obtains the gb2312 index value, and calculates the flash location based on the size of the font library. Read the corresponding data. The MCU sends the read data to the LCD screen for display.
When implementing the above process, I encountered a problem, that is, how to transfer the gb2312.bin file to the flash? I have the following methods:
- Write to flash via the serial port using the Ymodem protocol.
- Through the flash burning tool (but you need to take down the flash, burn it and then solder it back)
- Write to flash via usb-hid using the Ymodem protocol.
- Write files to flash in the form of a virtual USB disk.
Well...if you have any good ideas, please give me some advice. I can think of the above methods.
So, to sum up, I think it is most convenient to simulate a USB flash drive through gd32e503v and write the bin file to the USB flash drive on the PC side.
So I checked the schematic diagram and found out the solution for the USB port:
Also looked at the USB example code:
The official website only provides two examples, one for keyboard and one for CDC. As for USB flash disk, it belongs to MSC, but unfortunately it is not provided by the official website.
However, if we look carefully at the official information, we can find that the official still provides some necessary library files, as shown in the figure below, usbd stands for usb device, usbh stands for usbhost. These necessary driver codes are all there, and further checking the file usbd_library, we can find that the official actually provides a sample demo of msc.
Okay, everything is ready, except for freezing your hands.
Based on the current situation, we have already created the framework of uCOSIII, so we plan to add to it.
- First, transplant the official 23_USBD_Keyboard to the uCosIII framework and test whether it is normal.
- According to the official usb msc file, modify the 23_USBD_Keyboard project to realize the USB disk function.
Open the 23_USBD_Keyboard project, and you can see that the project structure is as follows. Application is where users modify the files. The three files USBD_Drivers, USBD_Devices, and USBD_Class are all officially provided. Generally, there is no special requirement and no need to modify them. You just need to add them.
We follow the same pattern, create corresponding files in our own project, and import
Then during compilation, there will be many header files that cannot be found. We can look in the demo project, find the corresponding header file path, and import them together. After that, you will find that some function interfaces cannot be found, so I also added a USBD_User folder for easy modification.
It should be noted that the file gd32e_50x_it.c is the entry of the interrupt function. Therefore, we need to copy some contents in the Demo to our project, including the following interface functions:
During this period, there will be some compilation errors, header files cannot be found, functions cannot be found, etc. I will not go into details about these basic skills.
Further, write the main function code
Two threads were created previously, so we add the following code to task2: (In fact, it is just copying the main function of the official routine)
Then compile and pass it, and then debug to see the effect.
But there was a problem:
And the development board can no longer debug or burn. . This scared me, I don't know why. However, fortunately, the gd32e503v development board brings out boot0 and boot1, which can easily modify the startup method of the mcu. (From flash, from ram... You can find the specific details on Baidu, stm32's Boot0 Boot1) Why stm32? ? ? Because gd is almost perfectly compatible with stm32~! The best domestic IC. I think it's awesome.
Pull boot0 and boot1 high, select erase all for flash programming, and then power on again to start flash programming.
Because the chip cannot be burned due to our code, we need to modify the code:
Then, set boot0 and boot1 low again, and you can debug. The chip is finally normal.
The above is just the beginning of realizing the USB disk function.
It took me quite a while, unfinished, to be continued...
|