tsandmann / freertos-teensy

FreeRTOS port with C++ std::thread support for ARM boards Teensy 3.5, 3.6, 4.0 and 4.1 (cortex-m4f and cortex-m7f)
95 stars 16 forks source link

freertos-teensy porting for Teensyduino #3

Open gpb01 opened 3 years ago

gpb01 commented 3 years ago

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 commented 3 years ago

Hi Guglielmo,

yes, I will have a look at it.

Regards, Timo

tsandmann commented 3 years ago

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:

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

gpb01 commented 3 years ago

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

gpb01 commented 3 years ago

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 commented 3 years ago

... 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 commented 3 years ago

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

gpb01 commented 3 years ago

Hi Timo, THANKS !!!

fralbo commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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

tsandmann commented 1 year ago

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.

Stevenlawrencehoriba commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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" ?