Is there a way to disable FreeRTOS ticks on one core?

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Is there a way to disable FreeRTOS ticks on one core?

Postby Derf Jagged » Wed Oct 07, 2020 2:21 am

I have a task running on the second core that flips GPIOs on and off and takes between 900ns and 1500ns about 4 times per second. Unfortunately, the FreeRTOS scheduler preempts this task every 1ms and causes a large delay and making it take too long.

Is there a way that I can either:

- Disable the FreeRTOS scheduler completely on one core so it only runs my single task?
- Disable FreeRTOS ticks on the second core and manually do them?
- Disable FreeRTOS completely via menuconfig but still be able to run my task and use the GPIO operations?

I won't be running any other tasks on this core. I see that I can change the tick rate in menuconfig, but I don't know what side effects would come from decreasing the tick rate.

Thanks!

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby ESP_Sprite » Wed Oct 07, 2020 6:55 am

General advice: Don't bitbang GPIOs on the ESP32. The FreeRTOS tick timer isn't the only thing leading to jitter there: shared buses, RPC calls because of flashing etc, they can all influence timing. Rather, try to see if there's a hardware device that can generate the signal you need. For instance, it sounds like you're generating something PWM'ish here; you could look at the LEDC or MCPWM peripherals. Worst case, the RTC peripheral is really flexible in generating signals.

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby Derf Jagged » Wed Oct 07, 2020 1:20 pm

ESP_Sprite wrote:
Wed Oct 07, 2020 6:55 am
General advice: Don't bitbang GPIOs on the ESP32. The FreeRTOS tick timer isn't the only thing leading to jitter there: shared buses, RPC calls because of flashing etc, they can all influence timing. Rather, try to see if there's a hardware device that can generate the signal you need. For instance, it sounds like you're generating something PWM'ish here; you could look at the LEDC or MCPWM peripherals. Worst case, the RTC peripheral is really flexible in generating signals.
Thanks for the reply. Would you have a recommendation for 8 pin digital parallel writes? My current setup works for my purposes seemingly for all times besides when FreeRTOS ticks (since it's such a long delay), but if there's a better option, that'd be great. I don't really know how any of the other hardware devices work.

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby ESP_Sprite » Wed Oct 07, 2020 2:33 pm

You can possibly adjust the I2S parallel (LCD) mode to do that. There's no real driver in ESP-IDF for that though, although there are a fair few projects that use that mode out there. In general, what are you trying to do; what are you writing to?

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby Derf Jagged » Wed Oct 07, 2020 2:56 pm

ESP_Sprite wrote:
Wed Oct 07, 2020 2:33 pm
You can possibly adjust the I2S parallel (LCD) mode to do that. There's no real driver in ESP-IDF for that though, although there are a fair few projects that use that mode out there. In general, what are you trying to do; what are you writing to?
Hmm, I'll look into that..
My project is emulating a Sega Genesis controller. My code waits for a low signal on the Select line, then writes out virtual button states on 7 separate pins, then does the same for when Select goes high. No one seems to know the exact threshold that you have to report by, but it seems to be within 2us (which the tick breaks if it happens while reporting).

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby Derf Jagged » Thu Oct 08, 2020 1:22 pm

ESP_Sprite wrote:
Wed Oct 07, 2020 2:33 pm
(snip)
While I look into that, do you know any of the answers for the questions in the first post? It's so close to working perfectly!

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby Derf Jagged » Wed Oct 14, 2020 2:29 am

In the end, after experimenting a lot with vTaskEndScheduler() and others, I found that just spawning my critical task on cpu1 and calling portENTER_CRITICAL() at the start worked so long as I turned off the Task Watchdog for cpu1. Works great, I can do GPIO manipulation in an infinite loop.

matherp
Posts: 5
Joined: Mon Dec 21, 2020 8:03 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby matherp » Mon Jan 25, 2021 6:20 pm

Derf jagged

I've got the same requirement to allocate one core to a continuously looping task. Please could you share the code you used to create the critical task and lock it to a CPU

Many thanks

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby Derf Jagged » Sat Mar 13, 2021 9:14 pm

matherp wrote:
Mon Jan 25, 2021 6:20 pm
Derf jagged

I've got the same requirement to allocate one core to a continuously looping task. Please could you share the code you used to create the critical task and lock it to a CPU

Many thanks
Sorry for the extremely late reply, I just dug this up in my open tabs. Hopefully this might help you or someone else. The "Select" task is the important one. You need to turn off the Task Watchdog for cpu1 in the ESP-IDF menuconfig.
Attachments
GENESIS_IMPLEMENTATION.c
(7.03 KiB) Downloaded 621 times

moefear85
Posts: 44
Joined: Sun Sep 05, 2021 4:55 pm

Re: Is there a way to disable FreeRTOS ticks on one core?

Postby moefear85 » Mon Apr 11, 2022 10:00 pm

on a side-note, checkout esp-iot-solution. it includes drivers for i2s in lcd-mode, making it easier to implement your own protocol without bitbanging. Other than that, you could use an attiny or atmega as a co-processor, and have that do the bitbanging. you'd only need the esp32 for wireless communication.

Who is online

Users browsing this forum: Baidu [Spider] and 114 guests