Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32Cube USB VCP #38

Open
Tyrn opened this issue May 19, 2022 · 9 comments
Open

STM32Cube USB VCP #38

Tyrn opened this issue May 19, 2022 · 9 comments

Comments

@Tyrn
Copy link

Tyrn commented May 19, 2022

Hi,

Is there any experience with MIN protocol outside Arduino? I'm having trouble adapting it to the middleware supplied by STM32CubeIDE. Shouldn't be too difficult; unfortunately, I'm a newbie.

Sorry, I did some Google research, didn't find anything.

@kentindell
Copy link
Collaborator

Yep, used extensively on a PyBoard (STM32F405) with USB VCP. Also used on an RP2040 Raspberry Pi Pico with USB. Check out this video:

https://youtu.be/o2vqKgQ-v1k

Source code for the MicroPython firmware changes:

https://github.com/kentindell/canhack/tree/master/pico/micropython

@kentindell
Copy link
Collaborator

The monitor framework has been used to build the CANPicoCtrl GUI: the host is all in Python, talking to the Pico, with its monitor in Python.

https://kentindell.github.io/2022/05/11/canpicoctrl/

The monitor software for host and target is included in the branch mincan in this repo:

https://github.com/min-protocol/min/tree/mincan

I'll merge this and tidy everything up when I've got the Linux implementation super robust (right now the pyserial hangs on close() if there's a write timeout, so I'm changing the discovery of a monitor to a ping, with a timeout). The framework should be very useful for anyone wanting to do command/response from a host app.

@Tyrn
Copy link
Author

Tyrn commented May 19, 2022

Oh, how nice of you! Thanks!

@Tyrn
Copy link
Author

Tyrn commented May 19, 2022

Yep, used extensively on a PyBoard (STM32F405) with USB VCP.

Are there any public repositories with this?

@kentindell
Copy link
Collaborator

No, but it's obsolete compared to the Pico implementation using TinyUSB.

@Tyrn
Copy link
Author

Tyrn commented May 19, 2022

I have to manage STM32F103C8T6 using STM32CubeIDE.

@kentindell
Copy link
Collaborator

Take a look at how MIN is stitched in to the MicroPython Pico framework: it doesn't touch anything but the callbacks, and if your IDE has USB support it should be straightforward to glue it together in a similar way.

@Tyrn
Copy link
Author

Tyrn commented May 23, 2022

I'm overwhelmed, actually :(

usbd_cdc_if.c suggests its own set of callbacks and nothing else whatever, which I have no idea how to marry with half the MIN callbacks.

A Cube version of sketch_echo

@kentindell
Copy link
Collaborator

If you look in rp2_min.c you'll see a couple of static functions: usb_write and usb_read. These push bytes to/from USB. In the Pico case, it uses the TinyUSB library that's instantiated by MicroPython (the Pico SDK has TinyUSB support too, and I guess the STM32 SDK also does, so it will look similar).

The MIN callbacks are also in there: min_tx_space just says "yeah, 1K free", min_tx_byte pushes a byte into a local buffer, min_tx_start clears the local buffer, and min_tx_finished pushes the local buffer into TinyUSB (via the local push function).

The function min_poll is called from the Python recv() code, which pulls the bytes from the USB drivers, which is how MIN is driven.

The interesting callback is min_application_handler, which in this case creates a bunch of Python objects on the heap to pass into Python-world. But that's where your application code would go to handle incoming MIN frames.

MIN is entirely polled, so no interrupts. And the TinyUSB interface is polled too (there are interrupts in the background that feed the USB API but I don't go anywhere near those and let MicroPython deal with it all).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants