3562 views|6 replies

6841

Posts

11

Resources
The OP
 

[National Technology N32G457 Review] RT_Thread Studio transplants USB virtual serial port [Copy link]

 

Using the built-in USB function of N32G45, connect the computer USB, virtualize a USB serial port, and realize data communication between the computer and the development board. The official MDK provides an example. Using RT_Thread Studio, it does not work after being configured as USB. Now port the MDK program in the example to rt_thread_studio.

1. Create a new usb_driver folder in packages, copy the Virtual_COM_Port folder in the example to this directory, and then copy the Nationstech.N32G45x_Library.1.1.1\firmware\n32g45x_usbfs_driver folder to the directory.

Add the compiled directory to the project directory:

Delete main.c and main.h under Vitrual_COM_Port

Then compile, there will be many errors, many of which are repeated definitions of functions in n32g45x_it.c, delete the repeated functions. Another is to add the n32g45x.h header file. After the compilation is successful, add the header file and USB initialization function in main.c of applications

#include <stdint.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "hw_config.h"
#include "usb_lib.h"
#include "usb_pwr.h"

/* defined the LED1 pin: PB5 */
#define LED1_PIN    100

int main(void)
{
    uint32_t Speed = 200;
    /* set LED1 pin mode to output */
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
    USB_Interrupts_Config();
    Set_USBClock();
    USB_Init();
    while (1)
    {
        rt_pin_write(LED1_PIN, PIN_LOW);
        rt_thread_mdelay(Speed);
        rt_pin_write(LED1_PIN, PIN_HIGH);
        rt_thread_mdelay(Speed);
    }
}

After the compilation is successful, download it to the development board and restart it: The computer successfully detects the serial port:

Use the serial port assistant to connect to the virtual serial port and send data to the development board: The development board shell successfully prints out:

The USB virtual serial port receiving function is void EP3_OUT_Callback(void) in usb_endp.c. If data needs to be processed, it can be processed here.

/*******************************************************************************
* Function Name  : EP3_OUT_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP3_OUT_Callback(void)
{
  uint16_t USB_Rx_Cnt;
  
  /* Get the received data buffer and update the counter */
  USB_Rx_Cnt = USB_SilRead(EP3_OUT, USB_Rx_Buffer);
  
  /* USB data will be immediately processed, this allow next USB traffic being 
  NAKed till the end of the USART Xfer */
  
  USB_To_USART_Send_Data(USB_Rx_Buffer, USB_Rx_Cnt);
 
  /* Enable the receive of data on EP3 */
  USB_SetEpRxValid(ENDP3);
}

The USB virtual serial port sending function is hw_config.c

/*******************************************************************************
* Function Name  : USB_To_USART_Send_Data.
* Description    : send the received data from USB to the UART 0.
* Input          : data_buffer: data address.
                   Nb_bytes: number of bytes to send.
* Return         : none.
*******************************************************************************/
void USB_To_USART_Send_Data(uint8_t* data_buffer, uint8_t Nb_bytes)
{
  
  uint32_t i;
  
  for (i = 0; i < Nb_bytes; i++)
  {
    USART_SendData(USART1, *(data_buffer + i));
    while(USART_GetFlagStatus(USART1, USART_FLAG_TXDE) == RESET); 
  }  
}

You can modify it as needed, use the usb_ virtual serial port, save a USB-TTL is also very convenient. The project upload is as follows:

N32G45_USB.7z

4.7 MB, downloads: 24

This post is from Domestic Chip Exchange

Latest reply

Did he split it into 64-byte packets?  Details Published on 2022-2-9 22:06
 
 

6778

Posts

2

Resources
2
 

Test what happens when sending data larger than 64 bytes.

This post is from Domestic Chip Exchange
 
 
 

6841

Posts

11

Resources
3
 

Indicates no pressure:

This post is from Domestic Chip Exchange

Comments

Did he split it into 64-byte packets?  Details Published on 2022-2-9 22:06
 
 
 

6841

Posts

11

Resources
4
 

I wanted to write it in the same way as stm32 as device registration, but I couldn't find any information.

This post is from Domestic Chip Exchange
 
 
 

6778

Posts

2

Resources
5
 
means no pressure:

Did he split it into 64-byte packets?

This post is from Domestic Chip Exchange

Comments

I specifically looked up the USB interface buf and found that the longest packet received is 64.  Details Published on 2022-2-12 08:51
 
 
 

6841

Posts

11

Resources
6
 
wangerxian posted on 2022-2-9 22:06 Did he split it into 64-byte packets?

I specifically looked up the USB interface buf and found that the longest packet received is 64.

This post is from Domestic Chip Exchange
 
 
 

6841

Posts

11

Resources
7
 

/* Private variables ---------------------------------------------------------*/
uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];

#define VIRTUAL_COM_PORT_DATA_SIZE 64

Maybe it’s because of the DEMO, so it directly transfers to rt_printf, so there is no problem.

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Low power super-regenerative receiver for 433MHz ISM band

Low power super-regenerative receiver for 433MHz ISM band HC360.com May 12, 2006 9:40 AM Source: EDN China ...

Start → Run → Command Encyclopedia

This post was last edited by jameswangsynnex on 2015-3-3 20:00 winver---------Check the Windows version wmimgmt.msc--- ...

Brief analysis of the functional block diagram of the MSP430 series microcontroller

This post was last edited by tiankai001 on 2018-12-6 16:55 This content is originally created by EEWORLD forum user tian ...

Limited-time free download | NI white paper: "Three Visions of the O-RAN Alliance"

As global cellular data usage continues to grow, telecommunications systems must evolve to keep up with the demand. Whil ...

Problems with freewheeling diodes in MOS drive motors

This post was last edited by me on 2021-3-17 11:36 As the title says, and as shown in the figure below, when using MOS ...

【Development and application based on NUCLEO-F746ZG motor】13. Parameter configuration - USART3 configuration

The function of this serial port on the development board is to communicate with ST-LINK, and then connect ST_LINK2 to t ...

[Evaluation of EC-01F-Kit, the NB-IoT development board of Anxinke] Unboxing

1. Receiving goods The RF NB-IoT development board from Essence arrived on time. It also provided a mobile data card and ...

[Sipeed LicheeRV 86 Panel Review] 13. Using TCP to encapsulate HTTP packets to request weather information

This post was last edited by sonicfirr on 2022-4-19 20:21 I am still getting familiar with Linux . I just realized that ...

Help choose a step-down DCDC chip

The input voltage is required to be 60V and the output is 6-12V. The cost should be low, the efficiency should be as hig ...

Reading check-in station 3: Chapters 9-14 - "RT-Thread Device Driver Development Guide"

Reading partners @南若 @chrisrh @wakojosin @xiaolinen @damiaa Check-in for the third station, here comes the topi ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list