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
Quick update: my FX3U finally arrived. It turns on just fine, but I wasn't able to program it. There aren't any obvious boot0 pads on the board. I did a small just to pull it up, reset the board and the PLC entered in bootloader mode. But then when I try to upload any code I end up in a timeout. It could be possible that I have a bad USB<->Serial cable (unlikely as I use it for other applications as well) or that the Serial port on the device is not wired to the correct UART. I'll have to debug further
Reply 1 0
kinsa
Could you post a hi-res picture of the board?

You will need to disable the read protection bit before you can upload the firmware.

stm32flash -k /dev/ttyUSB0
Reply 0 0
kinsa
Assuming the connections are correct, the following command should give info about the board:
stm32flash /dev/ttyUSB0
Reply 0 0
thiagoralves
The board does not have any USB connectors. Should I wire it up to the usb pins on the MCU to read the board info? Or can it be retrieved through serial?
Here is a high-res pic of the board:
Reply 0 0
kinsa
The commands are for the serial port connection. 

I'm not sure if the serial port needs a cross cable. Does it work with the GX Works software?

If it doesn't then you need to swap pins 2 & 3 of the serial port.

BTW, the J10 port (the 4 circular pads on top of U19) is the stlink programming port.
Reply 0 0
kinsa
I've ordered the same model but from different manufacturer. Let's see how standardised they are.
Reply 0 0
thiagoralves
kinsa wrote:
Does it work with the GX Works software?

Never tried. Is that software free?
kinsa wrote:
BTW, the J10 port (the 4 circular pads on top of U19) is the stlink programming port.

I figured it would either be the st link port or Serial TTL.
kinsa wrote:
I've ordered the same model but from different manufacturer. Let's see how standardised they are.
That would be interesting to see. If they are not standardized then it will be impossible to add support for it on OpenPLC
Reply 0 0
kinsa
The software is free to use for a certain number of days and it is windows only.

I just realized that I have purchased the wrong one, FX3U-24MT instead of FX3U-14MT 🙄

According to this diagram, there's no need for a cross cable.
So-do-board-plc-mitsubishi-fx3U-14MT.jpg 
I think the issue is the other boot pin, BOOT1 is connected or used as a GPIO pin.
10149.png 
BOOT1 is pin PB2, 37th pin on the LQFP100 package.
Reply 0 0
kinsa
Studying your picture, this is BOOT0:

BOOT0.png 

And BOOT1 is connected somewhere:

BOO1.png 

(Notice how the tracks pins 38-42 are elongated suggesting it might not be connected/used)
Reply 0 0
thiagoralves
I thought about that too, but what intrigues me is that actually when I start the device with BOOT0 pulled up it seems that it actually enters in bootloader mode because whatever program it came with to blink the outputs doesn't run (I don't see any output LEDs blinking). I'll trace PB2 to figure out which input it is tied to (hopefully it is an input) and then make sure it is low on boot.

Which UART is used by the bootloader? I'm wondering if the Serial port is wired to a different UART, and that may be the problem. On the datasheet it seems that this MCU has up to 5 different UARTs. The board is using a least two, one for the Serial port and another for RS485
Reply 1 0
kinsa
The dfu bootloader for STM32F103 is fixed on UART1 (PA9/PA10).

The part number of this chip is not visible but this is most likely LS232 chip. Check whether any 2 of these 4 pins are connected to PA9-PA10. Note that there might be a series resistor between RX/TX pins and the UART chip.

uart.png 

PA9 and PA10:

pa9-10.png 

If you take a photo of the backside, we can easily trace the BOOT1 pin.

I'm pretty sure the hardware is standard. If you search the term
Quote:
三菱 FX3U-14MT-原理图
you'll see the schematics, BOM and the firmware offered for sale.
Reply 0 0
thiagoralves
U26 is indeed the RS-232 driver (SP232EEN). I checked that part pinout and found out that T2IN and R2OUT are connected to PA9 and PA10 on the STM32. So in fact the serial port is wired to UART1, which is great. Next step is figuring out how to program this thing. Perhaps the easiest way would be to burn a serial bootloader. Do you know any? The Mapple bootloader, as far as I can tell, is USB.
Reply 1 0
thiagoralves
I think I finally managed to access the bootloader. The trick was to reset the device with BOOT0 pulled high and with the PLC switch at the 'stop' position. For whatever reason that was the only combination that let me go through. Maybe that little switch is tied to BOOT1, I don't know...

However, the next challenge is that the device has the read protection bit set. Here is the output when I try to program it on Arduino:
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.11.0                  
      -------------------------------------------------------------------
Serial Port COM30 is successfully opened.
Port configuration: parity = even, baudrate = 115200, data-bit = 8,
                     stop-bit = 1.0, flow-control = off
Activating device: OK
Board       : --
Chip ID: 0x414 
BootLoader protocol version: 2.2
Warning: Device is under Read Out Protection
Error: RDP level is set to 1, try using Read UnProtect (-rdu) command in order to remove the Read Out Protection.

RUNNING Program ... 
  Address:      : 0x8000000
Response received from device: NACK
Error: START command not acknowledged!
Error: Start operation failed

Reply 1 0
thiagoralves
It worked!! A simple 
 C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin> .\STM32_Programmer_CLI.exe -c port=COM30 -rdu

did the trick!!

      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.11.0                  
      -------------------------------------------------------------------
Serial Port COM30 is successfully opened.
Port configuration: parity = even, baudrate = 115200, data-bit = 8,
                     stop-bit = 1.0, flow-control = off
Timeout error occured while waiting for acknowledgement.
Activating device: OK
Board       : --
Chip ID: 0x414 
BootLoader protocol version: 2.2
Device name : STM32F101/F103 High-density
Flash size  : 512 KBytes (default)
Device type : MCU
Revision ID : --  
Device CPU  : Cortex-M3

Memory Programming ...
Opening and parsing file: Blink.ino.bin
  File          : Blink.ino.bin
  Size          : 12.61 KB 
  Address       : 0x08000000 

Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 6]
Download in Progress:

File download complete
Time elapsed during download operation: 00:00:01.986
RUNNING Program ... 
  Address:      : 0x8000000
Start operation achieved successfully

Reply 1 0
kinsa
I think I finally managed to access the bootloader. The trick was to reset the device with BOOT0 pulled high and with the PLC switch at the 'stop' position. For whatever reason that was the only combination that let me go through. Maybe that little switch is tied to BOOT1, I don't know...


You can always check with a multi-meter between the switch and BOOT1 pin.

Looks like the device has 64KB of ram (according to the datasheet for 512KB of flash).

The WS214RS board has an STM32F030 chip with only 8KB of ram.

So using Arduino as a platform is not an issue with the FX3U boards.
Reply 1 0
Reply