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
Hi @kinsa this is a nice, but why did you redo something that is already done? OpenPLC Editor already supports STM32 boards. Instead of doing it from scratch, you could have just added support for the WS2N-14MR-S hardware using the current STM32 code. 
Reply 0 0
kinsa
I need to use FreeRTOS and implementing it on top of arduino would be too unwieldy. Code size is critical for lower end devices.
Reply 0 0
thiagoralves
Hey @kinsa I’m really interested in officially supporting this STM32-based PLC ( WS2N-14MR-S ) on OpenPLC. I’ve never heard of these PLCs before, they seem to be FX1N type clones from China. Since they are so cheap it seems to be a great target for OpenPLC users. Do you know if these devices come with any sort of bootloader that allows them to be programmed from the serial port? Having to use an STLink programmer would be a show stopper for many users here.
Reply 0 0
kinsa
There are plenty of FX series clones available out there and most of the users use the unlicensed version of the development platform.

There's a built-in STM32 uart bootloader that can be accessed by asserting the BOOT0 pin of the microcontroller during startup or after reset. (This assumes that they did not enable the level 2 readout protection of the chip otherwise the firmware will not be modifiable).

The bootloader can also be accessed from the user code; it's just a matter of listening for a special byte sequence on the the uart input and then switching over to the bootloader.

Note that a blue pill board with an ST link programmer can be had for less than $5 USD :-D



Reply 0 0
thiagoralves
Thanks for the info. I knew about the blue pill boards (I have a few), but I was looking for a more complete PLC hardware. I don’t know how robust it is, but a full PLC for under $50 seems magical. I just bought one for me to test. If there is an easy way to start the bootloader and upload code to it, it will be a great addition to OpenPLC
Reply 0 0
thiagoralves
One more question while I wait for my "FX3U" clone to arrive. Is this Serial db9 port wired to the UART on the STM32? Is this the same UART that is used by the bootloader?

The thing is, if I need to write a full blown tutorial involving STLink, soldering iron and some other DIY stuff to program this PLC, then I rather not even bother to add support for this device on OpenPLC. The community has a lot of newbies. A DIY tutorial like that would generate more questions than answers. But if the setup is more "plug-and-play" just involving plugging a serial cable and shorting boot0 pin, then that's pretty good for the community.
Reply 0 0
kinsa
The serial port on the boards that I have are bootloader ready, but YMMV.
Reply 0 0
rtuman
@thiagoralves 
It would be awesome if OpenPLC can support the "FX3U" clones and provide Modbus Slave and Master support.  I am currently testing a FX3U clone with an USB-to-serial converter (DB9).  I was able to connect to it from my PC using 38.4 kbps (EVEN, 7,1) and no swapping of Tx and Rd.

@kinsa 
Is it possible to retain a copy of the existing PLC firmware/OS before a new one is loaded?
Reply 0 0
thiagoralves
rtuman wrote:
@thiagoralves 
It would be awesome if OpenPLC can support the "FX3U" clones and provide Modbus Slave and Master support.  I am currently testing a FX3U clone with an USB-to-serial converter (DB9).  I was able to connect to it from my PC using 38.4 kbps (EVEN, 7,1) and no swapping of Tx and Rd.

@kinsa 
Is it possible to retain a copy of the existing PLC firmware/OS before a new one is loaded?

Modbus Master will not come to the micro runtime in the near future. The main runtime uses libmodbus for Modbus Master support. Unfortunately libmodbus footprint is too big for some microcontrollers, so the Modbus Master code would have to be rewritten from scratch in bare metal, just like the Slave code was. Not a straightforward task...

As for the existing PLC firmware, I found several copies of it on the wild. There are some Russian forums (that you can read with Google Translate) that distribute many versions of that firmware. In any case, the PLC is so cheap that if you break it, just buy a new one 🙂
Reply 0 0
rtuman
Understood.  Modbus Slave will suffice.  I'll be anxiously waiting for OpenPLC support for the  FX3U clones!

Thank you so much for the good work.
Reply 0 0
kinsa
The μC is readout protected so it is not easy to extract the original firmware.

I'm using https://github.com/Jacajack/liblightmodbus library; Modbus Master is part of the big TODO list.

Do note that these FX clones also use STM32 clones.
Reply 0 0
kinsa
The code for enabling the STM32 UART bootloader is now ready.

The bootloader is accessed by sending 3 break signals on the serial port.
Reply 0 0
thiagoralves
3 break signals, like UART control break? Is that standard or is it something they implemented on their firmware? I'm wondering if regular usb->serial adapters will be able to send that.
Reply 0 0
kinsa
My other usb adaptor doesn't generate that signal.

It's not a standard. Any string sequence that is not a valid modbus rtu can be used as a trigger to start the bootloader.

This is just for convenience, the proper way for triggering the bootloader is using the BOOT0 pin.
Reply 0 0
Reply