Generic Serial Driver. This module implements a generic full duplex serial driver. The driver implements a SerialDriver interface and uses I/O Queues for communication between the upper and the lower driver. Event flags are used to notify the application about incoming data, outgoing data and other I/O events.
This is my example code for the STM32F4 Discovers using the RTOS ChibiOS.
requirements
- Chibios 2.5.0+ (or a recent development snapshot)
- arm toolchain (e.g. arm-none-eabi from summon-arm)
features
- serial over USB console
- PWM initialization and control
- ADC measuring, continuous and single scan
- background blinker thread
- code structured into separate files
usage
- edit the Makefile and point 'CHIBIOS = ../../chibios' to your ChibiOS folder
- make
- connect the STM32F4 Discovery with both USB connectors
- flash the STM32F4: st-flash write build/ch.bin 0x8000000
- use your favorite terminal programm to connect to the Serial Port (/dev/ttyACM0 for me, probably COM1 on Windows)
console commands
- help
- exit
- info
- systime
- mem
- threads
- toggle 1/2/3/4 (toggles #led, short: t)
- blinkspeed #speed (changes blinker period to #speed ms, short: bs)
- cycle #duty (changes the duty cycle of PWM1 to #duty, short: c)
- ramp #from #to #step [delay] (creates a ramp for PWM1 with the given parameters, short: r)
- measure (measures 16384 analog samples on pin PC1 and prints the first and the average, short: m)
- measureAnalog (measures 16384 samples and converts the average to Volts, short: ma)
- measureDirect (measures 16384 samples and prints them all, short: md)
- measureContinuous (starts a background analog conversion, short: mc)
- readContinuousData (prints what has been collected by the background conversion, short: rd)
- stopContinuous (stops the analog conversion, short sc)
disclaimer
Neither am I a good C programmer nor do I have extensive knowledge aboutChibiOS, the STM32F4 or uCs in general. I wrote this code to make myselffamiliar with the STM32F4 Discovery and I figured ChibiOS was a usefull tool.From my POV the code is not that bad, but your opinion may differ. Inthat case, please don't laugh at my code but provide constructive criticism.I just realized: I'm no pro at Git, Github and Markdown either...
Since I started from the USB-CDC code example from ChibiOS which is GPLv3,I think I am forced to release this code under GPLv3 though I don't care what you dowith the code. I asked Giovanni and he said 'there is not much meat' in it anyways.
Introduction
This is a small example application that uses the HID (Human InterfaceDevice) class to communicate over USB.
This project is based on ChibiOS real-timeoperating system and is designed to run on theOlimexSTM32-E407 board. Itshould work with only minor modifications on other STM32 boardssupported by ChibiOS.
On the client side, a small client uses the HIDRAW interface of theLinux kernel to communicate with the board.
In this example, two HID reports are defined:
- IN report (board->PC): 2 bytes
- First byte: a sequence number
- Second byte: the state of the WKUP pushbutton
- OUT report (PC->board): 2 bytes
- First byte: a sequence number
- Second byte: the state of the green LED
Two interrupt USB endpoints (one IN and one OUT) are used.
How to run
Prerequisites
You first need to download the latest version of the stable 2.6.xbranch of ChibiOS.
Board
The code for the board is in the directory
stm32-e407
.To compile it you first need to modify the
Makefile
. Modify thefollowing line:to point to the directory containing the sources of ChibiOS.
Then, just type
make
and the result image to program to theSTM32-E407 board is build/ch.elf
.Client (Linux)
The code of the Linux client is in the directory
linux-client
.Just type
make
to compile the client.Run
- Download the image to the STM32-E407 board
- Plug a USB cable into the OTG2 mini-USB socket of the board
- Find the corresponding
hidraw
device that was created (example/dev/hidraw3
) - Launch the client:
test-usb-hid /dev/hidraw3
- Each time the WKUP button of the board is pushed, the green LED should toggle