-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32Cube support #872
Comments
I think easiest way to integrate RF24 lib into a STM32Cube project is to add it as an included directory ( Copying all the files into the project would break builds because the build system seems to compile all files under the Core/Src folder (with @colombojrj How did you try integrating RF24 into your STM32Cube project? CMake support is secondary since STM32Cube has no support for it (by default). |
Hi, sorry for the delay. Firstly, I would like to thank for the opportunity of contributing with this library. How I would like to integrate RF24 into my stm32 code? (aka my dream)
How to add examples into the RF24 library?When working on stm32 projects, I (usually) keep in git only the ioc file. I (usually) do not add the STM32F1 ST library. I believe we could create examples using the STM32CubeIDE software and add only the changed files (basically main.c) and the ioc file. It may be possible to run some command to automatically generate code to that ioc file from the shell. This would allow for the automatic build tests. Example of how I actually integrate RF24 into my codeI keep a project called Nrfusb, basically a custom BluePill with the RF24 firmware library. It is very useful to our robotics team. More specifically, here you will find how I integrated the RF24 library into my code. What do you think? I believe that I can help with the examples. |
Help with the examples would be appreciated. Although I'm still not sure how to generate Makefiles that are used to drive the compiler. After looking into the CMake support in the IDE, it seems that STM should implement official CMake support if we go that route. I don't want to rely on third party solutions/tutorials to instruct users on how to use CMake in STM32 projects. Therefore, I think the first point (cloning RF24 into the project) should be our official approach. We can keep a few lines of code in the CMakeLists.txt, but that would be for advanced users only (& more driven by community support). In fact, I think you actually outlined a rough draft of the document we need to create (about getting RF24 integrated into the IDE). 💯 I will do some more testing and push my changes... I would also like to see better support for using a specified SPI bus, but that will come later. |
Tomorrow I will port some rf24 example and I will share it here.
Em sex., 9 de set. de 2022 21:52, Brendan ***@***.***>
escreveu:
… Hello with the examples would be appreciated. Although I'm still not sure
how to generate Makefiles that are used to drive the compiler.
After looking into the CMake support in the IDE, it seems that STM should
implement official CMake support if we go that route. I don't want to rely
on third party solutions/tutorials to instruct users on how to use CMake in
STM32 projects.
Therefore, I think the first point (cloning RF24 into the project) should
be our official approach. We can keep a few lines of code in the
CMakeLists.txt, but that would be for advanced users only (& more driven by
community support).
In fact, I think you actually outlined a rough draft of the document we
need to create (about getting RF24 integrated into the IDE). 💯
I will do some more testing and push my changes...
------------------------------
I would also like to see better support for using a specified SPI bus, but
that will come later.
—
Reply to this email directly, view it on GitHub
<#872 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYPGI2MHKYRZBOQSAROXRDV5PLWFANCNFSM6AAAAAAQIMDNCQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Wow! Replying the github email post things here!
Em sex., 9 de set. de 2022 21:56, José Roberto Colombo Junior <
***@***.***> escreveu:
… Tomorrow I will port some rf24 example and I will share it here.
Em sex., 9 de set. de 2022 21:52, Brendan ***@***.***>
escreveu:
> Hello with the examples would be appreciated. Although I'm still not sure
> how to generate Makefiles that are used to drive the compiler.
>
> After looking into the CMake support in the IDE, it seems that STM should
> implement official CMake support if we go that route. I don't want to rely
> on third party solutions/tutorials to instruct users on how to use CMake in
> STM32 projects.
>
> Therefore, I think the first point (cloning RF24 into the project) should
> be our official approach. We can keep a few lines of code in the
> CMakeLists.txt, but that would be for advanced users only (& more driven by
> community support).
>
> In fact, I think you actually outlined a rough draft of the document we
> need to create (about getting RF24 integrated into the IDE). 💯
>
> I will do some more testing and push my changes...
> ------------------------------
>
> I would also like to see better support for using a specified SPI bus,
> but that will come later.
>
> —
> Reply to this email directly, view it on GitHub
> <#872 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAYPGI2MHKYRZBOQSAROXRDV5PLWFANCNFSM6AAAAAAQIMDNCQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
I imagine the "Drivers" folder (in the STM32Cube project) is the correct place to clone RF24 libs, yes? |
Yes. I would put it there.
Em sex., 9 de set. de 2022 22:39, Brendan ***@***.***>
escreveu:
… I imagine the "Drivers" folder (in the STM32Cube project) is the correct
place to clone RF24 libs, yes?
—
Reply to this email directly, view it on GitHub
<#872 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYPGI4XNT3YKMWW7MY4E7LV5PREXANCNFSM6AAAAAAQIMDNCQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I think a separate utility/STM32/includes.h should be created for the various HAL files specific to STM chips. This should ease the contribution of patches to support STM32 chips that we might be currently overlooking. |
Ok. I refactored the original work to follow the utility/template better, ran clang-format on the added/modified sources, and started a how-to doc on the stm32cube-support branch. It compiles in my local project following the steps outlined in the new doc. I relied on the IDE's auto-code generation feature, so I'm not sure if I haven't actually run my project on my STM32F4 board (yet) because the code in main.c is not completely filled out. I just have the bare minimum to init the radio right now. The SPI wrapper could be greatly improved because it now uses an OOP pointer. Meaning people should be able to use their own
|
Hi, I will test the code today, and then I will be sharing it. I need to ask about how I should share the code. I have never reached this point in sharing code with people. Should I create a new branch and submit a pull request to the stm32 branch? |
Maybe we can use a builtin user button on the board (if it has one). My STM32F411 has a a user button labeled "key" (in addition to "boot" and "reset" buttons).
Yeah, I think this might cause problems for an example that aims to be a simple demonstration. Alternatively, we could write comments to encourage users to change certain variables that affect the example's behavior, then they could simply compile and flash it to the chip. I'm not very experienced with using semi-hosting, but maybe the ST-Link could be used as a Serial-like output. I'm not sure how it could be used to get user input though.
There are several ways. My first idea is create a gist on github and share the link. Although if you want to share more than 1 file, it might be better to create a PR from a branch on your fork. If you want to use a PR, then I would suggest you make it target the stm32Cube-support branch here on the the upstream RF24 repo (not our master branch). A little off topic here, but I recently started exploring the Rust programming language which can also be deployed on microcontrollers. Apparently there is already enough HAL libs written in Rust to get the nRF24L01 working on various boards (including STM32 and nRF52 boards). I'm not giving up on this endeavor, but it may actually be easier for users to utilize Rust if they're trying to avoid using the STM32Cube IDE (which is basically Eclipse). |
What do you think of this? I am curious about Rust. I hope to try it soon. |
|
|
There are a few. In my test project I changed the properties of the main.c file to use If having 2 separate files is more user friendly (for both project config and readability), then the cpp file should be named something more specific to the project. This is something I forgot to address in the new how-to doc.
My apologies. I wasn't sure of your skill level in "git-fu". I think it would be easiest for your branch to just
You shouldn't need to have 3 SPI buses if all your changing is the bus config for each slave device - that is what Arduino's It doesn't make sense to declare an Furthermore, your code passes a Traditionally, if nothing is passed to |
Hi, I think I have misunderstood. Do you mean something like this?
However, the spi.begin() still needs to be called with the hspi1 object handler. If not, the RF24_SPI class will pass nullptr to HAL_SPI_Init, which will fail:
I am still not sure about do not pass the spi object to radio.begin(). I will test this code and post an update. |
If you use the refactored code that I pushed to stm32cube-support branch: Lines 7 to 16 in dc084e9
then you can RF24_SPI spi();
spi.begin(&hspi);
radio.begin(&spi); I haven't tested this yet, but this is how we handle SPI buses that are specified by the user. |
Thanks for your work so far!
At this point I'm not sure if I'm missing something... Did I follow the instructions correctly? |
RF24 libs are C++ libs, so the main driver file should be a .cpp file. You can of course change the eclipse settings of the project to invoke We didn't add support for the STM32F7 series because we didn't have a board to test it on. You could make a PR to the stm32cube-support branch which would include the snippet you posted and doc tweaks (as you see fit). I haven't worked on this issue in a while because the build system isn't generated by CMake (which would make this a lot easier); ST devs don't seem interested in changing that. And, it seemed like the HAL API for each stm32fxxx series was slightly different in various ways (👎), so you may still run into compiler errors related to symbols used from the HAL API. |
@laserranger3000 This is a quote from an above comment that you might find helpful
|
It's compiling now by specifying g++ for main.c as suggested, thanks |
Let us know if you find further needed tweaks. Like I said, a PR would be welcome. |
Hi, hope you are doing fine. I have worked very hard on testing the radio library with STM32 and (I believe) I have found a problem with my implementation. The actual implementation of delayMicroseconds (to STM32) is:
which is replaced with:
which depends on:
But when attending the radio interrupts, the registers may not get updated, because they are updated in other interrupt, i.e., the internal value of
This delay function (may) be used in csn function. It may be worth to check if other architectures also would suffer of similar problem. I hope to finish the examples code this year. |
Arduino platforms prohibit use of Instead of working around this common limitation in the library code, you should use a Some pseudo-code to overcome any language barrier: // a flag to keep track of the interrupt event
volatile bool hasRX = false;
// the callback function called by an interrupt:
void rx_interrupt() {
hasRX = true;
}
// the main loop/function
void main() {
if (hasRX) {
radio.write( /* ... */ );
hasRX = false;
}
} |
I got the tip from your documentation. And I have done exactly that (your pseudo code) in my code. I was not sure if I should add a timeout in the code. |
I also need to ask another question. Would you have some kind of benchmark? I have tested the AckPayloads and the write method takes something like 800 us to run. In ping-pong example (where the radios change roles), I got something about 3300 us between sending and receiving an answer. Are these values too differente from arduino? |
I would discourage adding any error checking to the
It really depends on the radio settings and local environment (like temperature, surrounding objects, etc), but you should strive to get something close to what the Arduino examples show. 800 us sounds about right, but 3300 us is something I would expect from a slower platform (like Circuitpython). I suspect there's something weird going on there. |
Hello guys, |
It might. All the low level hardware code is in the RF24 lib. You'd probably have to add the path to the cloned RF24Network and RF24Mesh repos, similar to instructions stated in the stm32cube-support branch's added doc (see here). Honestly, I haven't been focusing on this issue for a while (over a year). I've been occasionally re-basing the stm32cube-support branch in the RF24 repo to bring in updates from the master branch. But I haven't tested the branch in a almost 2 years. I don't have the STM32Cube IDE installed anymore, so I have no plans to continue pursuing this. If you make any progress, then please report it here.This issue is largely reliant on community help. Unfortunately, the community involvement seems to be a hit-and-run kind of situation. Most of the coders interested in this feature don't seem very outgoing or probably discouraged by using English. |
Thank you for reply. Yes, I had the same thought that since the hardware related code is mostly in the radio class. Then it would be easier to include the Mesh and network libs once the radio lib is included. Currently I am using a custom made library for RF24 but I was thinking to make a mesh communication on top of it and came across this arduino library, now I am thinking I should use this instead of my own library. But this needs porting to STM32cube IDE. Will give it a try porting to stm32CubeIDE, and if made some progress. will share it here. |
A port was already started on the branch stm32cube-support. Please use that branch and follow the instructions shown in the added doc on that branch. In case you're unfamiliar with git, "branch" is a term that basically means "slightly different version". We use branches to develop new features without messing up the working code in the master branch (from which releases are published).
You can see the difference between the 2 branches using GitHub: master...stm32cube-support |
Preliminary work to get this lib working in the IDE was done by @colombojrj in an unprompted PR #863
This thread is a continuation of the discussion started from that PR. Because that PR did not follow our utility/template driver files, The PR was closed and the work was cloned to a branch here upstream: stm32cube-support
Todo
Notes
This project is predominantly CMake driven now. Any Makefiles generated for this project are geared for the armhf compiler on Linux (RPi OS 32-bit). The STM32Cube IDE defaults to using Makefiles for the arm-none-eabi-gcc/++ compilers. The new CI may benefit from a CMake driven example, but it may not be necessary if it is a project that can be imported by the STM32Cube IDE. Using PlatformIO + STM32Cube framework may help in this regard as there should be minimal setup & configuration needed in this new CI workflow.
All use of
printf()
in RF24 is for debugging output only. Historically, the easiest approach to debugging programs in the Arduino IDE has been using the USB Serial monitor. However, the STM32Cube IDE largely relies on using an ST-Link debugging probe. Because an app developed in the STM32Cube IDE does not automatically include enumerating a USB CDC Serial device (which is board specific), the use ofprintf()
is redundant and should only be used if USB CDC is setup for the STM32 project. OtherwisesprintfPrettyDetails()
should be more flexible in that the buffer of debugging info can be directed to any bus (possibly even through the ST-Link). Another alternative is using theencodeRadioDetails()
which dumps the radio's registers' values to a uint8_t array for external interpretation.Lastly, all documentation provided by STM is scattered (based on components or chip family) or just non-existent. Our own document on getting RF24 started with STM32 devices may require linking to community answers for additional resources 😞.
The text was updated successfully, but these errors were encountered: