Giter VIP home page Giter VIP logo

usblibrarystm32's Introduction

USBLibrary for stm32

PlatformIO Registry

This library adds a very basic implementation of the original AVR Arduino USB API to make existing libraries compatible with stm32 boards running the STM32Duino core. Caution, this library is very beta and most likely not suited for production code unless you make sure to test it thoroughly!

STM32F103 is currently working with only minor bugs and STM32F4xx support is being worked on. The goal is to eventually get all 5 usb implementations of STM32 working and to merge it back into the main STM32duino core.

Features

At this moment the library has the following features:

  • USBAPI implementation
  • PluggableUSB implementation (with added runtime plugging)
  • HID library implementation (with small fix on sending)

What can you do with this?

  • Use a (or multiple) Virtual serial port(s) over USB together with all the other connections => usbcomposite can't do this!
  • Use the original Keyboard and Mouse libraries from Arduino
  • Use a Joystick library like ArduinoJoystickLibrary (my favorite)
  • Use the MIDIUSB library to act as MIDI device
  • Use any other HID/PUSB library if they are compatible

What can't i do with this/what is different?

  • I havent had time to test all libraries except the ones mentioned above, if you want to see a library tested let me know.
  • You need to call an extra method in Setup for now, until i find a proper solution. e.g. USB_Begin();
  • Non STM32F103 chips are not supported yet, due to issues with the underlying stm code of stm32duino, this will be the focus of the next revision

Testing/supported

I currently test these libraries:

  • A custom pluggable SerialUSB library for stm32
  • Mouse and Keyboard libraries made by Arduino
  • ArduinoJoystickLibrary
  • MIDIUSB (needs extra build flag, might not be compatible with other libraries => look at the sample)

On these boards:

  • STM32F103 Blue pill
  • STM32F103 Black pill (clone)
  • CH32F103 Blue pill (chinese clone)

Installation Instructions per project

  • Include the library via platformio or Arduino IDE
  • Add -D USBCON and -D HAL_PCD_MODULE_ENABLED to your build flags
  • Initialise Keyboard/Mouse/Serial
  • Call USB_Begin(); in your Setup
  • Optionally also call while (!USB_Running()){ delay(50); } in your setup if you want to wait until the device actually has an usb connection, otherwise make sure to check USB_Running() before calling any usb methods!
  • Initialise joystick library
  • Do NOT include the builtin usb-composite Keyboard or mouse libraries, if you want to use mouse or keyboard include the Arduino libraries instead

Installation in core one-time (mandatory)

Warning, this is needed to use this library but will change the core to not use the builtin usb library anymore, this means any existing projects cant use usbcomposite until you uninstall again

  • Go to %USERPROFILE%\.platformio\packages\framework-arduinoststm32\cores\arduino\stm32\usb
  • Delete all files in the folder
  • Download usbd_conf.h, usbd_desc.h, usbd_ep_conf.h and usbd_if.h
  • Place the 4 files in the usb directory

Uninstallation from core

To revert the previous changes just delete the entire %USERPROFILE%\.platformio\packages\framework-arduinoststm32 folder, platformio will download a new one and it will ensure everything is back to default.

Examples

Examples can also be copied from the examples folder on github

Simple example

Example with ArduinoJoystickLibrary

#include <Joystick.h>

// Create the Joystick
Joystick_ Joystick;

// Constant that maps the physical pin to the joystick button.
const int pinToButtonMap = 9;

void setup() {
	// Initialize Button Pins
	pinMode(pinToButtonMap, INPUT_PULLUP);

	//Initialise USB !IMPORTANT!
	USB_Begin();

	// Initialize Joystick Library
	Joystick.begin();
}

// Last state of the button
int lastButtonState = 0;

void loop() {

	// Read pin values
	int currentButtonState = !digitalRead(pinToButtonMap);
	if (currentButtonState != lastButtonState)
	{
	Joystick.setButton(0, currentButtonState);
	lastButtonState = currentButtonState;
	}

	delay(50);
}

Why is this not in the core yet?

This is still code in testing, and while it works well on the tested libraries i want to improve the resource usage some more before this could be a valid alternative for the existing functionality, if you want to help me do that, help is very much welcome.

usblibrarystm32's People

Contributors

levi--g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usblibrarystm32's Issues

which MIDIUSB library needed?

Hello!
I'm trying to set up MIDIUSB using the following official core:

[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino

However MIDIUSB.h is needed. Can you please share which version will work with your library?
I tried adding MIDIUSB by Gary Grewal buy it won't compile:
#error MIDIUSB can only be used with an USB MCU.

I'd be grateful for your guidance!
Thanks for making this possible, very excited to enjoy the USB midi with the official core!

STM32F401 Black Pill SerialUSB + Joystick

Hello there, still me.

After succeeding implementing both SerialUSB and custom HID with Joystick library on a F103, I am here to ask if it is possible in any way for you to help me unlocking this possibility also on the better performing and more reliable F401 Black Pill.

Let me attach some info here..
I am running your library on the latest Platformio release, and this is the .ini file config I'm attempting to use.

`[env:genericSTM32F401CD]
platform = ststm32
board = genericSTM32F401CD
framework = arduino

build_flags = 
    ;-D USBD_REENUM_DISABLED
    -D USBCON
    -D PLUGGABLE_USB_ENABLED
    -D USBD_USE_HID_COMPOSITE
    -D USBD_VID=0x0CD4
    -D USBD_PID=0x1010
    '-D USB_PRODUCT_STRING="Custom Handbrake"'

lib_deps = 
    levi--g/USBLibrarySTM32@^0.2.0
    mheironimus/Joystick@^2.1.1
    thomasfredericks/Bounce2@^2.72`

But attempting to compile the same code which works flawlessy on a Blue pill, the compiler gives me the following attached errors..

Is there anything I can do to solve this? Or could you help in any way?

Thank you so much in advance, your support has already proven to be unvaluable!

F401 Serial and HID

Custom pluggable SerialUSB library?

First of all thank you for this amazing library which is allowing me to program my Blue Pills as game peripherals through Platformio. Can't say how much I apreciate it.

I am here to ask if it is possible in any way to add the Serial over USB functionality on top of the Game Peripheral HID.
I really need my application to send some Serial messages through USB, but I can't find any reference to the "Custom Pluggable SerialUSB library" you mentioned in your description.

Can you please help me getting this to work?

Using Joystick Libary with SerialUSB Communication

Thank you for hard working, i tried to use SerialUsb method but device didn't recognize by windows.
Also tried to use only FFB libary but i got some error.
I am making mistake or not yet supporting those features?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.