About FreeRTOS [message #1805596] |
Thu, 18 April 2019 08:07  |
Eclipse User |
|
|
|
Firstly I congratulation for you delevloped 4diac, open source runtime and plc programming ide.
I use STM32F746 discovery kit which includes ethernet. Also I did run freeRTOS and lwip on STM32F76 board.
I try to compile 4diac for freertos+lwip until now I did not success. Some errors like this:
"[100%] Linking CXX executable forte"
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
CMakeFiles/forte.dir/arch/freeRTOS/main.cpp.obj: In function `forte_malloc(unsigned int)':
main.cpp:(.text._Z12forte_mallocj[_Z12forte_mallocj]+0xa): undefined reference to `pvPortMalloc'
undefined reference to `vTaskDelete'
undefined reference to `xTaskCreate'
.... etc.
I want to ask you officially support freeRTOS? can I compile forte for freertos+lwip (for stm32) or freeRTOS upcoming?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: About FreeRTOS [message #1806206 is a reply to message #1806054] |
Mon, 06 May 2019 04:47   |
Eclipse User |
|
|
|
Yes, I got running cleary in a Stm32 and also in a NXP .
As Alois said, you should start your LwIP first. After I check that the LwIP didn't fail, I start my forte task:
if(sys_thread_new("forte_thread", forte_thread, NULL, 2000, 4) == NULL)
LWIP_ASSERT("forte_thread(): Task creation failed.", 0);
the 2000 is the stack size. I'm not sure about it, but I think the stack later multiplies by 4 somewhere. Anyhow, I'd recommend to add:
void vApplicationMallocFailedHook(){
for(;;){
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ){
for(;;){
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
put a breakpoint in both vTaskDelay, and in FreeRTOSConfig.h file make sure you have:
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_MALLOC_FAILED_HOOK 1
This will allow you to check if there's a problem with your memory size. If the breakpoints above are reached, your memory is too small
|
|
|
Re: About FreeRTOS [message #1814253 is a reply to message #1806206] |
Fri, 06 September 2019 07:27   |
Eclipse User |
|
|
|
Hi Jose Maria Jesus Cabral Lassalle,
After for a long time I returned back to try to compile 4diac forte for STM32F746.
I compiled forte as a static library and add to my lwip freertos project.
As you said, I debugged and watched my memory (heap) with vApplicationMallocFailedHook function. I saw my memory which I allocated heap is not enough. When forte define object (RMT_DEV *device = new RMT_DEV;) the microcontroller(STM32F7) make malloc failed.
I incrased my allocated heap there are no problems in there.
But now I have a problem with healthy connection. If forte task deactive my lwip task works fine. But I activate forte task (sys_thread_new) ip doesnt works clearly. I send ping but no response.
void vForteThread(void * argument){
char flag[] = "-c";
char address[16] = "10.0.0.252";
char port[6];
sprintf(port, "%u", 61499);
strcat(address, port);
char* arguments[] = {flag, address};
forteGlobalInitialize();
TForteInstance GESforteInstance;
// int resultForte = forteStartInstanceGeneric(0,0, &GESforteInstance);
int resultForte = forteStartInstanceGeneric(2,arguments, &GESforteInstance);
if(FORTE_OK == resultForte){
forteJoinInstance(GESforteInstance);
}else{
Count++;
}
forteGlobalDeinitialize();
vTaskDelete(NULL);
}
void vIPTask(void const* argument){
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_1, GPIO_PIN_SET);
MX_LWIP_Init();
osDelay(500);
sys_thread_new("forte_th", vForteThread, NULL, 10240, 4);
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_1, GPIO_PIN_RESET);
for(;;){
osThreadTerminate(NULL);
}
}
I didnt find where am I wrong? How is your forte task?
Thanks
[Updated on: Fri, 06 September 2019 08:21] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Re: About FreeRTOS [message #1814721 is a reply to message #1814692] |
Tue, 17 September 2019 02:34   |
Eclipse User |
|
|
|
Alois Zoitl wrote on Mon, 16 September 2019 13:24Is your freeRTOS scheduler running? You must not call the forteJoinInstance from main.
Sorry Professor, I misunderstood this reply.
Let me explain that everything from beginning.
First of all into main function I created a task for lwip init.
int main(void){
... // some init codes
...
osThreadDef(ipTask, vIPTask, osPriorityNormal, 0, IPTASK_HEAPSIZE);
ipTaskHandle = osThreadCreate(osThread(ipTask), NULL);
osKernelStart()
}
in vIPTask I check the lwip send ping, works fine
if ping works fine create and run forte task
void vIPTask(void const* argument){
MX_LWIP_Init();
for(;;){
if(HAL_GPIO_ReadPin(GPIOI,GPIO_PIN_11) && forteFlag == false){ // if click the button
if(sys_thread_new("forte", vForteTask, NULL, FORTETASK_HEAPSIZE, 1) == NULL){ // start the forte thread
LWIP_ASSERT("vForteTask(): Task creation failed.", 0);
}
forteFlag = true;
}
}
Forte task codes as Jose Cabral said
void vForteTask( void * argument ){
( void ) argument;
forteGlobalInitialize();
TForteInstance GESforteInstance;
int resultForte = forteStartInstanceGeneric(0,0, &GESforteInstance);
if(FORTE_OK == resultForte){
forteJoinInstance(GESforteInstance); // problem is here
}else{
Count++;
}
forteGlobalDeinitialize();
vTaskDelete(NULL);
}
I watched in debug the codes when run forteJoinInstance(system crash) there is no response anything.
In debug, jump into the function(forteJoinInstance) it goes to
forte_Init.cpp
poDev->MGR.joinResourceThread(); then goes to
RMT_RES.cpp
getResourceEventExecution()->joinEventChainExecutionThread(); then goes to
ecet.h
then goes to
threadbase.tpp
if (0 != paThread) {
paThread->setAlive(true);
paThread->run(); //from this line then goes to
fdselecthand.cpp
void CFDSelectHandler::run(void){
....
retval = select(static_cast<int>(nHighestFDID + 1), &anFDSet, NULL, NULL, &tv); then goes to
sockets.c
lwip_select(....){
....
waitres = sys_arch_sem_wait(SELECT_SEM_PTR(select_cb.sem), msectimeout); // debug waits this line
}
after this line select mechanism waits semaphoretake and system not response anything
[Updated on: Tue, 17 September 2019 03:27] by Moderator
|
|
|
|
|
Re: About FreeRTOS [message #1814749 is a reply to message #1814732] |
Tue, 17 September 2019 07:53   |
Eclipse User |
|
|
|
Hi,
from CThread::join(); it shouldn't go to
if (0 != paThread) {
paThread->setAlive(true);
paThread->run(); //from this line
but I think this is just a misreading of the debugging stack.
The only thing I can imagine is causing problem is the fact that you leave your task vIPTask alive in an infinite loop without sleep.
I have a very similar configuration, where in a task I initialize the IP stack, start Forte thread, but then the first task is killed. So, maybe you could try the following
void vIPTask(void const* argument){
MX_LWIP_Init();
while(forteFlag == false){
if(HAL_GPIO_ReadPin(GPIOI,GPIO_PIN_11) ){ // if click the button
if(sys_thread_new("forte", vForteTask, NULL, FORTETASK_HEAPSIZE, 1) == NULL){ // start the forte thread
LWIP_ASSERT("vForteTask(): Task creation failed.", 0);
}
forteFlag = true;
}
}
vTaskDelete(NULL);
}
|
|
|
Re: About FreeRTOS [message #1814750 is a reply to message #1814749] |
Tue, 17 September 2019 08:20   |
Eclipse User |
|
|
|
Jose Maria Jesus Cabral Lassalle wrote on Tue, 17 September 2019 11:53Hi,
from CThread::join(); it shouldn't go to
if (0 != paThread) {
paThread->setAlive(true);
paThread->run(); //from this line
but I think this is just a misreading of the debugging stack.
The only thing I can imagine is causing problem is the fact that you leave your task vIPTask alive in an infinite loop without sleep.
I have a very similar configuration, where in a task I initialize the IP stack, start Forte thread, but then the first task is killed. So, maybe you could try the following
void vIPTask(void const* argument){
MX_LWIP_Init();
while(forteFlag == false){
if(HAL_GPIO_ReadPin(GPIOI,GPIO_PIN_11) ){ // if click the button
if(sys_thread_new("forte", vForteTask, NULL, FORTETASK_HEAPSIZE, 1) == NULL){ // start the forte thread
LWIP_ASSERT("vForteTask(): Task creation failed.", 0);
}
forteFlag = true;
}
}
vTaskDelete(NULL);
}
I tried as you said but still doesnt work.
forteJoinInstance(GESforteInstance); -> doesnt success.
|
|
|
|
Re: About FreeRTOS [message #1814756 is a reply to message #1814751] |
Tue, 17 September 2019 09:08   |
Eclipse User |
|
|
|
void vForteTask( void * argument ){
( void ) argument;
forteGlobalInitialize();
TForteInstance GESforteInstance;
int resultForte = forteStartInstanceGeneric(0,0, &GESforteInstance);
// if(FORTE_OK == resultForte){
// forteJoinInstance(GESforteInstance);
// }else{
// Count++;
// }
forteGlobalDeinitialize();
vTaskDelete(NULL);
}
void vIPTask(void const* argument){
MX_LWIP_Init();
// while(forteFlag == false){
for(;;){
if(HAL_GPIO_ReadPin(GPIOI,GPIO_PIN_11) && forteFlag == false){
if(sys_thread_new("forte", vForteTask, NULL, FORTETASK_HEAPSIZE, 1) == NULL){
LWIP_ASSERT("vForteTask(): Task creation failed.", 0);
}
forteFlag=true;
}
}
// vTaskDelete(NULL);
}
If the codes is configured in this way, pinging is alive.
|
|
|
|
|
|
|
|
Re: About FreeRTOS [message #1815063 is a reply to message #1815022] |
Wed, 25 September 2019 01:57   |
Eclipse User |
|
|
|
Jose Maria Jesus Cabral Lassalle wrote on Tue, 24 September 2019 10:19What did you change so forte could run? are you sure forte is running?
One question: is the FORTE_COM_ETH enabled when you compile forte?
I\''m not sure what the problem could be. I attached my FreeRTOSConfig.h file so you can compare with yours. Check the variables related to the priorities, this might be cause some problems
It's also strange that it crashes when you kill the vIPtask. Can you send the file where your main function is and the vIPTask is created?
1) Actually I am not sure after which changes forte run but in my opinion forte runs because I am watching in debug forte task runs. The forte task is processing in void CFDSelectHandler::run(void) (in fdselecthand.cpp) function. By the way the forte task in void CFDSelectHandler::run(void)
if((0 != FD_ISSET(sockDes, &anFDSet)) && (0 != callee)){
doesnt pass anytime. Maybe I missed something about sockets(flags etc.).
2) Yes FORTE_COM_ETH enabled to compile forte
3) Truely strange that it crashes when you kill the vIPtask. But I configured again according to your FreeRTOSConfig.h, there is no crash after vIPTask delete. Thanks for that.
My main function which includes the init vIPTask
int main(void){
... // some init codes
...
osThreadDef(ipTask, vIPTask, osPriorityNormal, 0, IPTASK_HEAPSIZE);
ipTaskHandle = osThreadCreate(osThread(ipTask), NULL);
osKernelStart()
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|