Skip to main content
Explorer
November 20, 2023
Solved

How to use virtual COM port with nucleo-H563ZI

  • November 20, 2023
  • 2 replies
  • 9277 views

Hello,

I am new in the STM world.

I am using the nucleo-H563ZI deverlopment board and I want to get the virtual COM port to work.

On github I found the examples of the Board.

https://github.com/STMicroelectronics/STM32CubeH5 

I opend the project "...\Projects\NUCLEO-H563ZI\Applications\USBX\Ux_Device_HID_CDC_ACM" and compiled it.

After that the PC recognize a vitual COM Port. So far so good.

Now I want to send or receive Data by the virtual COM port.

But I can't find the function for sending or receiving Data.

 

Is there anybody who can help me, please?

 

Best regards

Christian

 

 

    This topic has been closed for replies.
    Best answer by AScha.3

    aaaa, i thought it is clear: you have to replace this with the call you have in your actual system to "send" .

    so on H563 + Azure you need the matching call ... (i just look...)

    look also:

    https://learn.microsoft.com/en-us/azure/rtos/usbx/usbx-device-stack-4

    or

    https://github.com/search?q=usbx%20cdc&type=repositories

     

    should be something like:

    ux_device_class_cdc_acm_write(cdc_acm, ...);

    2 replies

    Super User
    November 20, 2023

    to use printf(...) you need to send it to the usb->cdc ;

    put in main:

     

     

     

    int _write(int file, char *ptr, int len)
    {
    	 if(CDC_Transmit_FS((uint8_t *)ptr, len))
    	 {
    		 HAL_Delay(2);
    		 CDC_Transmit_FS((uint8_t *)ptr, len);
    	 }
    
     return len;
    }

     

     

     

    just a quick and dirty test...try :)

    Explorer
    November 20, 2023

    Hello AScha.3,

    thank you for your quick reply.

    I insert you code in example in section /* USER CODE BEGIN 4 */

    And call printf before while(1) with printf("A");

    By building project I got 4 errors:

    Virtual COM Port.PNG

    I hope you can read it.

    CDC_Transmit_FS is undefined.

    AScha.3Answer
    Super User
    November 20, 2023

    aaaa, i thought it is clear: you have to replace this with the call you have in your actual system to "send" .

    so on H563 + Azure you need the matching call ... (i just look...)

    look also:

    https://learn.microsoft.com/en-us/azure/rtos/usbx/usbx-device-stack-4

    or

    https://github.com/search?q=usbx%20cdc&type=repositories

     

    should be something like:

    ux_device_class_cdc_acm_write(cdc_acm, ...);

    ST Employee
    November 22, 2023

    Hi @Christian_Janz 

    First of all, welcome to STM32 World! :smiling_face_with_smiling_eyes:.

     

     

    as described in the Readme.md file you'll need two Hyperterminals to exachange data between the board and the PC. Did you succeed to have that running?

    Explorer
    November 22, 2023

    Hi @Haithem Rahmani and @AScha.3

    Thank you for your help.

     

    @Haithem Rahmani 

    "as described in the Readme.md file you'll need two Hyperterminals to exachange data between the board and the PC. Did you succeed to have that running?"

    Yes, this is working fine.

    I want to send and receive customized data from my programm and from PC via virtual com port.

    Thanks to @AScha.3, I found the function to send Data (ux_device_class_cdc_acm_write()).

    But my fault was to call it in main.c

    If I call it in ux_device_cdc_acm.c and it workin fine. Here my quick test:

    Virtual COM Port_3.PNG

    I am happy to get this to work.

    But is it possible to call the function in main.c or how can share data from main.c to ux_device_cdc_acm.c?

    Maybe with global variables?

    Super User
    November 27, 2023

    Hi @Christian_Janz  , you have a lot to understand now - using a RTOS , no more "just" a program.

    1. no more "main"  = the program ! now many "main" possible, all running (virtual) at same time.

    2. read the comment in main.c , and believe it :

    AScha3_0-1701094087247.png

    now your program is in processing tasks or threads !

    so if you dont need this (maybe same me: had to use this Azure just because STM leaves us no choice anymore : want USB , Fat-file system ? then use Azure! )

    you can use the first and only thread, that is generated by Cube if you let it do it :

    AScha3_2-1701094493253.png

    then in core -> app_threadx.c :

     

    AScha3_1-1701094421160.png

    i just rename this first thread to  >> tx_app_main_entry << , to see my "main" now by a similar name. :)

    so write here, what you in old times wrote in "main" , here my H563 program begins:

     

    void tx_app_main_entry(ULONG thread_input)
    {
     /* USER CODE BEGIN tx_app_main_entry */
    	printf("app_main start \n");
    	/*##-2- Register the file system object to the FatFs module ##############*/
     	fresult = f_mount(&SDfs, (TCHAR const*)SDPath, 1);			// SD card mount
     if(fresult)
     {
     	printf(" mount error ! \n");
    .....

     

    - ( but i am using fatfs here , not filex )