USB CDC serial communication example

Altusir
Posts: 5
Joined: Sun Mar 05, 2023 9:28 pm

USB CDC serial communication example

Postby Altusir » Mon Apr 03, 2023 6:48 pm

Hello,

I'm a bit new to the whole IDF universe and making my first babysteps.

So working with the IDF was mandatory as I'm currently experimenting with some peripherals.

After getting to know how to create the necessary business logic I'm currently facing the problem with communicating as USB peripheral to my Macbook. Setup: Wemos Lolin S2 Mini with a VS Code Espressif IDF setup and IDF 5.0.1 with the setting Component config > ESP System Settings > Channel for console output > USB CDC for the feedback of the controller.

Now I wanted to improve my code to be able to receive commands via USB, so I added the console snippet (with linenoise) from the docs to receive commands via the VS Code serial monitor (aka. idf_monitor.py). This works very fine.

But now I wanted to improve my code and add communication via a self written tooling in golang. Every code I'm using on the internet does not show the results or stability as sending commands via the idf_monitor.py and using the esp_console.h. Does someone here have some examples or ressources for the communication between a usb cdc idf esp32 and some code on a pc/mac? Or at least some helping hints?

I don't stick to golang, as I'm currently just trying to get it work.

This is my current setup: https://github.com/mrkwenzel/esp-idf-go ... b130228706

The only thing to get it work is using Arduino like implementation as here https://gist.github.com/lroman242/e38f1 ... 43739c55ee but I want to use peripherals as the hmac perhipheral described like here: https://docs.espressif.com/projects/esp ... -reference

The idea is to send a message to the esp32 and receive the calculated result. And this over and over.

//Edit: Maybe this needs to be moved to IDF?

Altusir
Posts: 5
Joined: Sun Mar 05, 2023 9:28 pm

Re: USB CDC serial communication example

Postby Altusir » Wed Apr 05, 2023 2:41 pm

Ok now i tested tinyusb and it provided me some interesting results. At least i got my gen joke command stable.

ESP Code: https://github.com/mrkwenzel/esp-idf-go ... ice_main.c
golang Code: https://github.com/mrkwenzel/esp-idf-go ... al/main.go

Output: https://gist.github.com/mrkwenzel/5ae64 ... 8203060a67

So the random code is not stable. Any idea how to get it stable? And also how to flash the esp32 even with tinyusb enabled?

Altusir
Posts: 5
Joined: Sun Mar 05, 2023 9:28 pm

Re: USB CDC serial communication example

Postby Altusir » Fri Apr 07, 2023 5:50 pm

Ok, so now I got the most stable way:

ESP32: https://github.com/mrkwenzel/esp-idf-go ... m_device.c
go: https://github.com/mrkwenzel/esp-idf-go ... ain_1st.go

The only things I'm missing:
1) How can I read arguments? Like I want to send "GENRAND124" and receive "SAS<256 Bit random>124KIA" as 124 is something like a checking number. How can i achieve something like this?
2) How can I flash the ESP32S2 using UART and the same port? With tinyusb enabled I have to set it to DFU when flashing a new version. Without tinyusb it was possible to flash the esp32s2 without turning into DFU
3) esp_tusb_init_console does not redirect ESP_LOGI or fprintf as I don't receive the strings in my golang buffer. What am I doing wrong?

Who is online

Users browsing this forum: No registered users and 86 guests