Skip to content

Rp2040#377

Merged
Miq1 merged 1 commit into
eModbus:masterfrom
ecarjat:rp2040
Feb 19, 2026
Merged

Rp2040#377
Miq1 merged 1 commit into
eModbus:masterfrom
ecarjat:rp2040

Conversation

@ecarjat

@ecarjat ecarjat commented Oct 9, 2024

Copy link
Copy Markdown
Contributor

This PR enables the code ModbusServerRTU to run on a RP2040 using the arduino framework and the earlephilhower core.
I have only tested the RTU server part. The client RTU replicates the changes done in server and should work as is but it has not been tested.

@Miq1

Miq1 commented Oct 9, 2024

Copy link
Copy Markdown
Contributor

Nice!
I have no RP2040 yet to test it, so it will have to wait for that.
I have a few objections, though:

  • the addition of __linux__ to the #ifdef checks in the async TCP code is not sensible in my opinion, as there will be no such support without completely rewriting the code.
  • your code formatting preferences are different to ours, so all the replaced braces are irritating at least. I would ask you to maintain our formatting habits instead.
  • there is a new #if HAS_FREERTOS section introduced in the middle of the RTU cpp code that I would prefer to protect the complete code.

@ecarjat

ecarjat commented Oct 9, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the quick reply.

  • On code formatting, I did change it so that the braces match your formatting habits. This is what commit [2824eff] intends to do. My current diff does not show a difference. Could you tell me in which file you see a difference ?
  • On __linux__ I've added all the platforms previously listed in the options.h file without checking if this would have worked on the platform. Happy to change it to defined(ESP32) || defined(ESP8266) if that that's the only platforms it works for.
  • On #if HAS_FREERTOS, on second thought I believe this should be changed to #if ESP8266 || ESP32 as the code in this function is specific to these platforms.

@Miq1

Miq1 commented Oct 9, 2024

Copy link
Copy Markdown
Contributor

My bad, sorry! I had a look only at the first commit.

Regarding those RTOS task calls, that could be valid for the RP2040 as well - IIRC there are two cores, too? On the ESP32 running the worker task on a dedicated core helps to maintain the bus speed at higher baud rates, the ESP32 can go up to 5Mbaud with it. The RTU server or client do not run on the ESP8266 for exactly the reason of having only one core.

@ecarjat

ecarjat commented Oct 9, 2024

Copy link
Copy Markdown
Contributor Author

The RP2040 has two cores indeed, however the function used xTaskCreatePinnedToCore is proprietary to Expressif. According to this, the "proper" RTOS way to do it is to set affinity. To mimic xTaskCreatePinnedToCore functionality I had to split it into two calls.

@Miq1

Miq1 commented Oct 9, 2024

Copy link
Copy Markdown
Contributor

We are getting there. 😀
To swap out the Espressif task calls you are using the ARDUINO_ARCH... define. I would think the HAS_FREERTOS2040 would be more consistent instead. At one spot of these there is a isolated #elsif - shouldn't that be an #else?
Finally the addition of __linux__ still is in the async TCP files...

I will order a RP2040 for me to test. I would like it better to have the TCP parts also working on that MCU. Did you try those as well? I suppose your definition in options.h is protecting you from all the HAS_FREERTOS encapsulated code.

@Miq1

Miq1 commented Oct 9, 2024

Copy link
Copy Markdown
Contributor

Excellent! Thank you so much. I expect to get the RP2040 on Saturday, so I may approve the PR beginning of next week.

@ecarjat

ecarjat commented Oct 9, 2024

Copy link
Copy Markdown
Contributor Author
  • __linux__ removed.
  • Agree on the platform vs RTOS flavour in terms of choosing the task creation method. I believe the flag HAS_FREERTOS should be named HAS_ESP_FREERTOS ;-) but that's a decision for you to make and probably too much refactoring.
  • My RP2040 does not have wifi so I can't test the TCP part. I initially introduced a HAS_IP flag to distinguish between plaform and and capabilities but in the end thought this was too complicated.
  • I'll craft a simple RP2040 example before the weekend so that you can test.

@Miq1

Miq1 commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

What are your recent changes about to achieve? Just renaming the config variable? If so, why is there no matching commit for options.h?

@ecarjat

ecarjat commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

Just revisiting this project and cleaning up code on my end. Did not think about the side effect on this PR. I can remove it for the time being if you prefer.

Comment thread src/options.h
- squash rp2040 branch history onto upstream/master

- include RP2040 FreeRTOS guards and RTU task affinity compatibility

- keep RP2040 RTU server example and library metadata updates
@Miq1 Miq1 merged commit 8528ffe into eModbus:master Feb 19, 2026
14 checks passed
@Miq1

Miq1 commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

@ecarjat Thank you for your contribution.

mathieucarbou pushed a commit to mathieucarbou/eModbus that referenced this pull request Mar 3, 2026
…s#377)

- squash rp2040 branch history onto upstream/master

- include RP2040 FreeRTOS guards and RTU task affinity compatibility

- keep RP2040 RTU server example and library metadata updates

Co-authored-by: Emmanuel Carjat <emmanuel.carjat@quanthouse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants