Here is the first cross-MCU code which was used as a test.
A simple blink, which runs on a FreeRTOS task.
#include "mps.h"
void TaskBlink(void *pvParams)
{
for (;;)
{
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("LED on");
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("LED off");
delay(1000);
}
}
void setup() {
initializeMPS();
pinMode(LED_BUILTIN, OUTPUT);
task(TaskBlink);
}
void loop() {}
- Includes the MCU pin setup tool's generated main header. (Which includes all necessary headers as well)
- Defines the task which blinks the led in an infinite loop, and prints out text on Serial.
- Calls the MCU pin setup initialization function which does the initial setup. If our case for example "Serial.begin()" is called inside, if the UART was enabled in the tool.
- Sets the builtin LED pin to output.
- Starts the task, and does nothing in the idle loop.
For Arduino, the Arduino-FreeRTOS library is needed, can be installed in Arduino IDE's Library Manager.
For ESP32, the ESP-IDF needs to be set up, leave the "main.c" totally empty, and put this code into e.g.: "app.cpp". I know it is a bad workaround, will think about it more.
In "make menuconfig", the idle loop for FreeRTOS must be enabled! It uses that for the main loop. It is ugly too, I know.
But with this, the code is nice and readable, and is the same for Arduino Pro Mini and ESP32.
Next step, do a video tutorial about this.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.