2023-11-20 06:40 AM
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
Solved! Go to Solution.
2023-11-20 07:50 AM - edited 2023-11-20 07:54 AM
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, ...);
2023-11-20 06:48 AM - edited 2023-11-20 06:53 AM
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 :)
2023-11-20 07:32 AM
2023-11-20 07:50 AM - edited 2023-11-20 07:54 AM
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, ...);
2023-11-20 08:01 AM
+ 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 */
2023-11-20 08:35 AM
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
2023-11-21 01:20 AM
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.
Were I can find the adress or where I get the adress?
Do you know is there a documentation or an How to?
2023-11-21 02:05 AM
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
2023-11-22 12:44 AM
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?
2023-11-22 01:53 AM
Hi @Haithem Rahmani and @AScha.3
Thank you for your help.
"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:
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?