Author Topic: Any READABLE example of USB code for STM32F0xx or equivalent... ?  (Read 3719 times)

0 Members and 1 Guest are viewing this topic.

Offline L1L1Topic starter

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gr
Hi folks,

I've been programming Cortex-M0 chips for the past year in C, mainly STM32F0xx and SAMD21.
As part of learning how to use these microcontrollers, at first I like to skip using the HAL libraries provided by manufacturers and program registers directly. I often read the actual code of the manufacturer HAL libraries and compare it with the docs, before writing my own "simplified" version of these functions.

I've happily applied this approach to GPIO, ADC, Interrupts, CANbus, I2C, SPI, etc. But I haven't manage to extend it to USB, for example for USB CDC serial implementation. The manufacturer libraries are a mess of abstraction with layers of callbacks. The documentation is usually unclear.

Does anyone know of a simple example of USB code (preferably for CDC) for the STM32F0xx, SAMD21 or some relative? Something that a human can read?

Regards, Alain
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11236
  • Country: us
    • Personal site
Re: Any READABLE example of USB code for STM32F0xx or equivalent... ?
« Reply #1 on: July 14, 2017, 06:43:47 am »
HID for SAM D21 - https://github.com/ataradov/dgw/tree/master/embedded

CDC is coming in the next few days, I'm working on it at the moment.
Alex
 
The following users thanked this post: chickenHeadKnob

Offline L1L1Topic starter

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gr
Re: Any READABLE example of USB code for STM32F0xx or equivalent... ?
« Reply #2 on: July 16, 2017, 06:39:29 am »
HID for SAM D21 - https://github.com/ataradov/dgw/tree/master/embedded

CDC is coming in the next few days, I'm working on it at the moment.

Many thanks! I started looking through your code: so far it seems much easier to follow than other stuff I'd seen previously.  :-+
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11236
  • Country: us
    • Personal site
Re: Any READABLE example of USB code for STM32F0xx or equivalent... ?
« Reply #3 on: July 16, 2017, 06:42:12 am »
Here is CDC for D11 - https://github.com/ataradov/vcp . It will work on D21 with minor effort as well.

The code is pretty minimal. USB peripherals in most MCUs suck, since they are designed by hardware people, who have no clue about programming.

PS: It was just finished, so bugs are quite possible.
« Last Edit: July 16, 2017, 07:08:16 am by ataradov »
Alex
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Any READABLE example of USB code for STM32F0xx or equivalent... ?
« Reply #4 on: July 16, 2017, 10:30:46 pm »
Nice.  I've bought a couple of https://hackaday.io/project/10210-dixi-arduino-sam-d11-usb-stick and have been a bit depressed because the Arduino support is so bloated (9k for Blink, including the CDC code, out of 12k available post-bootloader.  Most of that is the CDC implementation.)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf