kinsa
Hi,

I just want to share my work on running OpenPLC on STM32 hardware.

https://github.com/kinsamanka/openplc-stm32-freertos

My goal is to run OpenPLC on cheap hardware that you can find on Aliexpress (try "WS2N-14MR-S").

It is using PlatformIO for the build environment so that it will be easy to port to other platform/architectures.

At the moment the code is configured for an AMSAMOTION ETH-MODBUS-IO5R module with a working modbus tcp slave.

Note that this is still an ongoing WIP.
Reply 5 0
thiagoralves
This is interesting @kinsa. How are you doing the slave configuration parameters? It would be awesome if you could add your contributions to the official OpenPLC Editor repository. I know you're using platformIO instead of arduino-cli, but I believe that it shouldn't be too hard to port your efforts over to OpenPLC Editor, and it would benefit a lot of people
Reply 1 0
kinsa
The configuration is just an array of const structs.

https://github.com/kinsamanka/openplc-stm32-freertos/blob/master/src/modbus_slave.h

Regarding integration, that's the long term goal. PlatformIO can easily handle the existing arduino codebase.  Importing the arduino code would be my next task once I've ironed out the Modbus master.
Reply 0 0
thiagoralves
It would be better to do this as PLC function blocks on the editor, way more user friendly. The integration part I mean is for it to be more transparent to the user, so that the average Joe doesn’t have to edit .c source code files by hand 
Reply 0 0
kinsa
I've looked at the manuals  (https://www.amsamotion.store/wp-content/uploads/2021/09/AMX-FX3U_V1.2.pdf) on how it is done one the original programmer but I don't have any idea yet on how to implement it.

I was leaning more on the way the original Beremiz implements it.
Reply 1 0
kinsa
I've partially converted the existing arduino code to use PlatformIO; it's not really hard:

https://github.com/kinsamanka/openplc-pio-arduino

It's actually leaner too.
Reply 0 0
kinsa
I've tried porting the Modbus stack and now the Uno and Pro Micro boards have gained Modbus Master capabilities.

With extra free ram and code space too (for Pro Micro, with both master and slave enabled):

Building in release mode
Compiling .pio/build/micro/src/Baremetal.ino.cpp.o
Linking .pio/build/micro/firmware.elf
Checking size .pio/build/micro/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  36.5% (used 934 bytes from 2560 bytes)
Flash: [=====     ]  53.6% (used 15374 bytes from 28672 bytes)


The code for the Uno board is even smaller.

The only issue is that the changes are extensive, no way of testing all boards.
Reply 0 0
kinsa
BTW, the slave configuration is done using the editor

editor.png
Reply 3 0
thiagoralves
This is awesome! I'll check your code and see if I can integrate it into blocks that can be used on any platform. This would be pretty cool.
Reply 0 0
kubilay kerti
I developed it from modbus support for modbus. I'm testing it.
modbus.png
Reply 0 0
thiagoralves
Hey @kinsa I'm trying to finally add support for these STM32 PLCs on OpenPLC, but my main road block has been arduino-cli. I can upload code from Arduino IDE normally, but for some reason, arduino-cli won't upload the code to the board complaining about STM32_Programmer_CLI even though it is installed on the system:
arduino-cli.exe -v upload --port COM30 --fqbn STM32:stm32:GenF1:pnum=Generic_F103VC,upload_method=serialMethod C:\Users\Win10\Documents\Arduino\Blink_FX3U
Error initializing instance: Loading index file: loading json index file C:\Users\Win10\AppData\Local\Arduino15\2>&1: open C:\Users\Win10\AppData\Local\Arduino15\2>&1: The filename, directory name, or volume label syntax is incorrect.
"C:\Users\Win10\AppData\Local\Arduino15\packages\STM32\tools\STM32Tools\1.4.0/tools/win/stm32CubeProg.bat" 1 "C:\Users\Win10\AppData\Local\Temp\arduino-sketch-7DA1CDC5C6F0BA41CFE3F0B7FAE61854/Blink_FX3U.ino.bin" COM30 -s
'STM32_Programmer_CLI.exe' is not recognized as an internal or external command,
operable program or batch file.

I believe that the stm32CubeProg.bat file is incorrectly setup and can't find my STM32 installation. If I copy over the STM32_Programmer_CLI.exe to the folder where arduino-cli is executed, AND set the %PATH% variable to include the STM32 installation as well (only setting the path does not work) then the upload process works just fine.

Did you have any issue related to this?
Reply 0 0
kinsa
I have not actually tried using the arduino-cli program.

But a couple of things stands out from the error: the
2>&1
redirection (not sure if it is valid under windows), and the backslash and forward slash mix on the
C:\Users\Win10\AppData\Local\Arduino15\packages\STM32\tools\STM32Tools\1.4.0/tools/win/stm32CubeProg.bat
command.

BTW, I'm nearly done with the UI, I hope to finish it this week.
Reply 1 0
thiagoralves
I found out the issue. The stm32CubeProg.bat file is messed up. I will make a PR to the STM32duino project with the fix and work on my local copy while it is not merged. Once that is up and I finish writing the hal file, uploading to STM32 PLCs will be as easy as uploading to any other board on the list. Well, almost. There is still the catch to invoke the serial bootloader using the BOOT0 pin. I wish there was a simpler way to jump to it from user code. Do you know if that's possible? This would make the programming part so much easier.
Reply 0 0
kinsa
I'm using a custom serial bootloader that conforms to the STM32 serial DFU protocol.

The only difference with the standard is that to invoke the bootloader, a special sequence of bytes is sent to the port.
Reply 0 0
thiagoralves
Guys, please try the new FX3U entry on your devices. I tested on mine and it works great, even with Modbus RTU. Do any of you have an "FX3U" device with built in Ethernet? I wonder how that works internally as I wanted to give support for Modbus/TCP on those PLCs as well.
Reply 1 0
William Zhang
Guys, please try the new FX3U entry on your devices. I tested on mine and it works great, even with Modbus RTU. Do any of you have an "FX3U" device with built in Ethernet? I wonder how that works internally as I wanted to give support for Modbus/TCP on those PLCs as well.

Hi, thiago, also the amsamotion, they have a FX3U with ethernet,  http://mall.amsamotion.com/item-1010.html
fx3u.png
Reply 0 0
Reply