Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

qheinal
Posts: 24
Joined: Tue Feb 20, 2024 4:38 pm

Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Postby qheinal » Sun Mar 17, 2024 2:24 am

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

liaifat85
Posts: 139
Joined: Wed Dec 06, 2023 2:46 pm

Re: Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Postby liaifat85 » Sun Mar 17, 2024 10:51 am

Please check if that 'FunctionAddr' contains the correct address of the start of the code in IRAM.

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Postby chegewara » Sun Mar 17, 2024 9:11 pm

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.

qheinal
Posts: 24
Joined: Tue Feb 20, 2024 4:38 pm

Re: Help with function pointers and xTaskCreate & xTaskCreatePinnedToCore

Postby qheinal » Tue Mar 19, 2024 1:49 am

It doesn't return its a loop. Apparently if i change the priority from 1 to 2 it works.

Who is online

Users browsing this forum: No registered users and 112 guests