AnsweredAssumed Answered

HardFault after Constructor of C++ class

Question asked by Pfeffer.Daniel on Aug 28, 2014
Latest reply on Aug 28, 2014 by Clive One
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...

Outcomes