cancel
Showing results for 
Search instead for 
Did you mean: 

How to use virtual COM port with nucleo-H563ZI

Christian_Janz
Associate II

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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, ...);

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

13 REPLIES 13
AScha.3
Chief III

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 :)

If you feel a post has answered your question, please click "Accept as Solution".

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.

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, ...);

If you feel a post has answered your question, please click "Accept as Solution".

+ to see, how to write parameters : look in the lib ->

<your project> /Middlewares/ST/usbx/common/usbx_device_classes/src/ux_device_class_cdc_acm_write.c

 

/*  DESCRIPTION                                                           */
/*                                                                        */ 
/*    This function writes to  the CDC class.                             */ 
/*                                                                        */ 
/*    It's for RTOS mode.                                                 */
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    cdc_acm                               Address of cdc_acm class      */ 
/*                                                instance                */ 
/*    buffer                                Pointer to data to write      */
/*    requested_length                      Length of bytes to write,     */
/*                                                set to 0 to issue ZLP   */
/*    actual_length                         Pointer to save number of     */
/*                                                bytes written           */
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 

 

If you feel a post has answered your question, please click "Accept as Solution".

and the test print :

1. should end with "new line" :   printf("ERROR! xxx ! \r\n");

2. should be in a loop repeated: after connect to pc -> open modem/terminal -> set connection to : usb/acm/serial - whatever it is ; but this needs some time and you see only, whats sended then. so your "A" at start you will probably never see.

about this:

  /* Infinite loop */
  while (1)
  {
      printf("Murks! \r\n);
    /* Delay for 2000ms (App_Delay is used to avoid context change). */
      tx_thread_sleep(200);  // ohne sleep geht usbx nicht ! komisch...
   
  }

and not in main ...rtos -> in thread

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your help! Ok new day new luck.

Sorry, I am a complete beginner.

I try to use the Function "ux_device_class_cdc_acm_write" in main.

I got an error that cdc_acm is undeclared.

Virtual COM Port_2.PNG

Were I can find the adress or where I get the adress?

Do you know is there a documentation or an How to?

 

look at examples , like this:

https://github.com/Dbotelho2000/CDC_USBX_G474/blob/main/USBX/App/ux_device_cdc_acm.c

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

 

If you feel a post has answered your question, please click "Accept as Solution".
Haithem Rahmani
ST Employee

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?

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?