feat: libtropic compatible with RP2040 and RP2350 MCUs (rpi-pico).#464
feat: libtropic compatible with RP2040 and RP2350 MCUs (rpi-pico).#464Caza20 wants to merge 9 commits intotropicsquare:developfrom
Conversation
|
However, something needs to be modified in the CMakeLists.txt file of cal/trezor_crypto. Because as it is, I get this error when compiling: But if you modify the CMakeLists.txt file of the original libtropic by adding the code below, it works! Am I doing something wrong? |
There was a problem hiding this comment.
Hi, thanks for the contribution!
Please, take a look at the comments below.
Regarding the Crypto Abstraction Layer (CAL), the approach is different in Libtropic (all details are in the documentation) and in our libtropic-arduino repository, which seems you are using. Unfortunately, we didn't explain how to handle different CALs in libtropic-arduino, for which we apologize. We assumed that libtropic-arduino will be used for hobby projects only and that MbedTLS CAL, which is used by default there, along with the Arduino HAL, will be sufficient enough. If you can provide us with more information about your project and perhaps some links to the source code, it will be easier for us to help you navigate through these issues. However, please keep in mind that our main focus is on the Libtropic repository, so the support for the libtropic-arduino will have a lower priority. That leads us to a question - have you thought about using Libtropic in a native CMake project without PlatformIO? We are asking because Libtropic in a native CMake project simplifies a lot of things the libtropic-arduino does in not very clear ways (thus your confusion with the Trezor Crypto CAL, which is understandable and sort of a pitfall of the libtropic-arduino project).
If you find some issues or have some more contributions, feel free to send us a PR. If you would like to continue with this discussion, reach us via our support portal.
| } | ||
| #endif | ||
|
|
||
| extern "C" int lt_port_log(const char *format, ...) |
There was a problem hiding this comment.
This is the only function that depends on Arduino.h, thus making the HAL harder to integrate into native projects that use only the Pico SDK or standard libraries. Would it be possible to rewrite this function so it does not depend on Arduino.h?
There was a problem hiding this comment.
I have modified the function to be compatible with both the Arduino SDK and the Pico SDK.
We designed it to use the Raspberry Pi Pico on PlatformIO with the Arduino framework.
There was a problem hiding this comment.
Thanks for the updated version with #ifdef ARDUINO. However, we would like this HAL to be written purely in C (with .c suffix instead of the current .cpp), with no mentions of Arduino API, so people can use it in native project utilizing only the Pico SDK. That means removing the code guarded by #ifdef ARDUINO, include of Arduino.h and renaming the file so it has the .c suffix.
We understand that for your use case, you might need the HAL to use both Arduino API and Pico SDK. However, this is a very specific use case which would not fit in with our other HALs. But a pure Pico SDK HAL (which this HAL can be) would be really appreciated!
…ates and returns an error if they are not equal.
…pares the data lengths and returns an error if they are not equal.
…h the Arduino SDK and Pico SDK.
|
Thank you for showing me the modifications needed. I have corrected them and updated the repository. Regarding CAL integration, the Rpi Pico does not support MbedTLS (or at least I have not been able to get it working). This is different with the ESP32, which already has it embedded. That is why it is necessary to be able to use the Trezor_crypto CAL for it to work. At Wuard, we have developed an HSM module specifically for makers that uses a Tropic01 chip and an Rpi Pico. Here is the link to the firmware for you to see. That firmware works without problems (but it uses the trezor_crypto CAL by modifying the main CMakeLists.txt file; unfortunately, I couldn't find another way). On libtropic-arduino, I have added a pull request so that the Tropic01 can be used with the Rpi Pico using PlatformIO and the Arduino framework (very popular in the maker community). I look forward to your comments, and if any further modifications are needed, please don't hesitate to let me know and I will gladly make them. |
medexs
left a comment
There was a problem hiding this comment.
Hi, thanks for the suggested fixes. There is still one more thing with the lt_port_log function - see the comment below.
Regarding the CAL integration and the other PR into our libtropic-arduino repository - I will provide more information about that in this other PR.
Thank you for the cooperation and interest, we really appreciate it!
| } | ||
| #endif | ||
|
|
||
| extern "C" int lt_port_log(const char *format, ...) |
There was a problem hiding this comment.
Thanks for the updated version with #ifdef ARDUINO. However, we would like this HAL to be written purely in C (with .c suffix instead of the current .cpp), with no mentions of Arduino API, so people can use it in native project utilizing only the Pico SDK. That means removing the code guarded by #ifdef ARDUINO, include of Arduino.h and renaming the file so it has the .c suffix.
We understand that for your use case, you might need the HAL to use both Arduino API and Pico SDK. However, this is a very specific use case which would not fit in with our other HALs. But a pure Pico SDK HAL (which this HAL can be) would be really appreciated!
… lt_port_log function (pico SDK only).
|
@medexs , I have uploaded the changes you requested. I hope everything is okay! Thanks. Best regards! |
|
Hi @Caza20 , thank you very much! However, there is one last thing - I ran our actions on this PR and clang-format action failed for both of the C files. Could you please fix the formatting? We provide instructions on how to do that in our Contributing guideline. I also have one question - both files say the HAL is compatible with RP2040, but do you think it will also work with RP2350? Again, thanks for the great cooperation! |
|
@medexs , I made the formatting changes using clang-format. I apologize for that; I should have done it before uploading. I think everything is okay now. Let me know if anything needs to be modified. The code works for both the RP2040 (Rpi Pico) and the RP2350 (Rpi Pico 2). I look forward to your feedback. Thanks. Regards. |
Description
This Pull Request adds support for RP2040 and RP2350 MCUs to the libtropic library.
The implementation introduces the required HAL functionality for Raspberry Pi Pico–class devices by adding new platform-specific code under hal/rpi-pico. These changes enable libtropic to run correctly on RP2040 and RP2350 microcontrollers.
These MCUs works with the trezor_crypto library.
This work was motivated by a real-world use case: at Wuard, we developed a basic HSM using an RP2350 MCU together with the Tropic01 secure element. More information here
The goal is to make this setup accessible to makers and developers, with easy programming and integration via PlatformIO.
These changes allow libtropic to be used on low-cost, widely available MCUs while preserving compatibility with the existing architecture.
Reference related issues or tickets: Issue #458 and PR #459
Type of Change
Select the type(s) that best describe your change:
Checklist
Before submitting, please confirm that you have completed the following:
Optional Checks
You can enable optional CI jobs by checking following boxes. For example, coverage job is useful when modifying or implementing new tests.
Notes for Reviewers
Platform-specific code is isolated under hal/rpi-pico.
Changes were tested on real hardware using RP2040 and RP2350 MCUs.
The primary target use case is integration with PlatformIO and maker-oriented projects.