Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » forte+freertos+lwip on stm32 flash problem
forte+freertos+lwip on stm32 flash problem [message #1827389] Thu, 14 May 2020 03:24 Go to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
I did as

https://www.eclipse.org/4diac/en_help.php?helppage=html/installation/freeRTOSLwIP.html

the libforte-static.a library is 2570kb

if i check the iec61131 moduble, then the file will be very large,

then i complied the library with freertos and lwip,

the bin file will be over 512k, it runs out off the 512k flash.

Any experience?

The second problem is when i debug
static void forte_thread(void *arg)
{
forteGlobalInitialize();
TForteInstance forteInstance = 0;
int resultForte = forteStartInstanceGeneric(0, 0, &forteInstance);
if(FORTE_OK == resultForte){
forteJoinInstance(forteInstance);
}else{
printf("Error %d: Couldn't start forte\n", resultForte);
}
forteGlobalDeinitialize();
vTaskDelete(NULL);
}
int resultForte = forteStartInstanceGeneric(0, 0, &forteInstance);
this line is hang up, why?

[Updated on: Thu, 14 May 2020 07:54]

Report message to a moderator

Re: forte+freertos+lwip on stm32 flash problem [message #1827429 is a reply to message #1827389] Thu, 14 May 2020 10:47 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1560
Registered: January 2014
Senior Member

Hi,

first of all I assume you built everything with debug disabled? Debug symbols consume quite some memory.
I made good experiences with -Os (optimize for size) or -O2. The latter often produces smaller binaries for arm then -Os.

Furthermore I had a quick look on the default compiler settings of our default freeRTOS setup and it is missing quite some options that can help you on embedded systems.

I would experiment at least with the following compiler settings: -ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fno-exceptions
and the following linker options for the final linking stage linking your binary: -W,--gc-sections -fno-threadsafe-statics

The functions and data sections allow the linker with the gc-sections to remove not used elements. No-rtti and no-exceptions should greatly reduce the binary size as well.

No-Threadsafe-statics should reduce ram usage. If you take an older forte (1.8.4 or so) you will find there also CMakefiles for Lego Mindstorms nxt (in the ecos folder). There I did the most heavy tuning. Producing a Map file can help here to find out what is all part of your binary image.

Maybe some arm specific options like -mno-thumb-interwork could also bring some size reduction. But here I would refer to your tool-chain.

For your second problem I would a assume a stack size or heapsize problem. How much ram do you have? Can you step into and find out where it breaks inside.

I hope this helps you to move forward.


Re: forte+freertos+lwip on stm32 flash problem [message #1828053 is a reply to message #1827429] Sat, 30 May 2020 15:47 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
Thank you for your so nice advice,
yes, now i have the problem of RAM, my device is stm32F407ZET6,
it's with 512k flash and 128k ram,the Eth is W5500,
in definition:
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.priority = (osPriority_t) osPriorityHigh,
.stack_size = 128 * 4
};
/* Definitions for Task02 */
osThreadId_t Task02Handle;
const osThreadAttr_t Task02_attributes = {
.name = "Task02",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 50
};

in main()
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);


void StartDefaultTask(void *argument)
{
lwipInit();

Task02Handle = osThreadNew(forte_thread, NULL, &Task02_attributes);

vTaskDelete(NULL);
}

the forte version is 1.11 the freertos is 10.2.1 ,the lwip is 2.1.2,
the libforte-static.a is ready on windows with trueStudio, tool-chain is
arm-atollic-eabi.
it seems not enough ram according to the suspending thread stack

even I change
osThreadId_t Task02Handle;
const osThreadAttr_t Task02_attributes = {
.name = "Task02",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 50
};
to 128*80 it didn't work
  • Attachment: snap1.jpg
    (Size: 30.18KB, Downloaded 70 times)

[Updated on: Sat, 30 May 2020 15:51]

Report message to a moderator

Re: forte+freertos+lwip on stm32 flash problem [message #1828119 is a reply to message #1828053] Tue, 02 June 2020 07:04 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1560
Registered: January 2014
Senior Member

How much heap have you configured? given your stack trace I would see stack size is currently not your problem.
Re: forte+freertos+lwip on stm32 flash problem [message #1828122 is a reply to message #1828119] Tue, 02 June 2020 07:22 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
i can see the line forte_malloc, which create the string in CStringDictionary, would use 8000*1B=8000B=8k, the total ram is 192k, does it cost too much?
the #configTotal_HEAP_Size is by default 15360 = 15k, if i adjust the number to bigger, then the compiler will not pass.
Re: forte+freertos+lwip on stm32 flash problem [message #1828125 is a reply to message #1828122] Tue, 02 June 2020 07:45 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1560
Registered: January 2014
Senior Member

In the advanced cmake options you can adjust the size of the string dict. There is also an option to make stringdict a statically allocated array which would then not be resized and therefore not be allocated on the heap.
but 15k of heap will definitely not be enough. I think you need to deeper analyze what is needing your ram for what puproses and tune that.
Re: forte+freertos+lwip on stm32 flash problem [message #1828131 is a reply to message #1828125] Tue, 02 June 2020 08:26 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
when i set #define configTOTAL_HEAP_SIZE ((size_t)45360)
there is no problem, if 65360 then will not pass
then the error is different
as the snapshot
  • Attachment: s2.jpg
    (Size: 63.02KB, Downloaded 71 times)
Re: forte+freertos+lwip on stm32 flash problem [message #1828155 is a reply to message #1828131] Tue, 02 June 2020 19:15 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1560
Registered: January 2014
Senior Member

I think now you are in the deep of your hardware and we can only be of little help. bus error looks like either your memory setup is wrong or you are beyond your memory regions.
Re: forte+freertos+lwip on stm32 flash problem [message #1828476 is a reply to message #1828155] Wed, 10 June 2020 12:20 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
the clue indirect that the piece of code

void CResource::initializeResIf2InConnections(){
if(0 != m_pstInterfaceSpec){
mResIf2InConnections = new CInterface2InternalDataConnection[m_pstInterfaceSpec->m_nNumDIs];
for(TPortId i = 0; i < m_pstInterfaceSpec->m_nNumDIs; i++){
(mResIf2InConnections + i)->setSource(this, i);
}
}
}

could this code cause memory alloc problem?

actully, could you give the suggestion how much ram is needed to run forte on stm32? Or to do what steps can reduce the ram consume?
  • Attachment: 22.jpg
    (Size: 26.77KB, Downloaded 72 times)
  • Attachment: 21.jpg
    (Size: 35.35KB, Downloaded 57 times)
  • Attachment: 23.jpg
    (Size: 19.01KB, Downloaded 63 times)
  • Attachment: 24.jpg
    (Size: 29.95KB, Downloaded 62 times)
  • Attachment: 25.jpg
    (Size: 17.29KB, Downloaded 67 times)

[Updated on: Wed, 10 June 2020 13:10]

Report message to a moderator

Re: forte+freertos+lwip on stm32 flash problem [message #1828480 is a reply to message #1828476] Wed, 10 June 2020 13:14 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
i changed:
#define configTOTAL_HEAP_SIZE ((size_t)35360)
the the ucheap is lower , but the same error in the same place
Re: forte+freertos+lwip on stm32 flash problem [message #1828487 is a reply to message #1828480] Wed, 10 June 2020 14:52 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1560
Registered: January 2014
Senior Member

In my experience on low memory devices composite FBs need a lot of memory and for beginning you should definitly avoid them. If you need a lightweight encapsulation means you can use subapps (typed and untyped). I had 4diac FORTE running on an arm7 with 64k of ram using eCos. I currently don't know how much RAM freertos and lwIP is using. A good starting point is looking at the map file which your linker can produce.
Re: forte+freertos+lwip on stm32 flash problem [message #1828499 is a reply to message #1828487] Thu, 11 June 2020 01:26 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
when i build the static library with DEBUG, then i found the stack line :
CIEC_WSTRING& MGR_ID() {
return *static_cast<CIEC_WSTRING*>(getDI(0));
}

getID(0)) is no problem, but *static_cast<CIEC_WSTRING*> caused BusFault_Handler

that is very wired
Re: forte+freertos+lwip on stm32 flash problem [message #1828509 is a reply to message #1828499] Thu, 11 June 2020 07:40 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member

CIEC_ANY *CTypeLib::createDataTypeInstance(CStringDictionary::TStringId pa_nDTNameId, TForteByte *pa_acDataBuf) {
CIEC_ANY *poNewDT = 0;
CTypeEntry *poToCreate = findType(pa_nDTNameId, m_poDTLibStart);
if (0 != poToCreate) {
poNewDT = (static_cast<CDataTypeEntry *>(poToCreate))->createDataTypeInstance(pa_acDataBuf);
if (0 == poNewDT) // we could not create the requested object
m_eLastErrorMSG = e_OVERFLOW;
} else
m_eLastErrorMSG = e_UNSUPPORTED_TYPE;

return poNewDT;
}
e_UNSUPPORTED_TYPE;

can't findType, still researching

[Updated on: Thu, 11 June 2020 07:41]

Report message to a moderator

Re: forte+freertos+lwip on stm32 flash problem [message #1828517 is a reply to message #1828509] Thu, 11 June 2020 09:07 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
in findType(pa_nDTNameId, m_poDTLibStart);
the link list of m_poDTLibStart is not the complete one and not correct.
i don't know why
Re: forte+freertos+lwip on stm32 flash problem [message #1828518 is a reply to message #1828517] Thu, 11 June 2020 09:25 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 198
Registered: May 2019
Senior Member
i found the reason at last
__libc_init_array();
should not be called at the beginning of the main(), i removed it
because it has already been called by system, if called twice, then the initilzation would be problem

so plz update the the last line in docment of https://www.eclipse.org/4diac/en_help.php?helppage=html/installation/freeRTOSLwIP.html

Re: forte+freertos+lwip on stm32 flash problem [message #1828521 is a reply to message #1828518] Thu, 11 June 2020 09:53 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1560
Registered: January 2014
Senior Member

If you read the documentation it is stated in some cases it is not called and only in the cases when it is not called you should call it by yourselve. The better solution is always to have a standard LD file and a standard startup procedure where this is handled.
Previous Topic:Compiling forte with xilinx toolchain failed
Next Topic:4DIAC IDE 1.12.2 source ships as 1.12.1
Goto Forum:
  


Current Time: Thu Mar 28 14:37:42 GMT 2024

Powered by FUDForum. Page generated in 0.06919 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top