Page 1 of 1

Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Posted: Sun Mar 17, 2024 2:24 am
by qheinal
I want to run a task on a specific core. The code is loaded from external source. The external code just does some register moves and then an ILL instruction which causes the Illegal Instruction Exception as i intended it to. Code is loaded in IRAM btw.

This works but it dispaches it to wrong core because I set exception handlers specific for core 0 and they dont get triggered.

Code: Select all

  
         void (*MainPtr)(void*);
         MainPtr = (void(*)(void*))(FunctionAddr) ; //FunctionAddr is the Address of start of code from external source in IRAM
        xTaskCreate(MainPtr,"test" ,8192, NULL, 1, NULL); 
This does not work. It just restarts esp32

Code: Select all

  
         void (*MainPtr)(void*);
         MainPtr = (void(*)(void*))(FunctionAddr) ; //FunctionAddr is the Address of start of code from external source in IRAM
         xTaskCreatePinnedToCore(MainPtr,"test" ,8192, NULL, 1, NULL, 0);  
This works with no issues.

Code: Select all

  
         void (*MainPtr)(void*);
         MainPtr = (void(*)(void*))(FunctionAddr) ; //FunctionAddr is the Address of start of code from external source in IRAM
         MainPtr(NULL); //Execute code 
I do not know why it doesn't work for xTaskCreatePinnedToCore because manually triggering execution of code works by using function pointer

Re: Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Posted: Sun Mar 17, 2024 10:51 am
by liaifat85
Please check if that 'FunctionAddr' contains the correct address of the start of the code in IRAM.

Re: Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Posted: Sun Mar 17, 2024 9:11 pm
by chegewara

Code: Select all

         void (*MainPtr)(void*);
         MainPtr = (void(*)(void*))(FunctionAddr) ; //FunctionAddr is the Address of start of code from external source in IRAM
         MainPtr(NULL); //Execute code
       
If this works, then maybe try to use some hack and call it from within a task created with xTaskCreate?

Or maybe all works fine, just code crash because task should not return and yours FunctionAddr does return.

Re: Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Posted: Tue Mar 19, 2024 1:49 am
by qheinal
It doesn't return its a loop. Apparently if i change the priority from 1 to 2 it works.