Eclipse importable bluepill project

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

Re: Eclipse importable bluepill project

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

Code: Select all

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

In the project linker settings I had selected "No startup or default libs (-nostdlib)", but I also provided the -specs=nano.specs so if it really needs some stdlib code it is going to grab it from the list of libraries in that spec. However the libc function __libc_init_arrray() does actually call _init(), so I had to provide something. The default_init() function appears to just be a nop function. This function is meant to be a hook for operating systems to perform any initialization. For us, I think we should use it to our advantage to initialize the board hardware.

Maybe the _init() function should be more like:

Code: Select all

void _init(void) {
   extern void init(void); // from boards.cpp .. would have to be defined as extern "C" { void init(void) } in boards.h
   // we could be initializing the RCC clock/PLL etc and the peripheral clocks
   // before the global c++ constructors are called.
   // calling board
   init(); // init function from boards.cpp

That way the underlying hardware is properly configure before any c++ ctors are run.

Or we could just rename void init() in boards to _init() in boards.cpp and make sure it has 'C' binding instead of C++.



BTW: __libc_init_array looks something like this:

Code: Select all

   extern void (*__preinit_array_start[])(void);
   extern void (*__preinit_array_end[])(void);
   extern void (*__init_array_start[])(void);
   extern void (*__init_array_end[])(void);

      unsigned int i, cnt;
      // call any global c++ ctors
      cnt = __preinit_array_end - __preinit_array_start;
      for (i = 0; i < cnt; i++)

      cnt = __init_array_end - __init_array_start;
      for (i = 0; i < cnt; i++)


__libc_init_array() actually comes from libc

0x00000000080031b8 0x50 /home/kimballr/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7-m/libc.a(lib_a-init.o)
0x00000000080031b8 __libc_init_array
Last edited by Rick Kimball on Sat Dec 10, 2016 4:20 am, edited 1 time in total.

Posts: 2
Joined: Wed Nov 30, 2016 5:08 pm

Re: Eclipse importable bluepill project

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

Return to “IDE's”

Who is online

Users browsing this forum: No registered users and 1 guest