2014-08-28 04:48 AM
Hi,
I'm facing a problem that I don't understand (using CoIDE 1.7.7 and GCC 4.8 2014q3 for a C++ project) with an STM32F407VGT on the Discovery board. When the first constructor is done and it shall be jumped back to main(), I get thrown to the HardFault-Handler with INVSTATE-bit set in UFSR. The first called Constructor (from main() ) is:Screen::Screen(uint32_t num_pixels)
{
length = num_pixels;
p_bufferA = new Rgb[length];
p_bufferB = new Rgb[length];
p_calcBuffer = p_bufferA;
p_sendBuffer = p_bufferB;
}
and the the type Rgb is defined as:
union Rgb {
struct {
uint8_t r;
uint8_t g;
uint8_t b;
} ch;
unsigned int data : 24 __attribute__((__packed__));
Rgb();
}
I need the Union being packed for each being 24 bit.
Does anyone have an idea how to solve this problem?
Interestingly, I can compile and run the code successfully using an old linker-file, that was automatically generated by CoIDE 1.7.4. This causes around 120 K (!!!) more .data, and I don't know why...
2014-08-28 05:39 AM
Perhaps you should review the heap allocation, and ctors initialization?
2014-08-28 06:14 AM
at first: I have to correct myself: .text is growing by 120 k, using the old linker-script. not .data
@clive1: do you mean, that calling malloc(length*sizeof(Rgb)) instead of ''new'' might help? And what is ctors initialization?2014-08-28 08:11 AM
Dynamically allocated memory comes from the heap (new, malloc, etc), statically allocated constructors ''ctors'' are typically handled by C/C++ runtime code that initializes things at reset.
Probably Hard Faulting because the allocation/allocator fails.2014-08-28 12:33 PM
ok, I'll check that. Why would the behaviour change by using another linker script? Do I need special libc for c++? Did it just work before by accident?
Are there any general dos and don'ts for c++ on arm cortex?2014-08-28 01:12 PM
I'm not a C++ guy.
You'd have to look at the linker scripts to understand the differences, where specific objects/functions/structures are placed in memory, and if those memories are initialized or not?