Page 5 of 5

Re: C++ and STM32

Posted: Fri Jan 13, 2012 3:49 pm
by colin
One more thought:

If you can identify the exact optimization flag, it might help you find out more about what is going on, but moreover you might be able to use -O0 with only the exact flag needed for the link fix.

First see if it builds OK with -O1 or not.

Then, instead of specifying -O1 or -O2, etc., start with no optimization options at all and add the specific optimization flags that are part of -O1 or -O2, one at a time until the compile/link succeeds. (You will find it most efficient to use a “binary search” or bisection approach, in fact, rather than actually adding one flag at a time: add half the flags, see if it works; if it succeeds, add half of the remaining flags; if it fails, remove half of the flags you added, etc., until you identify the exact flag the is causing link to succeed.)

It would be ideal to figure out why abort() is being referenced, but this might be the most benefit for the least work in your case, since it's apparently only necessary in debugging mode.

Re: C++ and STM32

Posted: Sat Jan 14, 2012 2:08 pm
by noether
Hello colin,

another friend could reproduce the same error but with different compiler. We were trying with different optimization levels, and only the linker error triggers when -O0 is in main.cpp.
I suspect it is a bug/whatever in Eigen, I have posted this error in their official forum: http://forum.kde.org/viewtopic.php?f=74&t=98611

Yeah, regarding the linker error, I can get around it just putting some volatile floats for checking them out in gdb... but I would prefer do not to do it.

Cheers :P

Re: C++ and STM32

Posted: Fri Jan 27, 2012 6:48 pm
by Badger
I'm using a MemoryPool object within a class, but it needs to be aligned, and the data macros don't seem to work in a class:

Code: Select all

/**
 * @brief   Data part of a static memory pool initializer.
 * @details This macro should be used when statically initializing a
 *          memory pool that is part of a bigger structure.
 *
 * @param[in] name      the name of the memory pool variable
 * @param[in] size      size of the memory pool contained objects
 * @param[in] provider  memory provider function for the memory pool
 */
#define _MEMORYPOOL_DATA(name, size, provider)                              \
  {NULL, MEM_ALIGN_NEXT(size), provider}

/**
 * @brief Static memory pool initializer in hungry mode.
 * @details Statically initialized memory pools require no explicit
 *          initialization using @p chPoolInit().
 *
 * @param[in] name the name of the memory pool variable
 * @param[in] size size of the memory pool contained objects
 * @param[in] provider memory provider function for the memory pool or @p NULL
 *                     if the pool is not allowed to grow automatically
 */
#define MEMORYPOOL_DECL(name, size, provider)                               \
  MemoryPool name = _MEMORYPOOL_DATA(name, size, provider)


Any ideas how I might align the memory in the class?

edit: I've misunderstood! It is the alignment of the pool data that is an issue, not the alignment of the MemoryPool object. so I need to work out how to pad my class to a multiple of stkalign_t.

Got there in the end:

Code: Select all

template <class MsgType> class NotifierMsg {
public:
   virtual bool_t send(MemoryPool *, Mailbox *);
} __attribute__((aligned(sizeof(stkalign_t))));

Re: C++ and STM32

Posted: Sat Jan 28, 2012 7:47 am
by Giovanni
Hi,

Sorry for delay I've been KO for a while because flu. Correct anyway, the alignment of the pool object is unimportant, what error you get using that macro?

Giovanni

Re: C++ and STM32

Posted: Sat Jan 28, 2012 10:11 am
by Badger
I was only getting an error because I was using it wrong! From the docs I thought I could use it as the definition of the member variable, but instead I had to use it in the initialiser list like so:

Code: Select all

template <class MsgType, int N> Listener<MsgType,N>::Listener(Notifier<MsgType> *_source) 
: source(_source), notifier(&pool, &mailbox), pool(_MEMORYPOOL_DATA(pool, sizeof(MsgType), NULL))