stm32duino core with System Workbench for bluepill

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 3691 times

Slammer
Thu Apr 28, 2016 8:47 pm
Very nice….
I like this way of development!

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:
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'

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


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?
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$


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 3664 times

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 3658 times

Slammer
Fri Apr 29, 2016 11:06 am
As I can see, AC6 Workbench includes gcc 5.2.1 as default compiler :!:

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 :!:

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….

Rick Kimball
Fri Apr 29, 2016 11:42 am
Did you successfully debug with stlink?

Slammer
Fri Apr 29, 2016 11:50 am
Yes! I did it… thank you.
I am trying to make the HALMX version now….

Rick Kimball
Fri Apr 29, 2016 3:06 pm
There is an annoying bug when running eclipse and the AC6 System WorkBench plugin on Ubuntu. The normal way to access the “Properties” dialog to make changes to the C/C++ Builder / Settings is to right click on the project in the Project Explorer. However, when running Ubuntu this will cause a hang for many tens of seconds. In the past, I’ve had problems with other gtk3 based apps so I tried my time honored env settings to solve the problem. I modified my Eclipse.desktop file like this:

[Desktop Entry] Type=Application
Version=0.9.4
Name=Eclipse
Comment=Eclipse Mars 2
Icon=/home/kimballr/opt/eclipse/icon.xpm
Exec=env SWT_GTK3=0 UBUNTU_MENUPROXY=0 /home/kimballr/opt64/eclipse/eclipse -showlocation
Terminal=false
Path=/home/kimballr/
Name[en_US]=Eclipse-Mars2(64bit)


zmemw16
Sat Apr 30, 2016 12:06 am
@rick
any recommendation on following the ‘updates are available’ pop-up?

i was seeing a message related to MaxPermSize as an unrecognized switch, eclipse.ini was modified deleting lines with XXMaxPermSize and the following line for each.

could you detail anywhere string *kimbal* needs to be edited away? i’m a stephen :D
in openocd path as well???

i use a modified 1.6.5r5 where it’s dot dir is arduino165r5, similar for 1.78 etc etc
i ended up using a soft link to my arduino installed arm files and adding ~/stephen/arm to the path in eclipse.
i’m wondering will happen after the updates have installed?

i’m playing with nRF24’s at the moment, adding in their includes as a see what happens, yields ‘not found’ messages.
where/how would i add local user libraries? is there a search path to be amended as well?
the libraries entry under the project lists the standard arduino_stm32 ones.

any tips on how i’d use a maple mini in this setup?
i suppose that using a bluepill programmed as a bmp might prove to be interesting?

you mentioned doing a write up somewhen? yes please.

stephen


Rick Kimball
Sat Apr 30, 2016 4:34 am
zmemw16 wrote:
any recommendation on following the ‘updates are available’ pop-up?

zmemw16
Sat Apr 30, 2016 6:44 pm
i think i need another laptop for screen space! i’m either talking myself into or out of acquiring another, trouble is the price difference between a ‘decent’ i3 and not quite so decent i5 ain’t a lot. now chuck in 8gb and 1tb hard disk.

ok i’ll go off and firtle a bit with this … … …

stephen


Rick Kimball
Sat Apr 30, 2016 9:05 pm
Here is a good overview slideshow of the basics of how to create a project and debug with System Workbench:

http://www.stm32.eu/sites/default/files … ench_0.pdf

-rick


stevestrong
Sun Oct 02, 2016 5:00 pm
I decided to setup a project which enables debugging, and which allows me to build with or without Arduino IDE.
For this, I read about eclipse and I though I will try it out.

Well, it is not that simple because I am working on a Win10 computer.

First, I read about the Eclipse plugin for Arduino. After several unsuccessful tries and errors (two days of pain..) I wanted to give a try to Rick’s project.

@Rick,
After I import the project and adapted the PATH variable to find the “make.exe” now I get the error message:
“make: no rule to make the target”.
Which path should I include now?


Rick Kimball
Sun Oct 02, 2016 5:41 pm
I can’t say on windows, sorry.

RogerClark
Sun Oct 02, 2016 9:20 pm
Steve

You could load linux in a VM.

I know that means doing another install and setup of Eclipse, which can be a pain, but the VM installation of Linux would be simple and quite quick


Rick Kimball
Sun Oct 02, 2016 10:43 pm
stevestrong wrote:First, I read about the Eclipse plugin for Arduino. After several unsuccessful tries and errors (two days of pain..) I wanted to give a try to Rick’s project.

stevestrong
Mon Oct 03, 2016 8:39 am
Rick,
thanks a lot, I finally managed to successfully build the project on my Win10 machine, without Linux VM.

What I did is:
– I followed the steps recommended to install SW4STM32, onto the existing Eclipse installation,
– adapted the paths for GCC (from Arduino directory) and make.exe (from Ac6 plugin directory of Eclipse)

Now I will try to debug…


edogaldo
Thu Oct 06, 2016 8:49 am
Hi Rick, would it be possible to add USB2Serial upload method in your project template? If yes, can you advice for it?

ps: I know that USB2Serial does not support debugging but at the moment I don’t have a ST-Link device and I just need the upload feature..

Thanks in advance and best, E.


Rick Kimball
Thu Oct 06, 2016 1:29 pm
edogaldo wrote: .. would it be possible to add USB2Serial upload method in your project template?

edogaldo
Thu Oct 06, 2016 2:09 pm
Thanks Rick, I’ll try to setup it.

Interesting thing: I tried to compile the bluepill project with the default SW compiler (gcc 5.2.1) and I get error: “conflicting declaration of C function ‘char* utoa(long unsigned int, char*, int)’” on file “itoa.h” where utoa is defined as:
extern char* utoa( unsigned long value, char *string, int radix ) ;


sheepdoll
Thu Oct 06, 2016 3:43 pm
edogaldo wrote:Thanks Rick, I’ll try to setup it.

Interesting thing: I tried to compile the bluepill project with the default SW compiler (gcc 5.2.1) and I get error: “conflicting declaration of C function ‘char* utoa(long unsigned int, char*, int)’” on file “itoa.h” where utoa is defined as:
extern char* utoa( unsigned long value, char *string, int radix ) ;


edogaldo
Thu Oct 06, 2016 4:13 pm
Even with the -nostdlib I get the error:
'Building file: ../cores/maple/WString.cpp'
'Invoking: MCU G++ Compiler'
C:\EDOGALDO\STM32\RickKimball_bluepill\bluepill\Debug
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -DSTM32F103C8Tx -DDEBUG -DVECT_TAB_ADDR=0x8000000 -DGENERIC_STM32F103C -DF_CPU=72000000L -DBOARD_GENERIC_STM32F103C -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG -DSERIAL_USB -D__STM32F1__ -DARDUINO=10605 -DBOARD_generic_stm32f103c -DMCU_STM32F103CB -DGENERIC_BOOTLOADER -DARDUINO_ARCH_STM32F1 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/system/libmaple" -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/system/libmaple/include" -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/system/libmaple/stm32f1/include" -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/system/libmaple/usb/stm32f1" -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/system/libmaple/usb/usb_lib" -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/cores/maple" -I"C:/EDOGALDO/STM32/RickKimball_bluepill/bluepill/variants/generic_stm32f103c" -Os -g3 -Wall -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -ffunction-sections -c -fno-exceptions -fno-rtti -MMD -MP -MF"cores/maple/WString.d" -MT"cores/maple/WString.o" -o "cores/maple/WString.o" "../cores/maple/WString.cpp"
In file included from ../cores/maple/WString.cpp:23:0:
../cores/maple/itoa.h:34:65: error: conflicting declaration of C function 'char* utoa(long unsigned int, char*, int)'
extern char* utoa( unsigned long value, char *string, int radix ) ;
^
In file included from c:\users\EDOGALDO\.p2\pool\plugins\fr.ac6.mcu.externaltools.arm-none.win32_1.7.0.201602121829\tools\compiler\arm-none-eabi\include\stdlib.h:11:0,
from ../cores/maple/WString.h:26,
from ../cores/maple/WString.cpp:22:
c:\users\EDOGALDO\.p2\pool\plugins\fr.ac6.mcu.externaltools.arm-none.win32_1.7.0.201602121829\tools\compiler\arm-none-eabi\include\stdlib.h:185:8: note: previous declaration 'char* utoa(unsigned int, char*, int)'
char * _EXFUN(utoa,(unsigned, char *, int));
^
../cores/maple/WString.cpp: In constructor 'String::String(unsigned char, unsigned char)':
../cores/maple/WString.cpp:74:23: error: call of overloaded 'utoa(unsigned char&, char [9], unsigned char&)' is ambiguous
utoa(value, buf, base);
^
In file included from c:\users\EDOGALDO\.p2\pool\plugins\fr.ac6.mcu.externaltools.arm-none.win32_1.7.0.201602121829\tools\compiler\arm-none-eabi\include\stdlib.h:11:0,
from ../cores/maple/WString.h:26,
from ../cores/maple/WString.cpp:22:
c:\users\EDOGALDO\.p2\pool\plugins\fr.ac6.mcu.externaltools.arm-none.win32_1.7.0.201602121829\tools\compiler\arm-none-eabi\include\stdlib.h:185:8: note: candidate: char* utoa(unsigned int, char*, int)
char * _EXFUN(utoa,(unsigned, char *, int));
^
In file included from ../cores/maple/WString.cpp:23:0:
../cores/maple/itoa.h:34:14: note: candidate: char* utoa(long unsigned int, char*, int)
extern char* utoa( unsigned long value, char *string, int radix ) ;
^
make: *** [cores/maple/WString.o] Error 1

Rick Kimball
Thu Oct 06, 2016 4:42 pm
-nostdlib is a linker flag not a compile time flag it has nothing to do with compiling.

sheepdoll
Thu Oct 06, 2016 4:47 pm
edogaldo;

This is the relevant section of the makefile that is working for me on the Nucleo (I do not have a blue pill.) I am using BSD under OSX.

# compile gcc flags
ASFLAGS = -MMD -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10604 -DARDUINO_STM_NUCLEO_F103RE -DARDUINO_ARCH_HALMX -DSTM32F103xE -DSTM32_MEDIUM_DENSITY -DSTM32F1 -DBOARD_NUCLEO_F103RE -mthumb -D__STM32F1__
ASFLAGS += $(AS_INCLUDES) -fdata-sections -ffunction-sections
CFLAGS = -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
CFLAGS += -DBOARD_MXNucleoF103 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10604 -DARDUINO_STM_NUCLEO_F103RE
CFLAGS += -DARDUINO_ARCH_HALMX -DSTM32F103xE -DSTM32_MEDIUM_DENSITY -DSTM32F1 -DBOARD_NUCLEO_F103RE -mthumb -D__STM32F1__ $(C_INCLUDES)
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CPPFLAGS = -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
CPPFLAGS += -fno-rtti -fno-exceptions -DBOARD_MXNucleoF103 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10604 -DARDUINO_STM_NUCLEO_F103RE
CPPFLAGS += -DARDUINO_ARCH_HALMX -DSTM32F103xE -DSTM32_MEDIUM_DENSITY -DSTM32F1 -DBOARD_NUCLEO_F103RE -mthumb -D__STM32F1__ $(C_INCLUDES)


edogaldo
Thu Oct 06, 2016 4:59 pm
sheepdoll wrote:In eclipse I had to add these flags to the “Properties .. C C++ General .. Paths and Symbols .. #Symbols tab.” Otherwise the eclipse syntax checker kept giving me this same error. You have to include the #Symbols for each language module.

At present my code compiles. Hangs with a nill pointer exception somewhere in the startup static allocation code relating to USB/CDC or I2C.
[…]


Rick Kimball
Thu Oct 06, 2016 4:59 pm
edogaldo wrote:Thanks Rick, I’ll try to setup it.

Interesting thing: I tried to compile the bluepill project with the default SW compiler (gcc 5.2.1) and I get error: “conflicting declaration of C function ‘char* utoa(long unsigned int, char*, int)’” on file “itoa.h” where utoa is defined as:
extern char* utoa( unsigned long value, char *string, int radix ) ;


Rick Kimball
Thu Oct 06, 2016 5:07 pm
wait …

man libstd says:


Non-standard (i.e. non-ISO C) functions.
char * ltoa (long val, char *s, int radix)
char * utoa (unsigned int val, char *s, int radix)
char * ultoa (unsigned long val, char *s, int radix)
long random (void)
void srandom (unsigned long __seed)
long random_r (unsigned long *__ctx)
char * itoa (int val, char *s, int radix)
#define RANDOM_MAX 0x7FFFFFFF

..
so you just want to change utoa not ultoa .

-rick


Rick Kimball
Thu Oct 06, 2016 5:11 pm
Turns out the arduino code has a “fix” in for this

https://github.com/arduino/Arduino/pull/4830/files


edogaldo
Thu Oct 06, 2016 5:19 pm
Rick Kimball wrote:Turns out the arduino code has a “fix” in for this

https://github.com/arduino/Arduino/pull/4830/files


Rick Kimball
Thu Oct 06, 2016 5:35 pm
We will have to apply a fix at some point. When the arm-none-eabi-gcc version gets greater than 4.9.2 in the arduino IDE we will forced to deal with it.

Rick Kimball
Thu Oct 06, 2016 6:05 pm
edogaldo wrote:Even with the -nostdlib I get the error:
'Building file: ../cores/maple/WString.cpp'
'Invoking: MCU G++ Compiler'
...

stevestrong
Thu Oct 06, 2016 8:08 pm
edogaldo wrote:ps: one more question: is there a way to make the project use the Maple core available in the [Arduino installation]/hardware folder without duplicating it within the project’s path?

Rick Kimball
Thu Oct 06, 2016 8:12 pm
stevestrong wrote:edogaldo wrote:ps: one more question: is there a way to make the project use the Maple core available in the [Arduino installation]/hardware folder without duplicating it within the project’s path?

RogerClark
Thu Oct 06, 2016 8:45 pm
Rick

I am happy to add that change for utoi etc and the platform.txt fix,

can you check it works with the proposed changes to platform.txt and post the few lines that need changing, or just tell me what to remove ?

The utoi issue is already hitting me as some other cores have updated to require gcc 5.x I and I get issues if I add the compiler to the IDEs hidden gcc toolchain folder


edogaldo
Thu Oct 06, 2016 8:57 pm
stevestrong wrote:edogaldo wrote:ps: one more question: is there a way to make the project use the Maple core available in the [Arduino installation]/hardware folder without duplicating it within the project’s path?

Rick Kimball
Thu Oct 06, 2016 9:06 pm
I think he is talking about this http://eclipse.baeyens.it/ ?

stevestrong
Thu Oct 06, 2016 9:51 pm
Rick, sorry, i didnt want to say that the other one is better, i just pointed as an alternative solution for not copying the sources.
I really appreciate your work.

Oh, and i also have the system workbench plugin, these 2 plugins seem to coexist peaceful :P


RogerClark
Fri Oct 07, 2016 1:36 am
Steve

Which one is your personal preference ?


stevestrong
Fri Oct 07, 2016 7:27 am
My preference is Eclipse C++ IDE for Arduino.
The reason: no file copy is needed, the user is flexible by choosing either Arduino IDE or Eclipse IDE without any additional effort.

RogerClark
Fri Oct 07, 2016 7:40 am
Thanks

umejopa
Thu Oct 27, 2016 4:01 pm
How to set up the eclipse to work with chines ST-link V2 clone to and a stm32f103 to debugg ?
It work with the nucelo64 board with the st-link onboard

InvalidException
Sun Nov 13, 2016 6:00 pm
stevestrong wrote:My preference is Eclipse C++ IDE for Arduino.
The reason: no file copy is needed, the user is flexible by choosing either Arduino IDE or Eclipse IDE without any additional effort.

RogerClark
Sun Nov 13, 2016 7:21 pm
There is a blue pill version but it has not been fully merged with the repo and there isnt a boards manager package for it ( and wont be for some tme)

robertkendrick
Wed Dec 07, 2016 3:08 pm
Hi
Very interesting project (bluepill). I used your project files with the latest System Workbench (Nov 2016) and although it compiled and linked (after the utoa issue) the board (a jc66_coreboard) would not enumerate under USB (“device not recognised ….”).
I thought this might be down to using fairly old ArduinoSTM32 bluepill files with the newer System Workbench so I created a new bluepill_2 directory structure using your existing bluepill layout and followed it exactly but using the lastest ArduioSTM32 files. This failed to build with two issues which I have now resolved:
1) The usual utoa
2) unresolved reference to _init

The 2nd issue turned out to be located in a startup file (start_c.c if I remember correctly). Your bluepill startup file had a dummy _init() {asm NOP} but mine, copied from lastest ArduinoSTM32, did not. My question is : Did you create this dummy _init function in the startup file OR was it always in the original ArduinoSTM32 files and has since been removed. If the latter do you know why it was removed ?

And finally, although your bluepill project successfully finds the openocd cfg file (jc66_coreboard.cfg) in the bluepill project directory mine does not. I’ve checked the file exists and in System Workbench I’ve selected “local script” and checked the name is correct but it always returns to “SCRIPT NOT FOUND”. When I start openocd the error message displays the AC6-plugin-stboard-scripts directory and if I copy jc66_coreboard.cfg to this directory everything works as it should. But I can’t get it to work from the local project directory.

What was the purpose of copying over the Platform.txt and Boards.txt files. Are not these redundant in System Workbench?

Anyway, great work, I’m indebted.


Rick Kimball
Wed Dec 07, 2016 4:27 pm
robertkendrick wrote:What was the purpose of copying over the Platform.txt and Boards.txt files. Are not these redundant in System Workbench?

Rick Kimball
Wed Dec 07, 2016 5:37 pm
Looking at detail of the _init() function we see it is provided by newlib if we were linking with the stdlib libraries.
0800328c <_init>:
800328c: b5f8 push {r3, r4, r5, r6, r7, lr}
800328e: bf00 nop
8003290: bcf8 pop {r3, r4, r5, r6, r7}
8003292: bc08 pop {r3}
8003294: 469e mov lr, r3
8003296: 4770 bx lr

robertkendrick
Wed Dec 07, 2016 11:10 pm
Thanks for taking the time to write this.

Yes, I was running the System Workbench compiler. So, as usual, most of my problems were self inflicted.

Point also taken about the openocd cfg file. I had searched the project files (the xml) and puzzled as to why there were no mention of debugging tools and settings. Assume they are setup via eclipse plugins.


ag123
Mon Apr 17, 2017 11:12 am
hi all,

i’m using eclipse (actually without Sloeber) i’m setting the defines by manually defining them using platforms.txt and boards.txt as a reference. tedious but it works.

ot: >> it isn’t system workbench either it is gnu arm eclipse http://gnuarmeclipse.github.io. looking at the first post, i think system workbench is literally a better setup to work in and after all that is created by ST itself if i’m right about it. gnu arm eclipse is in perspective a ‘public 3rd party effort’, the environment is possibly similar to system workbench, the developer(s) of gnu arm eclipse developed several stm32 code ‘generators’ for creating blinky projects for some non st boards, notably from olimex, has a qemu emulator that sport several boards some from olimex and targets stm32 f1 and f4 targets but the features are incomplete (e.g. i think interrupt priorities currently won’t work) and hence only basic emulation functionality) and segger j-link and openocd connectivity <<

here is how i’ve tixed the issues

utoa() issue

as mentioned by rick
https://github.com/arduino/Arduino/pull/4830/files
this is simply because the later gcc versions delivered a utoa() function that has a somewhat different declaration

in my local copy of STM32F1/cores/maple/itoa.h
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)

#if !(GCC_VERSION > 40902)
extern char* utoa( unsigned long value, char *string, int radix ) ;
#endif


Rick Kimball
Mon Apr 17, 2017 12:03 pm
ag123 wrote:
the only trouble is that this is part of the variant start up codes, hence, we’d need to patch every variant if we want to fix the missing _init()

ag123
Mon Apr 17, 2017 12:50 pm
thanks rick,
i did find init() in STM32F1/variants/maple_mini/wirish/boards.cpp
i.e. it is part of the variant

however, i can’t figure out how premain() which calls init()
gets patched into __preinit_array

apparently in the newlib code the function __libc_init_array()
https://github.com/eblot/newlib/blob/ma … isc/init.c
is defined as such:
/* Handle ELF .{pre_init,init,fini}_array sections. */
#include <sys/types.h>

#ifdef HAVE_INITFINI_ARRAY

/* These magic symbols are provided by the linker. */
extern void (*__preinit_array_start []) (void) __attribute__((weak));
extern void (*__preinit_array_end []) (void) __attribute__((weak));
extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));

extern void _init (void);

/* Iterate over all the init routines. */
void
__libc_init_array (void)
{
size_t count;
size_t i;

count = __preinit_array_end - __preinit_array_start;
for (i = 0; i < count; i++)
__preinit_array_start[i] ();

_init ();

count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
__init_array_start[i] ();
}
#endi


Rick Kimball
Mon Apr 17, 2017 12:53 pm
ag123 wrote:
missing _init()

it turns out _init() is possibly intended for shared library initialization (e.g. in linux) and newlib does not ship with that,
http://dbp-consulting.com/tutorials/deb … artup.html
i noted that newlib provides void __libc_init_array() but does not provide _init()

i discussed it in some details here http://www.stm32duino.com/viewtopic.php … =80#p25978


Rick Kimball
Mon Apr 17, 2017 1:01 pm
ag123 wrote:however, i can’t figure out how premain() which calls init()
gets patched into __preinit_array

ag123
Mon Apr 17, 2017 1:03 pm
thanks rick, it seemed then that in my case, i missed out to include a lib in my build path, let me check that on my end

wow, i’ve been tracing and tracing and i simply couldn’t figure out where in the ld scripts, assembler files or c functions that premain() somehow gets into init_array :D


Rick Kimball
Mon Apr 17, 2017 1:08 pm
ag123 wrote:thanks rick, it seemed then that in my case, i missed out to include a lib in my build path, let me check that on my end :D

ag123
Mon Apr 17, 2017 1:13 pm
i run into a problem of ‘fat binaries’ and in an attempt to solve that i set the ld flags
–nostdlib no standard lib
-Xlinker –gc-sections remove unused sections
–specs=nano.specs use newlib-nano

i’m actually building using gcc-arm-none-eabi-6-2017-q1-update, so far it works
however, i get the error _init() is not defined if the above ld options are set
my guess is that –nostdlib overrides –specs=nano.specs and hence _init() is no longer included
however, without –nostdlib the binary size is considerably fatter even if –specs=nano.specs is stated
http://www.stm32duino.com/viewtopic.php … =80#p25978

ok i discovered something about my gcc installation gcc-arm-none-eabi-6-2017-q1-update (this is actually 6.3.1 going by the path names i see)
in the installation folder gcc-arm-none-eabi-6-2017-q1-update/lib/gcc/arm-none-eabi/6.3.1

there are 2 crt*.o files: crti.o and crtn.o
nm crti.o
00000000 T _fini
00000000 T _init


Rick Kimball
Mon Apr 17, 2017 1:20 pm
You probably want ‘-nostartfiles’ instead of ‘-nostdlib’.

-nostartfiles lets you provide your own startup code but lets you link with the nano.specs libc stuff.

As far as code bloat goes, you need to spend some time with arm-none-eabi-objdump -CS yoursketch.ino.cpp.elf | less to see what is causing your code to bloat.


ag123
Mon Apr 17, 2017 2:24 pm
i’m thinking that it is possibly better to simply call init() prior to calling main() in start_c(), that would make the code more readable. But in the mean time that constructor ‘black magic’ works, hence, i’d guess we’d leave it, until it doesn’t :D

gcc is interesting, with so many obscure/often ignored features in elf sections
http://www.cs.stevens.edu/~jschauma/810/elf.html
http://refspecs.linuxbase.org/LSB_3.0.0 … tions.html


paksoft
Fri Nov 24, 2017 4:44 pm
I’ve tried to use Rick’s bluepill.zip with AC6 in Windows 10 (64 bit), because setting up Linux is too difficult for me. I use blue pill and ST-Link from ebay.
I’m just newbie with eclipse software. I try to make several parameters adjustment and but finally, I’ve got error message. Does it look like fake ST-Link error?

Please give some suggestion.

pak


Rick Kimball
Fri Nov 24, 2017 6:00 pm
You should probably create a new test project using System Workbench without using my project configuration. Verify that you can compile and debug on windows. It looks like you are specifying the wrong stlink device, based on the vid/pid mismatch.

VID/PID 0x0483 0x3748 for ST-Link/V2
VID/PID 0x0483 0x374b for ST-Link/V2-1

I setup the project expecting an stlink-v2 … if you are using a “nucleo like” device you could change:
source [find interface/stlink-v2.cfg] to
source [find interface/stlink-v2-1.cfg]

This was the openocd.cfg I used.
# An openocd config for the jc66_coreboard board with a single STM32F103C8Tx chip.
source [find interface/stlink-v2.cfg] set WORKAREASIZE 0x4000
transport select hla_swd
source [find target/stm32f1x_stlink.cfg] adapter_khz 950
# use software reset
reset_config none


Rick Kimball
Fri Nov 24, 2017 6:32 pm
So I just upgraded my System Workbench. It seems the auto generated one now only actually works with stlink-v2-1 …

# This is an bluepill board with a single STM32F103CBTx chip
#
# Generated by System Workbench for STM32
# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)

source [find interface/stlink.cfg]

set WORKAREASIZE 0x5000

transport select “hla_swd”

set CHIPNAME STM32F103CBTx

# Enable debug when in low power modes
set ENABLE_LOW_POWER 1

# Stop Watchdog counters when halt
set STOP_WATCHDOG 1

# STlink Debug clock frequency
set CLOCK_FREQ 4000

# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI…)
reset_config srst_only srst_nogate connect_assert_srst
set CONNECT_UNDER_RESET 1

source [find target/stm32f1x.cfg]

Searching in my Ac6 directory I find stlink.cfg .. has this:
$ find . -iname ‘stlink.cfg’
./SystemWorkbench/plugins/fr.ac6.mcu.debug_2.1.3.201710251246/resources/openocd/st_scripts/interface/stlink.cfg
$ vi $(find . -iname ‘stlink.cfg’)

#
# STMicroelectronics ST-LINK in-circuit debugger/programmer
#

interface hla
hla_layout stlink
hla_device_desc “ST-LINK/V2-1”
hla_vid_pid 0x0483 0x374b

You are going to have to use a custom openocd.cfg file you can’t use the auto generated one any more.

Note: It is a constant struggle to keep things working that once worked. Vendors upgrade their “features” and usually the people who are doing the changes don’t care about maintaining things working with previous versions. … I think Raul Julia got them started on this path:

https://www.youtube.com/watch?v=AjGXn249Fc0


Rick Kimball
Fri Nov 24, 2017 7:45 pm
Since I last looked it seems they have added a new feature, the st-link server. It appears to offer access to both the debug interface along with the Serial Wire Viewer (SWV) monitoring port.

https://my.st.com/content/my_st_com/en/ … erver.html

You might want to check that out.


paksoft
Sat Nov 25, 2017 6:54 pm
@Rick
You should probably create a new test project using System Workbench without using my project configuration. Verify that you can compile and debug on windows. It looks like you are specifying the wrong stlink device, based on the vid/pid mismatch.

I created new project with the code generated by STMCubeMx.
It works, now I need to replace CMSIS with stm32duino core. Could you please give some guidelines for porting stm32duino core?

pak


Leave a Reply

Your email address will not be published. Required fields are marked *