Skip to content
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

Add STM32 cores support #1422

Open
wants to merge 16 commits into
base: development
Choose a base branch
from
Open

Conversation

KooLru
Copy link
Contributor

@KooLru KooLru commented May 24, 2020

This pull request adds initial support for STM32 Cores https://github.com/stm32duino/Arduino_Core_STM32 officially developed Arduino STM32 boards package from STMicroelectronics. It is based on HAL and LL libraries.

It has been tested with the Blue Pill (STM32F103C8T6).

@mfalkvidd
Copy link
Member

Thanks for this contribution. I don't know much about the hal, but I have one question: how does this relate to the existing stm32f hal? Should stm32f users use the hal in this pull request instead? Or should we keep both?

@KooLru
Copy link
Contributor Author

KooLru commented May 26, 2020

Thanks for this contribution. I don't know much about the hal, but I have one question: how does this relate to the existing stm32f hal?

I quoted some chars about stm32duino history

basically two "stm32duino" cores which are supported

Roger's core "Arduino_STM32" - based on Leaflabs libraries, focused mainly on BluePills and its derivates, still maintained by stm32duino web site veterans, works fine.

"Arduino_Core_STM32" - based on STM's HAL, the "new one", maintained by people close to STM, focused mainly on STM's Nucleo boards, accommodating the BluePills as well.

History background:

Roger started "stm32duino" site some 6y back, while the repo was placed on his github above.
Later on, by STM supported folk created github repo with a similar name, focused on the STM's Nucleo products.
The Roger's forum served as the support for both cores.

In meantime there were 2-3 repos created by veterans, forked from Roger's core, or HAL based.
I think the ones based on Roger's core have been merged to the above Roger's core already.

In late 2018 Roger announced he is going to close down the "stm32duino" site in April 2019, and he did. The veterans created a new one (see above the link) and there is a "read only old stm32duino" site still available, but partially broken - here - https://stm32duinoforum.com/forum/index_php.html

Should stm32f users use the hal in this pull request instead? Or should we keep both?

I ran only ethernet gateway on STM32F103, if someone use STM32 they can try compile their project with "new" platform.

I think you need to save both first time, they are different, but "mark" "old" as deprecated.

@tekka007
Copy link
Contributor

tekka007 commented May 29, 2020

Looks like this PR is based on https://github.com/tekka007/MySensors/tree/STM32duinoUpdate . Did you test the EEPROM emulation as I had issues in the past?

@KooLru
Copy link
Contributor Author

KooLru commented Jun 3, 2020

I use MY_SIGNING_SOFT that store data in EEPROM. It works.

I didn't follow this, I had to copy and paste the stm32 cores myself :)

@vittoriocalzolari
Copy link

Hello,

I have tried to compile and download the passive node example for a Nucleo F411RE but I got weird results.
The radio ( nRF24l01) is correctly initialized but wrong data are sent, I am attaching the debug log.
Arduino version is 1.8.12, STM32 core version 1.9.0

Ciao,

Vittorio
STM32_mysensors_passive_node_log.txt

@KooLru
Copy link
Contributor Author

KooLru commented Jun 30, 2020

I have tried to compile and download the passive node example for a Nucleo F411RE but I got weird results.

Looks like, that are you use https://github.com/tekka007/MySensors/tree/STM32duinoUpdate branch.

Can you try https://github.com/KooLru/MySensors/tree/stm32_cores ?

I ran this code on NUCLEO-F411RE dev board, and it works with #define MY_NODE_ID (without this define something gone wrong :)

@vittoriocalzolari
Copy link

Hi,

now it works, thanks. I have also successfully tested a Nucleo F303K8.

Vittorio

@spike314
Copy link

I have successfully run with STM32 "BlackPill F401CC" and "BlackPill F411CE" using an RFM69HCW. I am using the RFM69 new driver and had to add the default IRQ pin to RFM69_new.h -- Inserted at line 95:

#elif defined(ARDUINO_ARCH_STM32)
#define DEFAULT_RFM69_IRQ_PIN			(PA3)

After this, the code worked fine with both types of STM32 F4 black pill.

@mfalkvidd mfalkvidd mentioned this pull request Aug 21, 2020
@eiten
Copy link
Contributor

eiten commented Aug 22, 2020

Just tried it out on platformio, where I get errors.
platformio.ini:

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
framework = arduino
lib_deps =
    https://github.com/KooLru/MySensors.git#stm32_cores

output:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/blackpill_f411ce.html
PLATFORM: ST STM32 8.0.0 > WeAct BlackPill V2.0 (BlackPill F411CE)
HARDWARE: STM32F411CEU6 100MHz, 128KB RAM, 512KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32 4.10900.200819 (1.9.0) 
 - framework-cmsis 2.50501.200527 (5.5.1) 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <MySensors> 2.4.0-alpha #df37af9
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|   |-- <EEPROM> 2.0.1
|   |-- <IWatchdog> 1.0.0
Building in release mode
Linking .pio/build/blackpill_f411ce/firmware.elf
/home/edi/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/blackpill_f411ce/src/main.cpp.o: in function `premain()':
main.cpp:(.text.startup._Z7premainv+0x0): multiple definition of `premain()'; .pio/build/blackpill_f411ce/FrameworkArduino/main.cpp.o:main.cpp:(.text.startup._Z7premainv+0x0): first defined here
/home/edi/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/blackpill_f411ce/src/main.cpp.o: in function `main':
main.cpp:(.text.startup.main+0x0): multiple definition of `main'; .pio/build/blackpill_f411ce/FrameworkArduino/main.cpp.o:main.cpp:(.text.startup.main+0x0): first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/blackpill_f411ce/firmware.elf] Error 1

I will try again on baremetal Arduino IDE (which I hate to develop for STM32 but well...) and report back...

@eiten
Copy link
Contributor

eiten commented Aug 24, 2020

I will try again on baremetal Arduino IDE (which I hate to develop for STM32 but well...) and report back...

It works on Arduino IDE. I'll file a Issue over at STM32duino platformio framework.
I have a node in heavy testing, I'll report if any problems occur.

@KooLru
Copy link
Contributor Author

KooLru commented Aug 24, 2020

Hi,

#elif defined(ARDUINO_ARCH_STM32)
#define DEFAULT_RFM69_IRQ_PIN			(PA3)

Fixed.

@KarlVogel
Copy link

Just tried it out on platformio, where I get errors.
platformio.ini:

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
framework = arduino
lib_deps =
    https://github.com/KooLru/MySensors.git#stm32_cores

output:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/blackpill_f411ce.html
PLATFORM: ST STM32 8.0.0 > WeAct BlackPill V2.0 (BlackPill F411CE)
HARDWARE: STM32F411CEU6 100MHz, 128KB RAM, 512KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32 4.10900.200819 (1.9.0) 
 - framework-cmsis 2.50501.200527 (5.5.1) 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <MySensors> 2.4.0-alpha #df37af9
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|   |-- <EEPROM> 2.0.1
|   |-- <IWatchdog> 1.0.0
Building in release mode
Linking .pio/build/blackpill_f411ce/firmware.elf
/home/edi/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/blackpill_f411ce/src/main.cpp.o: in function `premain()':
main.cpp:(.text.startup._Z7premainv+0x0): multiple definition of `premain()'; .pio/build/blackpill_f411ce/FrameworkArduino/main.cpp.o:main.cpp:(.text.startup._Z7premainv+0x0): first defined here
/home/edi/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/blackpill_f411ce/src/main.cpp.o: in function `main':
main.cpp:(.text.startup.main+0x0): multiple definition of `main'; .pio/build/blackpill_f411ce/FrameworkArduino/main.cpp.o:main.cpp:(.text.startup.main+0x0): first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/blackpill_f411ce/firmware.elf] Error 1

I will try again on baremetal Arduino IDE (which I hate to develop for STM32 but well...) and report back...

Was playing around with this and bumped into the same issue. It stems from the fact that the platformio stm32 arduino environment has a main.cpp which is included. This:

https://github.com/stm32duino/Arduino_Core_STM32/blob/6b6a2546f2a7bfa5195a704eed3494dc53808f14/tools/platformio-build.py#L338

adds all the .cpp files from the cores/arduino directory, including:

https://github.com/stm32duino/Arduino_Core_STM32/blob/6b6a2546f2a7bfa5195a704eed3494dc53808f14/cores/arduino/main.cpp

which conflicts with the main from this stm32 MySensors:

https://github.com/mysensors/MySensors/blob/c5a3b8b68088dac3ab601790260a12af7d50450f/hal/architecture/STM32F1/MyMainSTM32F1.cpp

Haven't found a way to exclude the platformio main. There's some feature in platformio to filter the source list, but that only seems to work on your own project's files, just removing/renaming the platformio's main.cpp does make the compile/link succeed, but that's a bit heavy handed.

@KooLru
Copy link
Contributor Author

KooLru commented Feb 24, 2021

just removing/renaming the platformio's main.cpp

Or add _ _ attribute _ _ ((weak)) before framework-arduino preinit() and main() functions ...
~.platformio/packages/framework-arduinoststm32/cores/arduino with :

platformio/platform-ststm32#283 (comment)

@WhiskyDelta
Copy link

I found an issue or two, maybe related to these two:
stm32duino/Arduino_Core_STM32#1443
stm32duino/Arduino_Core_STM32#1129

When I try to compile the standard GatewaySerial sketch (propably also happens with different examples) with for the BluePill F103C8 I get this error:

In file included from C:\Users\arnes\Documents\Arduino\libraries\MySensors/MySensors.h:71,
                 from C:\Users\arnes\Documents\Arduino\libraries\MySensors\examples\GatewaySerial\GatewaySerial.ino:86:
C:\Users\arnes\Documents\Arduino\libraries\MySensors/hal/architecture/STM32/MyHwSTM32.cpp: In function 'void hwReadConfigBlock(void*, void*, size_t)':
C:\Users\arnes\Documents\Arduino\libraries\MySensors/hal/architecture/STM32/MyHwSTM32.cpp:52:2: error: 'eeprom_buffer_fill' was not declared in this scope
   52 |  eeprom_buffer_fill();
      |  ^~~~~~~~~~~~~~~~~~
C:\Users\arnes\Documents\Arduino\libraries\MySensors/hal/architecture/STM32/MyHwSTM32.cpp:54:12: error: 'eeprom_buffered_read_byte' was not declared in this scope
   54 |   *dst++ = eeprom_buffered_read_byte(offs++);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\arnes\Documents\Arduino\libraries\MySensors/hal/architecture/STM32/MyHwSTM32.cpp: In function 'void hwWriteConfigBlock(void*, void*, size_t)':
C:\Users\arnes\Documents\Arduino\libraries\MySensors/hal/architecture/STM32/MyHwSTM32.cpp:63:3: error: 'eeprom_buffered_write_byte' was not declared in this scope
   63 |   eeprom_buffered_write_byte(offs++, *src++);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\arnes\Documents\Arduino\libraries\MySensors/hal/architecture/STM32/MyHwSTM32.cpp:65:2: error: 'eeprom_buffer_flush' was not declared in this scope
   65 |  eeprom_buffer_flush();
      |  ^~~~~~~~~~~~~~~~~~~
exit status 1
Fehler beim Kompilieren für das Board Generic STM32F1 series.

This can be resolved by adding "#include <EEPROM.h>" in MyHwSTM32.h
I don't know if the resulting binary works though, because I have no hardware to test.
When I change the board to a STM32L0xx or STM32L1xx variant however, this solution does not work.

@WhiskyDelta
Copy link

What is the state of this PR? I see that there are some checks that were not successful, but when i click on "Details" I only get a 502 error.
I have forked KooLrus fork and fixed the eeprom problem and tried to implement sleep:
https://github.com/WhiskyDelta/MySensors/tree/stm32_cores
Maybe that helps.

@Tico06
Copy link
Contributor

Tico06 commented Jul 4, 2022

Hi There,

This is, for me, a very high interesting proposal. STM32 products offer a very wide set of possibilities in terms of power saving, memory and so. hopefully this will be merged in dev.

thx and br

Eric.

@Tico06
Copy link
Contributor

Tico06 commented Jul 4, 2022

Guys,
Looks like we have parallel and duplicate efforts to port to STM32:
#1422
#1437
#1486

Please could you cooperate on this. I am looking forward on STM32 support, including STM32Lx

Thx and BR,

Eric.

@Tico06
Copy link
Contributor

Tico06 commented Sep 14, 2022

Hi There,

I am interested in the STM32 support. What can I do to progress on this ? Checks look freezed in ESP8266/Arduino Mega - Examples...

Not sure @KooLru is around ? How could someone handover ?

thanks and regards,

Eric.

@WhiskyDelta
Copy link

Hi Tico06,
I would not get my hopes too high, since already since may noone reacted. I fear that MySensors is dying. But you can try out my fork I linked to above. It seems to work, but it is not properly tested.

@Tico06
Copy link
Contributor

Tico06 commented Sep 18, 2022

Hi Tico06, I would not get my hopes too high, since already since may noone reacted. I fear that MySensors is dying. But you can try out my fork I linked to above. It seems to work, but it is not properly tested.

Thanks a lot @WhiskyDelta for your answer. I'll give it a try.

I am afraid you are right saying MySensors is dying. I just love this project, and have implemented some sensors and actuators in my house and around. I am wondering why such project is not supported anymore. Is it due to hardware availability/affordability ? Or maybe developers leaked to a "concurrent" project ?
thanks and regards,

Eric.

@mfalkvidd
Copy link
Member

yes, interest is falling. This is statistics from the mysensors forum for the last 2 years (I was not able to get any older data)

AB73F6B1-1611-403C-8C25-9C363826B6AB

@virtual-maker
Copy link
Contributor

@WhiskyDelta, @Tico06, @mfalkvidd, @KooLru,
Your extensions for the new STM32 architecture look promising. Thank you for sharing.

Unfortunately, @KooLru's commits are a bit outdated and the branch with @WhiskyDelta's commits is difficult and complicated.

I will try to tidy up your commits and combine them into a new up-to-date feature branch.

Then some of your changes still need to be discussed here. But I am very confident that your new STM32 architecture can be included in development.

@Tico06
Copy link
Contributor

Tico06 commented Sep 19, 2022

Thanks a lot @virtual-maker! Looking forward to progress on this.

virtual-maker added a commit to virtual-maker/MySensors that referenced this pull request Sep 19, 2022
@Tico06
Copy link
Contributor

Tico06 commented Nov 4, 2022

Hi There,
I tried to quick compile a sample from MySensors targeted to STM32F1 and get this error:

In file included from /home/eric/.var/app/cc.arduino.IDE2/cache/.arduinoIDE-unsaved2022104-31-zo9398.qtqs/Node2Node/Node2Node.ino:47:
/home/eric/Arduino/libraries/MySensors/MySensors.h:83:2: error: #error Hardware abstraction not defined (unsupported platform)
   83 | #error Hardware abstraction not defined (unsupported platform)
      |  ^~~~~

exit status 1

Compilation error: exit status 1

Looks like ARDUINO_ARCH_STM32F1 is not defined. Any clue to drive me ?

Thx and reg

Eric.

@mfalkvidd
Copy link
Member

@Tico06 which branch did you use? That error is on line 86 in KooLru’s code so my guess is that you used the wrong branch by mistake.

@Tico06
Copy link
Contributor

Tico06 commented Nov 4, 2022

Arrff... my bad... thanks @mfalkvidd , I didn't pay attention to the branche. I guess it should be topic/mkr/issue1422 ?

@Tico06
Copy link
Contributor

Tico06 commented Nov 4, 2022

Ok, fine. It compiles without error !

I had to install STM32LowPower and STM32RTC.

I'll setup a RFM69 node with a temp sensor and report here my findings. If you want I perform some specific tests, please ping me. I have RFM69, NRF24.

thx and reg

Eric.

@Tico06
Copy link
Contributor

Tico06 commented Nov 29, 2022

Hi There,

So, I found some time to spent on this... I have a STM32F103C6Tx and it looks qiete short in flash capacity to store the binary:

Using board 'GenF1' from platform in folder: /home/eric/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0

...

/home/eric/.arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /home/eric/.var/app/cc.arduino.IDE2/cache/arduino-sketch-78B17CBF48820C947A0EB44B8E69FC8B/SHT31Sensor.ino.elf section `.text' will not fit in region `FLASH'
/home/eric/.arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 21952 bytes
collect2: error: ld returned 1 exit status
exit status 1

Compilation error: exit status 1

The same code fits very well in Atmega328P with 32k of flash. How could I produce with a lower binary footprint ?

I have order a STM32F103C8T6, nevertheless, I'd like to have a lighter binary. Any specific options in the Arduino IDE or in the code ?

thanks and regards,

Eric.

@nschurando
Copy link

Hi everyone.

I'm in the process of designing a sensor that the ATmega328P is not really cut out for. So I'm really happy to see there has been some great efforts to bring support for the STM32. Thank you.

At the moment, it seems both @KooLru and @virtual-maker branches compile. Is there any preferred one?

Finally, if there's anyway that I could contribute getting support for STM32 merged for good, I'd be happy to help.

Regards,

Nicolas

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.