2020-09-22 06:09 PM
I want to display a list of Custom Container in a scrollableContainer .
So I write the code like blow.
//declare in public
std::vector <menuDisplayContent> menuDisplayContanier;
/*--------------------------------------------------------------------*/
//in constructor
menuDisplayContanier.resize(5);
for (int i = 0; i < menuDisplayContanier.size(); i++)
{
menuDisplayContanier[i].setY( i * 170);
scrollableContainer1.add(menuDisplayContanier[i]);
}
It worked in PC simulator.But crashed when enter this screen in real board.
Firstly,I doubt the leak of heap is the reason. So I expand the heap size from 0x2000 to 0xF000. It crashed again. The heap size like below.
//in startup_stm32f429xx.s file
Stack_Size EQU 0x4000
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0xF000 // I change the heap size here.
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
Now, I can not find the reason. Is there other reason lead to this phenomenon?
2020-09-23 01:48 AM
Hello,
Have you tried having this piece of code in your setupScreen ?
If this does not fix your issue, please provide more info. In which constructor ?
/Alexandre
2020-09-23 05:40 AM
Have a functional Hard Fault Handler so you can catch failures there.
The constructors may be called before external memory and peripherals are functional.
2020-09-23 05:55 PM
I put this piece of code in a "menuDislpayScreenView::menuDislpayScreenView():" constructor.
All the code like below:
// in menuDislpayScreenView.hpp
class menuDislpayScreenView : public menuDislpayScreenViewBase
{
public:
menuDislpayScreenView();
virtual ~menuDislpayScreenView() {}
virtual void setupScreen();
virtual void tearDownScreen();
//....
std::vector <menuDisplayContent> menuDisplayContanier;
protected:
}
// in menuDislpayScreenView.cpp
menuDislpayScreenView::menuDislpayScreenView()
{
menuDisplayContanier.resize(6);
for (int i = 0; i < menuDisplayContanier.size(); i++)
{
menuDisplayContanier[i].setY( i * 170);
scrollableContainer1.add(menuDisplayContanier[i]);
}
}
void menuDislpayScreenView::setupScreen()
{
menuDislpayScreenViewBase::setupScreen();
for (int i = 0; i < menuDisplayContanier.size(); i++)
{
menuDisplayContanier[i].initialize();
}
}
It worked in PC simulator, but crashed in real board.
And the when I stop the crashed program. It like below.
2020-09-23 06:25 PM
How can I find the cause of hard fault.
In keil ,I only find the hard fault like below.
2020-09-25 05:57 AM
Have you tried what I suggested ?
Also, could you try with a normal array instead of a vector ?
/Alexandre