Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freertos-teensy porting for Teensyduino #3

Open
gpb01 opened this issue Jan 9, 2021 · 16 comments
Open

freertos-teensy porting for Teensyduino #3

gpb01 opened this issue Jan 9, 2021 · 16 comments
Assignees
Labels
enhancement New feature or request

Comments

@gpb01
Copy link

gpb01 commented Jan 9, 2021

Hi Timo,

following my issue on Phillip library, I move here to ask you if you think to make a version of your library that can be used in the Teensyduino environment. :-)

Thanks a lot in advance,

Guglielmo

@tsandmann
Copy link
Owner

Hi Guglielmo,

yes, I will have a look at it.

Regards,
Timo

@tsandmann tsandmann self-assigned this Jan 12, 2021
@tsandmann tsandmann added the enhancement New feature or request label Jan 12, 2021
@tsandmann
Copy link
Owner

There is a first test version available which can be used with Teensyduino. If you want to try it out:

  1. Download the library here as a zip archive.
  2. In Teensyduino select "Sketch -> Include Library -> Add .ZIP Library" and specify the downloaded zip archive.
  3. #include "arduino_freertos.h" in your sketch.

However, there are currently the following limitations:

  • No support for C++'s std::thread (the compiler provided by Teensyduino is too old for this).
  • If the sketch (or any included library) uses the EventResponder class, the EventResponder::attachInterrupt() variant must not be used, otherwise FreeRTOS will stop working. An update of the Teenys cores library is required to make this work.
  • configUSE_MALLOC_FAILED_HOOK has no effect, vApplicationMallocFailedHook() will not be executed if malloc() fails.

I haven't done much testing so far as I don't use Teensyduino for my projects.

@gpb01
Copy link
Author

gpb01 commented Jan 17, 2021

Hi Timo,
THANKS A LOT !!! For sure i will do some tests and inform you of any problem. :-)

@gpb01
Copy link
Author

gpb01 commented Mar 17, 2021

Hi Timo,
I tried you new release 10.4.1-6 in Teensyduino but, but, with this release, with the same program, I get some errors related to '__isb', '__dmb' and '__dsb' (e.g. : error: '__isb' was not declared in this scope __isb();).

∙ freertos-teensy-10.4.1-6/src/portable/teensy_4.cpp:143:11: error: '__isb' was not declared in this scope
∙ freertos-teensy-10.4.1-6/src/portable/teensy_common.cpp:146:11: error: '__isb' was not declared in this scope
∙ freertos-teensy-10.4.1-6/src/portable/teensy_4.cpp:173:11: error: '__dmb' was not declared in this scope
∙ freertos-teensy-10.4.1-6/src/portable/teensy_4.cpp:380:11: error: '__dsb' was not declared in this scope
∙ freertos-teensy-10.4.1-6/src/portable/teensy_4.cpp:381:11: error: '__isb' was not declared in this scope
∙ freertos-teensy-10.4.1-6/src/portable/teensy_common.cpp:215:11: error: '__isb' was not declared in this scope

Is it anything related to the compiler version present in IDE 1.8.13? is it possible to find a detour?

TIA

Guglielmo

@gpb01
Copy link
Author

gpb01 commented Mar 17, 2021

... so, I have included these #define in portable/teensy.h:

#define __isb() __asm volatile("isb" ::: "memory")
#define __dmb() __asm volatile("dmb" ::: "memory")
#define __dsb() __asm volatile("dsb" ::: "memory")

and there are no more errors. Is this a correct "detour" or can it cause problems?

TIA,

Guglielmo

@tsandmann
Copy link
Owner

You're right, that's a bug with Teensyduino.
The suggested #defines should fix this, yes.

@gpb01
Copy link
Author

gpb01 commented Mar 17, 2021

Hi Timo,
THANKS !!!

@fralbo
Copy link

fralbo commented Aug 24, 2022

No support for C++'s std::thread (the compiler provided by Teensyduino is too old for this).

Does it explain the problem I encounter in this issue ?

@tsandmann
Copy link
Owner

With the latest version available (v10.5.1_v5), there is now basic support for Teensyduino 1.58.

Please note, until this Pull request is merged, the EventResponder::attachInterrupt() variant must not be used, otherwise FreeRTOS will stop working.
See Readme for details of the limitations with Teensyduino.

@Stevenlawrencehoriba
Copy link

On Platform IO how do I add TeensyDuino to the freeRTOS build, so i can get libraries for Ethernet and SD card libraries

@tsandmann
Copy link
Owner

You can add FreeRTOS as a library to TeensyDuino (see README.md) if you want to use it with TeensyDuino.
Or you can add Platform IO libraries as usual when using a Platform IO project.
But you can't use TeensyDuino together with Platform IO.

@tsandmann tsandmann reopened this May 27, 2023
@Stevenlawrencehoriba
Copy link

this is the issue, I need to be able to run the devices under the port of freeRTOS for teensy 4.1, Your current port will compile nicely with platformIO and i can add my own project to the port from the folder etc, and it works ok, until I start wanting devices. So its really the other way round I want the freeRTOs port , with access to the hardware devices, otherwise there is no point in using the freeRTOS port. I need to use Ethernet on one task , serial devices on another task and business logic in between, using thrreads. as freeRTOS supports all the nice features you would expect, such as queusu and semaphores, it seems natural that tis is a basic requirement to also access the internal devices, whioch are linked to you locked source for Arduino, unless you know of another way?

@Stevenlawrencehoriba
Copy link

Stevenlawrencehoriba commented Jun 1, 2023

further info today.,. I have got freeRTOS for teensy working, using version 10.5.1_v6 with QNEthernet on one thread and LED on another. We need serial and sdcard threads. Do you think if these are isolated on there own threads and messages sent across to those threads to action device functions this would be OK. I had to use the URL method of adding in the libraries by hand as required. The issue i guess is going to be IF the libraries calls something that upsets the RTOS.

@Stevenlawrencehoriba
Copy link

additional information today ongoing work trying to get device to work on your freeRTOS port. Although the Ethernet server works in its own thread, adding the SDFat library is now an issue. In that If I try and initialise SDFat with sd.begin(SdioConfig(FIFO_SDIO), where it is a global, it will not initialise, If i place the "SdFat32 sd;" object inside the start of a task i.e. beginning of a task thread, it will initialise, but fail to work, i.e. any file control fails. I would be happy to share my entire project if that would help, as it really is simple test code , the same code in the thread, i have created a std arduino sketch under the Arduino IDE , and it works fine. So it MUST be something about you port of freeRTOS, and interaction with your devices. What or how can i do to help with getting the device to work under freeRTOS?

@tsandmann
Copy link
Owner

I did test the SDFat library as shown in the sdfat example, but not beyond that. So yes, there may be issues with other libraries, especially if they are not written for FreeRTOS. Do Ethernet and SDCard on Teensy use the same hardware controller or something? Maybe there is an interference or a hardware access is preempted when it shouldn't be.
The FreeRTOS port doesn't contain specific drivers for the Teensy, so your question goes far beyond this issue here.

@Stevenlawrencehoriba
Copy link

tonights findings. Finally got SDFAT working.. this may help other people.. make sure SDFat32 is initialied at the start of a thread. and to make the file read and writes work, use the defines as follows, not FILE_READ and FILE_WRITE

file = psd->open("hi.txt", O_WRITE | O_CREAT | O_TRUNC);

file = psd->open("hi.txt", O_READ);

as the defines FILE_READ and FILE_WRITE clash with another library "FD.h" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants