Page 1 of 2
Example code for STM32F4 Discovery
Posted: Mon Jul 02, 2012 2:31 pm
by Mathias
In the last week or so I've been experimenting with the STM32F4 Discovery board. I'm using the latest ChibiOS SVN version, since I use the USB-CDC code to communicate with the board.
features- serial over USB console
- PWM initialization and control
- ADC measuring, continuous and single scan
- background blinker thread
- code structured into separate files
- everything controllable from the console
Maybe someone finds this usefull.
git repository:
https://github.com/Mathias-L/STM32F4-Discovery-example-code.gittarball:
https://github.com/Mathias-L/STM32F4-Discovery-example-code/tarball/masterDisclaimer: I'm no expert in anything: Not C, not ChibiOS, not microcontrollers, not Git/Github, ... so most code is pretty simple or maybe even bad code/style. Feel free to criticise anything you want.
Also: Since I'm using a development build of ChibiOS and it was derived from the USB-CDC sample, this code has probably to be licensed under GPLv3. I don't care what you do with the code, but the licence is still GPLv3 until the next stable release ships and the testhal is released under a liberal license...
Re: Example code for STM32F4 Discovery
Posted: Tue Jul 03, 2012 4:17 pm
by jscott
Good example!! Thanks!
I have been trying to get things going on my STM32f4 explorer, but have been stumbling over the documentation.
You hit on most of the things I have been struggling with getting working.
So far I have been playing with a port to the Arduino, but that is just a stepping stone. I have much bigger plans...
I am still trying to find the "right" tool chain for my use. I am using IAR now, but looking at COOCOX.
Sooo many details to get started, and you have gotten me off to a good start.
Thanks
-John
Re: Example code for STM32F4 Discovery
Posted: Wed Jul 04, 2012 10:55 pm
by pito
Mathias, red and green lit, the blue led blinks..
Most probably I need a microusb connector in order to connect the usb console
P.
Re: Example code for STM32F4 Discovery
Posted: Thu Jul 05, 2012 2:04 pm
by Mathias
Youre right pito, you need a microUSB connector for the usb console, however if you have a serial to USB adapter it should be pretty straightforward to exchange the USB console for a serial UART one. If you want I can have a look into doing that optionally.
@jscott: Youre probably on Windows right? I can't help you there with the toolchain, but there seem to be quite a lot of prebuild toolchains. After all, every arm-none-eabi or similar should work. And unless your IDE provides it, you probably need a build environment like cygwin with make and similar tools too...
Re: Example code for STM32F4 Discovery
Posted: Thu Jul 05, 2012 8:25 pm
by jscott
Yes, I am on Windows. Most of my pain has been trying to get Eclipse integrated and working.
I have given up for now and am just using the command line with the yagarto toolchain.
That should work fine until I need to do some serious debugger.
I got you example up and running yesterday, and have already started to make some changes
to it to suit my purposes.
I am getting back into some of my robotics projects after a distraction into html/css/js land.
Thanks to everyone!!
-John
Re: Example code for STM32F4 Discovery
Posted: Fri Jul 06, 2012 6:38 am
by pito
Mathias, I am a "wireless" fan so I am using cheap BT modules with my dev boards

.
I redirected the usb to serial, and it works (even I have to get familiar with it a little bit)..
Maybe adding SDIO to log the maesurements on an sdcard would be nice to have

(since I am still coping with the SDIO testhal demo

)..
Code: Select all
ch> help
Commands: help exit info systime mem threads toggle t blinkspeed bs cycle c ramp r measure m measureAnalog ma vref v temperature te measureDirect md measureContinuous mc readContinuousData rd stopContinuous sc
ch> threads
addr stack prio refs state time
20000948 20000764 64 1 SLEEPING 0
20000998 20000A0C 1 1 READY 38577
200119F8 20011B04 64 1 SLEEPING 0
200010B0 20001834 64 1 CURRENT 6
ch> measure
Measured: 3744 14553
ch> mem
core free memory : 42064 bytes
heap fragments : 0
heap free total : 0 bytes
ch> temperature
No Background conversion running
ch> mc
ch> measureAnalog
Continuous measurement already running
ch> vref
VREFmeasured: 26784
VREFInt: 1.21V
ch>
Re: Example code for STM32F4 Discovery
Posted: Fri Jul 06, 2012 10:16 am
by Mathias
Youre using a BT to Serial adapter and redirected the console to serial ports right?
I don't have an SD card slot, so I can't test the SDIO Demo or anything with it.
I should have also written, that the analog measures are done on PC1, so you should probably put a potentiometer on 3V, PC1 and GND.
Re: Example code for STM32F4 Discovery
Posted: Fri Jul 06, 2012 10:45 am
by pito
Yes, I redirected the console to the serial port (pins pa2, pa3). My BT is a small module which has serial i/o (up to 1.3Mbit/s).
p/
Re: Example code for STM32F4 Discovery
Posted: Thu Jul 26, 2012 11:15 am
by gentijo
Hi,
I am trying to compile this project but I am getting a link error missing the syscalls stubs..
I found another article pointing to a stubs project on github but it appears to be a dead project.
Are there any other pointers out there to code / settings that will satisfy the linker error ?
Thank you
John Gentilin
/opt/yagarto-4.7.1/bin/../lib/gcc/arm-none-eabi/4.7.1/../../../../arm-none-eabi/lib/thumb/v7m/libc.a(lib_a-abort.o): In function `abort':
/Users/mfischer/Projects/yagarto/newlib-build/arm-none-eabi/thumb/v7m/newlib/libc/stdlib/../../../../../../../newlib-1.20.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/opt/yagarto-4.7.1/bin/../lib/gcc/arm-none-eabi/4.7.1/../../../../arm-none-eabi/lib/thumb/v7m/libc.a(lib_a-signalr.o): In function `_kill_r':
/Users/mfischer/Projects/yagarto/newlib-build/arm-none-eabi/thumb/v7m/newlib/libc/reent/../../../../../../../newlib-1.20.0/newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/opt/yagarto-4.7.1/bin/../lib/gcc/arm-none-eabi/4.7.1/../../../../arm-none-eabi/lib/thumb/v7m/libc.a(lib_a-signalr.o): In function `_getpid_r':
/Users/mfischer/Projects/yagarto/newlib-build/arm-none-eabi/thumb/v7m/newlib/libc/reent/../../../../../../../newlib-1.20.0/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
collect2: error: ld returned 1 exit status
make: *** [build/ch.elf] Error 1
Re: Example code for STM32F4 Discovery
Posted: Thu Jul 26, 2012 11:22 am
by Mathias
Are you able to compile other examples in the Testhal?