Skip to content

Conversation

sbgaia
Copy link
Member

@sbgaia sbgaia commented Sep 19, 2025

This PR adds preliminary support for building and running the reactor-uc library and its examples on FreeRTOS and ESP-IDF platforms, tested on the RP2040 (Pico) and ESP32 microcontrollers (#37).

@sbgaia sbgaia added enhancement New feature or request platform Platform support labels Sep 19, 2025
Copy link
Contributor

Coverage after merging esp32 into main will be

52.86%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   action.c70%65.38%62.50%71.88%113–114, 127–128, 131–134, 137–138, 140–143, 145, 149, 152–155, 25, 40–42, 46, 48, 55–56, 63–65, 65, 65–68
   builtin_triggers.c90.91%70%100%96.77%14, 18, 40, 43
   clock_synchronization.c0%0%0%0%100–103, 105–106, 106, 106–109, 114–116, 116, 116–118, 120–122, 122, 122–124, 124, 124, 124, 124–126, 129, 13, 130, 132, 135, 137–139, 14, 141, 143, 143, 143–145, 147–149, 149, 149–151, 154, 156, 158, 16, 160–161, 161, 161–163, 163, 163, 166, 166, 166–167, 17, 170–175, 175, 175–176, 18, 180, 182–188, 188, 188–189, 19, 192, 195–199, 20, 200, 200, 200–201, 203, 205, 208, 210–214, 214, 214–215, 215, 215–224, 224, 224–225, 227, 23, 23, 23, 230–232, 234–236, 238, 238, 238–239, 24, 241, 244–245, 247–249, 25, 250–254, 254, 254–256, 26, 26, 26, 261–264, 264, 264–266, 268–269, 27, 273–275, 277–278, 278, 278–279, 279, 279–287, 287, 287–288, 290, 294, 297–298, 30, 301–310, 310, 310–311, 314, 317–320, 323, 323, 323, 323, 323, 323, 323, 323, 323–329, 33, 330–339, 34, 340–344, 347–348, 35, 350, 354–362, 364, 367, 367, 367–368, 372–376, 379, 379, 379–380, 383, 385, 40, 42, 44, 46, 49, 49, 49–51, 51, 51–52, 55, 58, 62, 64–66, 66, 66, 69, 69, 69–70, 73–79, 79, 79–80, 83, 89–90, 93, 95, 95, 95–97
   connection.c78.43%53.33%100%87.88%10, 104, 110, 123–124, 137–138, 14, 14, 144, 146–147, 149, 16–17, 21–22, 22, 22–23, 25, 27–28, 34, 48, 48, 48–49, 55, 60–62, 97
   environment.c94.12%83.33%100%100%16, 29
   event.c100%100%100%100%
   federated.c6.53%3.26%10%7.94%10, 100–101, 103, 103, 103–104, 106, 106, 106, 106, 106–107, 107, 107–109, 11, 112, 112, 112–114, 117–118, 121–123, 123, 123–124, 124, 124–126, 128, 13, 131, 133, 135–139, 14, 140, 143–145, 147, 147, 147, 149, 15, 150–152, 154, 156, 156, 156–157, 159, 16, 160, 163–164, 171–173, 173, 173–174, 176, 178, 178, 178–179, 18, 18, 18, 180–181, 181, 181, 181, 181, 181, 181–189, 19, 19, 19, 190, 190, 190–191, 193–200, 202–205, 209, 21, 21, 21, 212, 212, 212–214, 216, 218, 22, 220–222, 222, 222, 222, 222–229, 23, 23, 23, 231–234, 234, 234–235, 237, 24, 240–243, 245, 25, 251–253, 266–267, 267, 267–268, 268, 268–269, 269, 269–270, 270, 270–271, 271, 271–272, 272, 272–273, 273, 273, 275, 275, 275–276, 276, 276–277, 277, 277–278, 278, 278–279, 279, 279, 281, 29–30, 34–39, 41, 43, 43, 43–44, 44, 44–45, 45, 45–46, 46, 46, 48, 50–53, 55, 55, 55–58, 58, 58–59, 61, 63–64, 64, 64–65, 69, 72–73, 73, 73–74, 76–78, 80, 84, 86, 88–90, 93, 95–99
   logging.c88.52%83.33%100%89.36%25, 38–40, 47, 60–61
   network_channel.c69.23%62.50%100%70.59%40, 40, 40, 45–48, 57
   physical_clock.c89.61%83.33%71.43%93.10%26, 41, 57–58, 81, 83
   port.c74.68%42.86%100%91.49%10, 10, 10, 15, 15, 15–16, 22, 26, 31, 31–33, 33, 33–34, 45, 45, 45–46
   queues.c86.11%79.03%100%88.03%100–106, 131–135, 138–139, 156, 161, 167, 34, 34, 38–44, 69–70, 96, 96
   reaction.c71.31%56.52%100%78.87%15, 21, 28–30, 30, 30–32, 32, 32–33, 43, 46, 53–54, 54, 54–56, 56, 56–57, 72, 88–90, 90, 90–93, 93, 93–94
   reactor.c69.33%51.52%100%82.28%10, 101–102, 14–19, 22, 28, 30, 32–37, 37, 37–38, 38, 38, 43, 55, 58–59, 59, 59–60, 60, 60–61, 63, 77–78, 81–82, 82, 82–83, 83, 83–84, 86, 91
   serialization.c37.50%25%50%40%16–17, 26–27, 33–34, 34, 34–35, 37–38, 41–42, 42, 42–43, 45–46
   startup_coordinator.c0%0%0%0%100,

Copy link
Contributor

Benchmark results after merging this PR:

Benchmark results

Performance:

PingPongUc:
Best Time: 244.492 msec
Worst Time: 244.806 msec
Median Time: 244.603 msec

PingPongC:
Best Time: 171.897 msec
Worst Time: 173.019 msec
Median Time: 172.508 msec

ReactionLatencyUc:
Best latency: 34609 nsec
Median latency: 60834 nsec
Worst latency: 129852 nsec

ReactionLatencyC:
Best latency: 21540 nsec
Median latency: 60692 nsec
Worst latency: 345777 nsec

Memory usage:

PingPongUc:
text data bss dec hex filename
37386 760 8472 46618 b61a bin/PingPongUc

PingPongC:
text data bss dec hex filename
47658 878 384 48920 bf18 bin/PingPongC

ReactionLatencyUc:
text data bss dec hex filename
23651 736 2520 26907 691b bin/ReactionLatencyUc

ReactionLatencyC:
text data bss dec hex filename
43200 846 384 44430 ad8e bin/ReactionLatencyC

Copy link
Contributor

Memory usage after merging this PR will be:

Memory Report

action_empty_test_c

from to increase (%)
text 69479 69479 0.00
data 752 752 0.00
bss 12416 12416 0.00
total 82647 82647 0.00

action_microstep_test_c

from to increase (%)
text 70308 70308 0.00
data 760 760 0.00
bss 12480 12480 0.00
total 83548 83548 0.00

action_overwrite_test_c

from to increase (%)
text 70185 70185 0.00
data 752 752 0.00
bss 12480 12480 0.00
total 83417 83417 0.00

action_test_c

from to increase (%)
text 70081 70081 0.00
data 760 760 0.00
bss 12480 12480 0.00
total 83321 83321 0.00

deadline_test_c

from to increase (%)
text 64936 64936 0.00
data 768 768 0.00
bss 11776 11776 0.00
total 77480 77480 0.00

delayed_conn_test_c

from to increase (%)
text 70423 70423 0.00
data 752 752 0.00
bss 13248 13248 0.00
total 84423 84423 0.00

event_payload_pool_test_c

from to increase (%)
text 24353 24353 0.00
data 720 720 0.00
bss 480 480 0.00
total 25553 25553 0.00

event_queue_test_c

from to increase (%)
text 29092 29092 0.00
data 728 728 0.00
bss 480 480 0.00
total 30300 30300 0.00

nanopb_test_c

from to increase (%)
text 44218 44218 0.00
data 1928 1928 0.00
bss 320 320 0.00
total 46466 46466 0.00

physical_clock_test_c

from to increase (%)
text 49792 49792 0.00
data 832 832 0.00
bss 640 640 0.00
total 51264 51264 0.00

port_test_c

from to increase (%)
text 70326 70326 0.00
data 752 752 0.00
bss 13056 13056 0.00
total 84134 84134 0.00

reaction_queue_test_c

from to increase (%)
text 28292 28292 0.00
data 728 728 0.00
bss 480 480 0.00
total 29500 29500 0.00

request_shutdown_test_c

from to increase (%)
text 70318 70318 0.00
data 752 752 0.00
bss 12480 12480 0.00
total 83550 83550 0.00

startup_test_c

from to increase (%)
text 64565 64565 0.00
data 760 760 0.00
bss 11776 11776 0.00
total 77101 77101 0.00

tcp_channel_test_c

from to increase (%)
text 92307 92307 0.00
data 2288 2288 0.00
bss 14720 14720 0.00
total 109315 109315 0.00

timer_test_c

from to increase (%)
text 64537 64537 0.00
data 752 752 0.00
bss 11776 11776 0.00
total 77065 77065 0.00

@sbgaia sbgaia changed the title Add preliminary support for ESP IDF and FreeRTOS framework. Add preliminary support for ESP IDF and FreeRTOS Sep 19, 2025
}

LF_ENTRY_POINT(TimerSource,32,32, SEC(1), false, false);
#ifdef TIMEOUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a configurable timeout to address an issue when debugging a Raspberry Pi Pico on WSL. After a reboot, the serial port must be manually forwarded from the host to WSL, which means that the initial boot logs are missed. This change gives users the option to set a long timeout, providing a sufficient window to re-establish the port connection and see the logs to confirm the board is working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is actually not a timeout in the LF sense, but a delay on startup?

@@ -0,0 +1,46 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty spaces.

cmake_minimum_required(VERSION 3.20.0)
set(PLATFORM "ESP_IDF" CACHE STRING "Platform to target")
set(BUILD_EXAMPLES OFF CAHCHE BOOL)
set(TIMEOUT "1" ON CACHE STRING "Timeout in seconds, disable for infinite")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why as a compile flag, normally the timeout value is inside the generated code?

#include "esp_flash.h"
#include "esp_system.h"
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/environment.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this include should be unnecessary because it should already be included by the previous include statement.


void app_main(void)
{
configure_led();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is app_main the entry point for the ESP sdk?

why not put this configure_led(); inside a startup reaction?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. It makes more sense to place this logic in the startup reaction.

@@ -0,0 +1,1389 @@
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we maybe, put this into the template repo for the ESP?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request platform Platform support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants