Spark Logic

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

Replies

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

Sign in to reply