-
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
Added initial support to STM32 (using CubeHAL API). #863
Conversation
Have you read our docs about porting this lib to non-Arduino API? The whole point of using the utility folder is to keep hardware specific SDK API out of RF24.cpp and RF24.h I think if you follow the template provided in the utility/template, then some of the additions to RF24.cpp, RF24.h, and RF24_config.h can be properly abstracted. Is there a way we could test compile this in CI, so we know future contributions won't break this? I wouldn't mind a new separate workflow (like we did for the Pico SDK - see build_rp2xxx.yml). Sadly, I don't have a STM32 board to test this on. So, I can't confirm this physically. |
Hi, I have seen that documentation, but I could not think of a way of porting the digitalWrite to the CubeHAL API because it uses two variables to describe a pin (the number and a handle struct). However, after a second thought, I think I could edit that gpio class to hold those two variables and then the problem would be solved. I will try to write some code. If you need to test it, you could buy the bluepill board+stlink, they are very cheap (2 dollars + shipping). I do not understand much of yml files, but I will try also. Soon I will come back with news. Seeya. And thanks for the library, it is very useful. |
I was actually considering the STM32F4 series (likely a black pill). I already have a debugger board. Can you provide some links to the SDK (like docs/download)? I'd be better equipped to help with the yml/CI then. |
Hi, yes I can. The F4 is very powerful. The easiest kit consists in using STM32CubeIDE. You can also use CMake with these microcontrollers, but I would let that for later. |
I ordered a black pill from AliExpress for $9. I prefer to have gone with a more official distributor because AliExpress (& other amazon-like stores) are littered with DIY electronics clones (which often cut corners when it comes to power circuits).
CMake is exactly the approach I aim to take with the CI; we can't install apps in CI that depend on using a GUI. I also want to make sure that this contribution won't affect the stm32duino core (assuming it uses the same SDK).
Take your time with the rewrite. I won't be able to test this until my black pill comes (estimated mid September). I've also gotta learn how to use the SDK (CMake is typically my preferred build option). I don't mean to be overbearing, and I think I tend to be with new contributors. I really am here to help because we do have some conventions that contributions should follow. BTW, the CI workflows (which use github actions) should tell you if your code broke something or doesn't fit with our code style, so I highly recommend you enable github actions for your fork before pushing another commit. |
Hi, you are not overbearing. You are actually very kind. About the stm32 mcu: some time ago, I have bought 10 bluepills and ... all of them were fake. It is very frustrating. From now on, I am using only the Nucleo boards sold by mouser/digikey. If you want to learn about the CubeHAL api, I may recommend two good course on udemy, here and here. I decided to try to push initial support to STM32 because I was losing code every time this library gets updated. Now, I am very proud of my last piece of code because, for the first time, I was able to build this library without any change to RF24.h, RF24.cpp and RF24_config.h (although I cheated and created includes manually, but I do not care for this). Even if the new code is not acceptable for publishing it here, I am very happy with it because from now on, I will only copy new updates into the library. Anyway, thanks. What have I done:
The STM32 mcu may have more than one SPI, so it is nice to let the user to decide what spi to use. About the CMake: I use CMake, but I am now very good at it. I really spent some time reading your CMake files, and it is too much sophisticated for me. So, I wrote some few lines to build the rf24 static library. I also verified a small inconvenient: I have completely forgotten about a dependency of the CubeHAL. It requires a configuration file ("stm32f1xx_hal_conf.h") that is deeply connected to the application code. So it is valid to assume that the library will not be able to be built alone, only with application code. I do not know if this is a problem. Finally, the library was tested and the radio ... worked! I will wait for your reply to decide how to proceed. My best regards. |
I want this to get accepted! This kind of contribution is exactly what we look forward to! Thanks for all the informative links too. It looks like what I would consider an STM32 SDK is split up into framework components. The docs for these components seem sparse without looking at the code. I haven't registered an account with the STM32 site yet, so I haven't downloaded anything yet (kinda weird that they require that).
I can help with that as I introduced the overloaded
I was just looking at the platformIO integration for the STM32Cube framework, and it looks like this is handled like a build environment variable (which probably translates into a
This answer is going to be a little daunting, but we usually create a new example folder for this purpose. If it isn't too much trouble, I'd like to get a port of the GettingStarted example to a new folder called examples_stm32 (at repo root). It is preferable to use as much native code from STM32Cube framework as possible (aside from the code that exemplifies using RF24). I had to do the same thing for the PicoSDK. Beneficially, once the CI is up and running, we can get the build artifacts from the workflow and flash them directly to the MCU (the build_rp2xx.yml produces both elf and hex artifacts for most boards supported). In the case of building these artifacts for different boards, I used a default_pins.h in the examples_pico/ that streamlines the default pins used for the radio. The pico SDK actually has default SPI pins defined for each supported board, so this examples_stm32/default_pins.h may be quite different. However, the default_pins.h idea is completely optional (the Arduino examples don't do this for simplicity). |
Hi, today was a busy day. I finished uploading the latest code here. The spi class may be considerably improved, for example, by checking if the pointer is valid (i.e., not nullptr) before calling the st api. The radio initialization would be something like:
I will try to rewrite the examples. Seeya. |
If there's a way to detect that the STM32Cube framework is being used by CMake (like a defined CMake variable), then we can simply add a condition at the top of the root CMakeLists.txt file that forwards the process to the utility/STM32/CmakeLists.txt (which would basically be the CMakeLists_required_to_stm32.txt that you put in the repo's root). We do the same thing for the PicoSDK (using the CMake variable Lines 1 to 7 in 89358b2
Everything else in that root CMakeLists.txt file is for Linux only. |
I just soldiered pins to my STM32F4 board, and I'm still playing around with it. I needed STM32CubeProgrammer installed to flash circuitpython to it over USB... I going to merge your latest branch stm32-support into a branch on this repo (called "stm32cube"), so I can start playing around with your changes - the main intention is to keep your git history intact, so your good work is properly attributed. I'm leaving this PR open as reminder. Unfortunately, we cannot merge this support into the master branch yet. When I clone your stm32-support branch to upstream here, I will close this PR and open an issue to continue discussions. I'll keep you posted... |
I have never flashed a stm32 through usb, but that sounds great. If you successes, please tell me. I was looking at the RF24 examples and one issue is the print/printf function. Although they are existed because of stdio.h, they are not implemented. I have found this post about how to enable the basic stdio functions in stm32 where they implement the low level mechanism of printf. What do you think? |
STM32F103 doesn't ship with a DFU capable bootloader, so I'd be surprised if the blue pill can be flashed over USB. The Arduino cores seem to have worked around this by using a HID-based soft bootloader that looks for a magic value and resets the board. I tried for hours trying to get that working on my STM32F4, but I gave up... I'll likely only use PlatformIO with the Arduino framework for this board.
I don't really know the STM32Cube framework that well yet. Initially, I'd recommend using |
discussion is continued in #872 |
This commit adds initial support to the STM32 when using the CubeMX/CubeIDE/CubeHAL software or API, i.e., not Arduino like interface or API. This code was tested with the STM32F103C8T6 microcontroller.