MySensors icon indicating copy to clipboard operation
MySensors copied to clipboard

Add STM32 cores support

Open KooLru opened this issue 4 years ago • 29 comments

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).

KooLru avatar May 24 '20 18:05 KooLru

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?

mfalkvidd avatar May 24 '20 20:05 mfalkvidd

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.

KooLru avatar May 26 '20 18:05 KooLru

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?

tekka007 avatar May 29 '20 14:05 tekka007

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 :)

KooLru avatar Jun 03 '20 01:06 KooLru

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

vittoriocalzolari avatar Jun 11 '20 10:06 vittoriocalzolari

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 :)

KooLru avatar Jun 30 '20 19:06 KooLru

Hi,

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

Vittorio

vittoriocalzolari avatar Jul 03 '20 08:07 vittoriocalzolari

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.

spike314 avatar Aug 16 '20 21:08 spike314

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 avatar Aug 22 '20 16:08 eiten

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.

eiten avatar Aug 24 '20 05:08 eiten

Hi,

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

Fixed.

KooLru avatar Aug 24 '20 22:08 KooLru

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.

KarlVogel avatar Jan 30 '21 08:01 KarlVogel

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 :

https://github.com/platformio/platform-ststm32/issues/283#issuecomment-712381939

KooLru avatar Feb 24 '21 18:02 KooLru

I found an issue or two, maybe related to these two: https://github.com/stm32duino/Arduino_Core_STM32/issues/1443 https://github.com/stm32duino/Arduino_Core_STM32/pull/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 avatar May 01 '22 17:05 WhiskyDelta

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.

WhiskyDelta avatar May 03 '22 20:05 WhiskyDelta

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 avatar Jul 04 '22 00:07 Tico06

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 avatar Jul 04 '22 12:07 Tico06

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.

Tico06 avatar Sep 14 '22 15:09 Tico06

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.

WhiskyDelta avatar Sep 16 '22 19:09 WhiskyDelta

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.

Tico06 avatar Sep 18 '22 10:09 Tico06

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

mfalkvidd avatar Sep 18 '22 16:09 mfalkvidd

@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.

virtual-maker avatar Sep 19 '22 06:09 virtual-maker

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

Tico06 avatar Sep 19 '22 06:09 Tico06

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.

Tico06 avatar Nov 04 '22 16:11 Tico06

@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.

mfalkvidd avatar Nov 04 '22 16:11 mfalkvidd

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

Tico06 avatar Nov 04 '22 19:11 Tico06

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 avatar Nov 04 '22 19:11 Tico06

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.

Tico06 avatar Nov 29 '22 15:11 Tico06

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

nschurando avatar Dec 18 '23 10:12 nschurando