stm32duino core with System Workbench for bluepill

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
Post Reply
User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

stm32duino core with System Workbench for bluepill

Post by Rick Kimball » Thu Apr 28, 2016 7:14 pm

[Note: since I first wrote this post, openstm32.org has released customized versions of eclipse for windows, linux and os/x. Those binaries are bundled with their plugin and other enhancements. It is best to download the latest version from http://www.openstm32.org ]

I put together our stm32duino core as an importable eclipse project. It is based on using the http://www.openstm32.org System Workbench eclipse plugin. My approach is different than what most people do, this setup isn't using the Arduino Plugin. The required defines, and include paths, and executable paths are just set in the eclipse project properties. This project configuration might give you a quick start template for using a bluepill board and an stlink dongle with bare metal eclipse using the stm32duino arduino core. I've included a recent snapshot of the master github tree and made a few source code tweaks. The example "sketch" is in src/asciitable.cpp.

I've made a few assumptions. I assume you are using linux. I expect you to have a working Arduino 1.6.x with the arm-none-eabi-gcc installed. I assume you have eclipse mars installed along with the System Workbench for STM32 from the openstm32.org website. I assume you are using a red or blue pill stm32f103 board that uses the PA12 1.5k pull up resistor. I'm assuming you are going to program it using an Stlink V2 dongle, either the ebay clone, a real one stlink, or a discovery board wired to program an external board (the bluepill).

Just use the menu File/Import... select the General tab and the second selection item named "Existing Project into Workspace". On the Import Dialog, click the "Select archive file:" radio button and select the bluepill.zip from the directory where you saved the file below

Then a quick build and debug should get you going.

If this get sufficient interest I'll write more about it.

I put the archived project in bluepill.zip in a gist as it is too big to attach directly here:

https://gist.github.com/RickKimball/aa7 ... uepill.zip

https://gist.github.com/RickKimball/aa7 ... 0b8f92eba9

-rick

Running Debug and looking at the GPIO registers:
debug_01.gif
debug_01.gif (113.7 KiB) Viewed 2318 times
Last edited by Rick Kimball on Mon Apr 03, 2017 1:53 pm, edited 11 times in total.
-rick

User avatar
Slammer
Posts: 252
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: Eclipse importable bluepill

Post by Slammer » Thu Apr 28, 2016 8:47 pm

Very nice....
I like this way of development!

User avatar
Slammer
Posts: 252
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: Eclipse importable bluepill

Post by Slammer » Thu Apr 28, 2016 11:44 pm

I just used your project to build a simple blink program.
The build is OK but when I am trying to Debug the program I have the following error:

Code: Select all

Error: timed out while waiting for target halted
TARGET: stm32f1x.cpu - Not halted
in procedure 'program' 
in procedure 'reset' called at file "embedded:startup.tcl", line 478
in procedure 'ocd_bouncer'
I am using ST-Link V2.... Have you any idea about it?

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Eclipse importable bluepill

Post by Rick Kimball » Fri Apr 29, 2016 12:26 am

If you used the Arduino IDE to load files without using the STLINK or BMP method, then you probably disabled the debug pins and made them GPIO pins accidentally.

You can force the bluepill to work with the stlink by switching the boot0 jumper from the default position of '0' to the boot0 '1'. Then press reset so the chip can see the new boot0 configuration and then try again. Make sure you kill the stalled debug session in eclipse. If that works and you can successfully upload, you can switch the boot0 jumper back to '0'.

-rick
Last edited by Rick Kimball on Fri Apr 29, 2016 1:42 am, edited 1 time in total.
-rick

zmemw16
Posts: 1449
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Eclipse importable bluepill

Post by zmemw16 » Fri Apr 29, 2016 1:08 am

i've installed eclipse mars cdt via the installer, installed the workbench from inside eclipse; it needed a restart and then installed gcc and openocd itself.
i pulled the bluepill.zip

i'm as usual for me, missing something.
i can select the bluepill.zip file, but i can't seem to set the directory for the archive import destination. it has a browse button that just give 3 i assume grayed out very small home, up and into buttons???

i then tried creating an empty bluepill project, now it allows selection of workspace/bluepill as a destination folder,
but i now have a project top dir bluepill with a child dir bluepill holding the rest.

i'm not totally convinced i have the correct bluepill.zip, mainly because i can't find the blink sketch and it looks more like the jc66_coreboard directory structure and files.

if you could confirm the following?

Code: Select all

stephen@i7:~$ ls -l bluepill.zip                                                                                                 
-rw-r--r-- 1 stephen stephen 3841736 Apr 28 20:20 bluepill.zip                                                                
stephen@i7:~$                                                                                                                 
stephen@i7:~$ md5sum bluepill.zip
f2fdced2541e91604b28d85ff44aaa45  bluepill.zip
stephen@i7:~$ 
stephen@i7:~$ cd Workspace/bluepill/bluepill/src
stephen@i7:~/Workspace/bluepill/bluepill/src$ ls -l
total 12
-rw-r--r-- 1 stephen stephen 1070 Apr 28 13:05 asciitable.cpp
-rw-r--r-- 1 stephen stephen   65 Apr 28 12:30 extra.c
-rw-r--r-- 1 stephen stephen 2727 Apr 28 08:06 streaming.h
stephen@i7:~/Workspace/bluepill/bluepill/src$ 
i think you did the BMP with a bluepill?

have i accidentally got the wrong zip file as well?

just been back to the gist, details are the same as above once extracted!


stephen

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Eclipse importable bluepill

Post by Rick Kimball » Fri Apr 29, 2016 1:18 am

You need to make sure you do a File/Import ... "Existing Project into Workspace" It is the second selection under General. This will create a new project entry in your workspace. The first selection "Archive File" only works with an existing project and would act as you have described. Note the attached animated images:
import_sequence.gif
import_sequence.gif (109.19 KiB) Viewed 2291 times
I've been testing with a chinese stlink clone. I just downloaded and tested the first zip file and it seems to work fine. However, it looks like I had uploaded a sample that does an asciitable.cpp sketch. This is actually problematic as a demo. You need to set the first breakpoint past the USBSerial connection to have it enumerate. Timing seems to be an issue with regard to using the USBSerial.

You might want to replace the asciitable.cpp with this:

Code: Select all

const int led = PC13;

void setup(void) {
	pinMode(led,OUTPUT);
	digitalWrite(led,1); // turn led off
}

void loop(void) {
	digitalWrite(led,0); // turn led on
	delay(100);
	digitalWrite(led,1); // turn led off
	delay(900);
}
Sorry for the confusion:

-rick
Last edited by Rick Kimball on Fri Apr 29, 2016 12:13 pm, edited 4 times in total.
-rick

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Eclipse importable bluepill

Post by Rick Kimball » Fri Apr 29, 2016 2:14 am

If you did want to successfully debug the asciitable.cpp that is using USBSerial, you might want to look at my debug session.
debugsession.gif
debugsession.gif (224.16 KiB) Viewed 2285 times
There are 4 windows of interest on this page.

1. The Eclipse Application, running in the Debug Perspective.
2. The Debug Configuration Dialog ( Note I pulled this up to show you what I changed, I already clicked "Debug" by the time this screen was snapped)
3. An xterm running $ screen /dev/ttyACM0 (The USBSerial on the bluepill is ttyACM0)
4. An xterm running # tail -f /var/log/syslog

To get to this point you need to do a few things:

o The first thing to change is the "Debug Configuration for the bluepill.elf. See the yellow highlighted area in the "Debug Configuration" dialog box. I changed the default breakpoint from "main" to "setup". However, because we are using USBSerial, it is best to set a breakpoint after it has enumerated and the host has connected. So I disabled the first breakpoint by unchecking the "Set breakpoint at:" in that dialog.

o The second step is to open the asciitable.cpp file and set a breakpoint at line 22. I have highlighted that in yellow also. To set a breakpoint you position the cursor on the line number and double click. That will set it. If you double click again it disables the breakpoint. Once you have the breakpoint at line 22 you can then start to Debug.

o Once you start the debug session you can watch the window running the tail of the syslog. You should see it enumerate /dev/ttyACM0. If it gives you any kinds of errors you may have to Terminate the debug session, unplug and replug the bluepill and try to debug again. If all goes well and it enumerates, it will be waiting for some host program to connect to /dev/ttyACM0.

o In the final xterm window,run:
$ screen /dev/ttyACM0
This will then show the output of the asciitable.cpp code. You can use the step commands to walk through each statement to monitor and inspect what is going on. When it is complete you can kill the screen window using CTRL-A K. (CTRL-A is the screen escape, K is short for kill, to see what you can do type CTRL-A ?)
Note: I have the optimization set to -Os (small code). If you want to be able to view program variables without resorting to looking at the registers, you might want to left click on the top of the project, and then right click to change the Settings for optimization for C and C++ (they are set independently ) recompile and relaunch.

-rick
-rick

User avatar
Slammer
Posts: 252
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: Eclipse importable bluepill

Post by Slammer » Fri Apr 29, 2016 11:06 am

As I can see, AC6 Workbench includes gcc 5.2.1 as default compiler :!:

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Eclipse importable bluepill

Post by Rick Kimball » Fri Apr 29, 2016 11:17 am

Slammer wrote:As I can see, AC6 Workbench includes gcc 5.2.1 as default compiler :!:
True. However, the way I have the project settings, it should be using the gcc from .arduino15
-rick

User avatar
Slammer
Posts: 252
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: Eclipse importable bluepill

Post by Slammer » Fri Apr 29, 2016 11:36 am

Yes, I saw it. With 5.2.1 the binary is almost 2KB smaller :!:
Anyway I am making some more tests to see what is different....

Post Reply