cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC library for stm32f042k6t6

Moamen Ayman
Associate III
Posted on July 29, 2017 at 11:52

Hello, I am trying to use stm32f042k6t6 MCU and I want to use the USB peripheral implemented in it. Could someone suggest me a USB CDC library I can use with this MCU to connect with PC, I am using the standard peripheral libraries from ST so I am looking for a compatible CDC library. 

Thanks in advance.

6 REPLIES 6
Moamen Ayman
Associate III
Posted on July 29, 2017 at 17:21

I am trying to port this library to my IAR project and use the CDC library:

https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries-expansions/stsw-stm32092.html

 

I got many errors so what is the right functions to send data, receive data and get USB status?

Posted on July 29, 2017 at 22:42

Hello!

Yes you are right! errors.

There is a good solution for making your USB functional.

Try the

https://my.st.com/content/my_st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

with HAL OR/AND LL drivers.

This is not like StdPeriph_Driver but is compatible with IAR EWARM  and has also functional examples.

Moamen Ayman
Associate III
Posted on August 01, 2017 at 18:55

Turvey.Clive.002

Moamen Ayman
Associate III
Posted on August 01, 2017 at 19:01

Palmer.Randall

Posted on August 01, 2017 at 18:54

Thanks Vangelis for your reply but I built the whole project based on the standard peripheral libraries so I want to use STSW-STM32092

library

this my code, I just want to initialize the CDC library and if any data received from the host, I send it back. does my code right?

♯ include 'usbd_cdc_core.h'

♯ include 'usbd_usr.h'

USB_CORE_HANDLE USB_Device_dev ;

extern USBD_Class_cb_TypeDef USBD_CDC_cb;

int main(void)

{

USBD_Init(&USB_Device_dev, &USR_desc, &USBD_CDC_cb, &USR_cb);

char data = 0;

void *x = 0;

USBD_CDC_cb.Init(x, 1);

while (1)

{

if(USBD_CDC_cb.EP0_RxReady(x) == 1)

{

USBD_CDC_cb.DataIn(x, data);

USBD_CDC_cb.DataOut(x, data);

}

}

}

Posted on August 01, 2017 at 20:20

Hello again!

Inside  your USBD_CDC_cb structure  you put some callback functions  like   usbd_cdc_DataIn,  usbd_cdc_DataOut called when the appropriatre endpoind received or transmitted something.

You can not use theese functions by calling them.

Try to send from host , some  characters and observe theese callback functions how to behave.

You can study also the example in STM32F0x2_USB-FS-Device_Lib V1.0.0\Projects\Virtual_COM_Port.