2022-04-05 02:28 AM
When I malloc the fontdata[2048] in internal RAM, it work well. But when I malloc fontdata[2048] in external RAM, it go into HardFault. The external RAM is SDRAM ( W9825G6KH 32MB ).
This is the code:
#include <gui/common/FrontendApplication.hpp>
#include <fonts/GeneratedFont.hpp>
#include <texts/TypedTextDatabase.hpp>
#include <stdio.h>
uint8_t fontdata[2048] __attribute__((section(".ARM.__at_0xC14B0000")));
//binary font object using the data
BinaryFont bf;
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
: FrontendApplicationBase(m, heap)
{
LoadFontFile("1:/Font/Font_simkai_40_4bpp.bin", Typography::LARGE);
}
void FrontendApplication::LoadFontFile(const char* fileName, const touchgfx::FontId type)
{
//read the binary font from a file
FILE* font = fopen(fileName, "rb");
if (font)
{
//read data from the file
fread(fontdata, 1, 2048, font);
fclose(font);
//initialize BinaryFont object in bf using placement new
new (&bf) BinaryFont((const struct touchgfx::BinaryFontData*)fontdata);
//replace application font 'DEFAULT' with the binary font
TypedTextDatabase::setFont(type, &bf); //Font_simkai_20_4bpp
}
}