ThreadX Porting #292
Replies: 7 comments 28 replies
-
for other platform, arduino core will use systick and provide a callback symbol but i couldn't find in arduino-pico. |
Beta Was this translation helpful? Give feedback.
-
Sorry, back to this topic after one year, I still want to add ThreadX to Arduino and RP2040. I just realized the pico-SDK was built into a static library in Arduino, what I need is to takeover systick and pendsv handler and override them with OS port defined in .S file, whether they are cmiss-compatible symbols (need link cmsis_core interface library and this is preferred to keep minimal code change) or private symbol (use isr_systick/isr_pendsv) in ctr0.S Any suggestions? |
Beta Was this translation helpful? Give feedback.
-
More inputs:
last but not least, i think threadX should not work with FreeRTOS enabled, how can I turn off/on FreeRTOS in configuration? |
Beta Was this translation helpful? Give feedback.
-
Thanks again. I was able to call the SDK API to register PendSV in the low level initialization function in ASM. I checked the right function address is placed into ram_vector_table[14], which is used by NVIC as vector. So I think PendSV will be fine. PUSH {r0, lr}
LDR r0, =-2
LDR r1, =PendSV_Handler
BL exception_set_exclusive_handler
POP {r0, r1}
MOV lr, r1 I'm still trying to figure out how to do with Systick. I think my project will not compatible with FreeRTOS, and as you said, by default it is off. So PIO is not used. You have below code to register a callback if (!__isFreeRTOS) {
// Enable SYSTICK exception
exception_set_exclusive_handler(SYSTICK_EXCEPTION, _SystickHandler);
systick_hw->csr = 0x7;
systick_hw->rvr = 0x00FFFFFF;
} else { private:
static void _SystickHandler() {
rp2040._epoch += 1LL << 24;
} Can I override this systick and will system works just fine? Because when I register my callback to replace yours, my rp2040 looks dead and USB is not funcitoning, I try to add some blink code in my task and it seems ThreadX multitask environement is not running.
Or I should not override your _SystickHandler? It's quite hard to debug in arduino environment without a debugger. |
Beta Was this translation helpful? Give feedback.
-
Just FYI. my port of ThreadX is verified and works on a single cortex-m0 configuration on rp2040. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your guidance. I was able to get ThreadX environment running on top of Arduino-pico platform under specific configuration/modification. I also observed some strange behaviors that need further debug/discuss.
class RP2040 {
public:
RP2040() { /* noop */ }
~RP2040() { /* noop */ }
void begin() {
_epoch = 0;
int off = 0;
_ccountPgm = new PIOProgram(&ccount_program);
_ccountPgm->prepare(&_pio, &_sm, &off);
ccount_program_init(_pio, _sm, off);
pio_sm_set_enabled(_pio, _sm, true);
}
......
inline uint32_t getCycleCount() {
return ccount_read(_pio, _sm);
}
inline uint64_t getCycleCount64() {
return ccount_read(_pio, _sm);
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // If I move this line, USB is not recognized by windows, and board seems dead.
Serial.begin(115200);
Serial.print("\r\nArduino Environment is Up\r\n");
/* Enter the ThreadX kernel. */
tx_kernel_enter();
} The library I made for testing is here, appreciate if you can have a try.. |
Beta Was this translation helpful? Give feedback.
-
Oh yes. Actually the when I start ThreadX environmenet in void arduino::serialEventRun(void) {
if (serialEvent && Serial.available()) {
serialEvent();
}
} PendSV should be the least priority configured by the initalization code, so I'm not sure how it will affect USB or other interrupt. In RTOS based system, urgent/frequent/time-sensing interrupt could be run independ of RTOS as long as user do not call RTOS specific API or use RTOS data in that ISR. That's my understanding.. But anyway, I see a deep integration of FreeRTOS in your core, I probably need to think about whether it is worth and how can do this in a similiar way.. But few things want to double check with you before start.
Appreciate! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to get threadx support to arduino-pico. I need three symbol to support RTOS port.
I use the value above but it seems the system is not working. Not sure if i'm using the right value.
Beta Was this translation helpful? Give feedback.
All reactions