Record - RT-Thread implement virtual USB serial-based
My record in punctuality atom Apollo F429 development board USB to serial port of the virtual process, hope to help others who want to learn the USB.
- First of all, I updated about the RT-Thread source code (since RT-Thread code updates very quickly, within a short time there may be a lot of code updates).
- Then I entered
rt-thread\bsp\stm32
the directory, find a punctual atomic Apollo F429 development board corresponding BSPstm32f429-atk-apollo
.
- Then I look a bit this BSP current support does not support USB. I opened Env tool in the directory, enter
menuconfig
the command to check a bit and found the USB option is not configured on-chip peripheral hardware configuration of the configuration menu, it appears that the BSP does not support USB devices.
- Then I thought, the new STM32 BSP BSP are all the same with a drive, see what I have not done a USB drive it. Then I opened the
rt-thread\bsp\stm32\libraries\HAL_Drivers
directory, as shown below, and found there really usb drive file, calleddrv_usbd_fs.c
. This is good to do.
- Open Sconscript script file in the same directory, check the drive configuration depend on what was found dependent on
BSP_USING_USBD_FS
the configuration.
- Since the drive, there must BSP has supported this feature, I searched all the BSP under stm32 catalog, to see if the configuration item under which the bsp. Look at the way dependencies. The F469 has found that this configuration item bsp, open the configuration looks the same time, using the select command also opens
RT_USING_USB_DEVICE
the configuration. With this example like that, and this is also added as long as enough arranged at punctual atoms Apollo bsp.
- Modify punctual atomic F429 Apollo bsp under Kconfig file, add this section of configuration items.
- Then you can use Env tool to configure the project. In the menuconfig configuration directory input usb, open usb drive configuration item just added.
- Then, the configuration device frame usb. Open virtual serial port.
- Save and then rebuild the project. Compile error was found. It appears to be no hardware configuration. You need to open stm32CubMX usb hardware configuration pins.
- Open
stm32f429-atk-apollo\board\CubeMX_Config
stm32CubMX the project directory, configuration usb.
- After the discovery of open usb function, clock configuration report warned, we re-configured at the clock. Once configured, re-generate the code.
- Since the update of the clock tree, so also the
stm32f429-atk-apollo\board\CubeMX_Config\Src
main.c in the directory clock configuration functionSystemClock_Config
update tostm32f429-atk-apollo\board
board.c file in the directory.
- And then re-open the project, compile, or error,
cannot open source input file "stm32f4xx_hal_exti.h": No such file or directory
I commented that the header files compiled try again. Compile again and found no problem.
- Download Run and enter
list_device
the command register in the system can be seen in the two usb related equipment.
- Then I added some test code in the main function, the compiler download and run.
#include <rtthread.h>
#include <rtdevice.h>
int main(void)
{
rt_device_t dev = RT_NULL;
char buf[] = "hello rt-thread!\r\n";
dev = rt_device_find("vcom");
if (dev)
rt_device_open(dev, RT_DEVICE_FLAG_RDWR);
else
return -RT_ERROR;
while (1)
{
rt_device_write(dev, 0, buf, rt_strlen(buf));
rt_thread_mdelay(500);
}
return RT_EOK;
}
- USB_SLAVE development board is connected to the computer interface, to open the device manager, found in a USB serial device, the serial port is opened with the tool, you receive the message transmitted over the main function of the
thus developed punctual atoms F429 Apollo USB board to achieve a virtual serial port.