Record - RT-Thread implement virtual USB serial-based

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.

  1. 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).
  2. Then I entered rt-thread\bsp\stm32the directory, find a punctual atomic Apollo F429 development board corresponding BSP stm32f429-atk-apollo.
    bsp path
  3. Then I look a bit this BSP current support does not support USB. I opened Env tool in the directory, enter menuconfigthe 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.
    Here Insert Picture Description
  4. 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_Driversdirectory, as shown below, and found there really usb drive file, called drv_usbd_fs.c. This is good to do.
    usb drive
  5. Open Sconscript script file in the same directory, check the drive configuration depend on what was found dependent on BSP_USING_USBD_FSthe configuration.
    Sconscript script
  6. 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_DEVICEthe configuration. With this example like that, and this is also added as long as enough arranged at punctual atoms Apollo bsp.
    Here Insert Picture Description
  7. Modify punctual atomic F429 Apollo bsp under Kconfig file, add this section of configuration items.
    Here Insert Picture Description
    Here Insert Picture Description
  8. Then you can use Env tool to configure the project. In the menuconfig configuration directory input usb, open usb drive configuration item just added.
    Here Insert Picture Description
  9. Then, the configuration device frame usb. Open virtual serial port.
    Here Insert Picture Description
  10. 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.
    Here Insert Picture Description
  11. Open stm32f429-atk-apollo\board\CubeMX_Configstm32CubMX the project directory, configuration usb.
    Here Insert Picture Description
    Here Insert Picture Description
  12. After the discovery of open usb function, clock configuration report warned, we re-configured at the clock. Once configured, re-generate the code.
    Here Insert Picture Description
  13. Since the update of the clock tree, so also the stm32f429-atk-apollo\board\CubeMX_Config\Srcmain.c in the directory clock configuration function SystemClock_Configupdate to stm32f429-atk-apollo\boardboard.c file in the directory.
    Here Insert Picture Description
  14. And then re-open the project, compile, or error, cannot open source input file "stm32f4xx_hal_exti.h": No such file or directoryI commented that the header files compiled try again. Compile again and found no problem.
    Here Insert Picture Description
    Here Insert Picture Description
  15. Download Run and enter list_devicethe command register in the system can be seen in the two usb related equipment.
    Here Insert Picture Description
  16. 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;
}
  1. 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
    Here Insert Picture Description
    Here Insert Picture Description
    thus developed punctual atoms F429 Apollo USB board to achieve a virtual serial port.

Guess you like

Origin blog.csdn.net/newbie_Blogger/article/details/92617242