[RISC-V MCU CH32V103 Evaluation] ---Advanced Wiki---Write USB Files
[Copy link]
This post was last edited by wintonson on 2021-1-31 15:33
【 RISC-V MCU CH32V103 Review】 ---Advanced Wiki--- Writing USB files
The Advancement of Victory
January 31 , 2021
Preface:
This is the eighth article written by Weizi on EEWORLD to evaluate ch32v103 . It is also the third article written by Weizi on ch32v103 related to USB . In the previous two articles, "Weizi" gave a brief explanation of " the concept of USB device enumeration" and "the actual enumeration process and the specific code connection". This article will take notes on the specific example of ch32v103 reading and writing USB flash drives, hoping to inspire everyone.
Through this article, readers can learn:
1 : How to call external libraries.
2 : How to add scatter-loading files.
3 : How to view the peripheral register value.
1. Preparation
Hardware preparation: 1 : core board; 2 : emulator; 3 : USB card reader; 4 : TF card.
Software preparation: 1 : MounRiver Studio ; 2 : win10 operating system 3 : official exam13 code.
2. Process
2.1 : Preparation process on win10 .
Preparation of the USB flash drive before operation. Check the existing file list in the USB flash drive on Windows 10. At the same time, check the ID of the USB flash drive through the device manager . The purpose of finding the ID is to recognize it in the MCU code.
Remember: 14CD 1212
2.2 : Project preparation
Rebuild the project
1 : Add a peripheral Udisk library. The method is as follows:
Select the folder where the library is located (as shown below):
After setting, the project column is in the following state:
Add the header file location of the corresponding library
Add link location
At this time, the compilation will produce the following error: (because the miscellaneous item is configured incorrectly)
If you add incorrect content under Miscellaneous , you will see the following prompt:
Description Resource Path Location Type redeclaration of memory region `RAM' CH32V103C8T6_exam13 line 1, external location: d:\mounriver\mounriver_studio\toolchain\risc-v embedded gcc\riscv-none-embed\bin\ld.exe: D:\MounRiver \MounRiver_Studio\workspace\CH32V103C8T6_exam13\Ld\Link.ld
After modification, the following prompt appears after compiling again:
2.3 : Enter debug mode (without USB drive)
Make a breakpoint in the diagram and press F5 to run to the breakpoint.
The running process of the code has been briefly described in the previous article. I will not go into details about the process here. Our goal is to add a breakpoint and observe the ID after successfully obtaining the ID . The breakpoint position is as shown below:
Look at the VID PID here . Insert the USB drive and wait for the breakpoint. Unfortunately, it does not enter the breakpoint interface as expected. Let's troubleshoot. (Troubleshooting usually starts with checking the hardware and then looking at the registers. Let's look at the registers first as in the next step).
2.4 : Check the register process
Check the registers of the USB peripheral as follows:
This means that the value of the register " RB_UIF_DETECT " remains unchanged whether the USB flash drive is inserted or removed. In fact, we found that we did not power the USB flash drive! S2 is in the off state. After turning the toggle switch to the On state, the following breakpoint will stop.
2.5 : Run directly to the end
The default is decimal . Let's look at it in hexadecimal :
These two values: 14CD 1212 came out! The enumeration was successful.
2.6 : Check whether it is successful on win10
Finally, unplug the USB drive, plug it into the computer, and observe whether there is a file created. As shown below;
We can see that there is indeed one more file.
3. Conclusion In this article, Weizi testedch32v103development board asUSBhost to write toflashdrive in detail. Weizi started the project from a blank project. The configuration process and debugging process in the middle are valuable. Through this test and the previous two tests, Weizi came to the conclusion:1:The IDEis really great and easy to use. It is easy to get started.2:The USBofthe ch32v103is easy to understand. Easy to get started and easy to operate.
|