HBleier
I am trying to get Sequent megabas to run on a RockChip RK3566.
I had to recompile the cli util megabas and change the line in the comm.c file from "/dev/i2c-0" to "/dev/i2c-2" due to the IO mapping differences between broadcom and rockchip's to the physical pin 3 & 5. This all worked well and I can now talk to the board using the cli util. Like when I do a "megabas -list" it finds the board and when I do "megabas 0 board" it prints the mcu temperature and voltages and firmware revision of the hat.
 
My problem is now I used OpenPLC_editor to write this:
PROGRAM program0
  VAR
    SM_BAS0 : SM_BAS;
    Stack : SINT := 0;
    Set_In1_T : UINT := 1;
  END_VAR
  VAR
    Uni_V1 AT %IW0 : UINT;
  END_VAR
  VAR
    _TMP_REAL_TO_UINT5_OUT : UINT;
  END_VAR

  SM_BAS0(STACK := 0, IN1_T := 1);
  _TMP_REAL_TO_UINT5_OUT := REAL_TO_UINT(SM_BAS0.UNIV1);
  Uni_V1 := _TMP_REAL_TO_UINT5_OUT;
END_PROGRAM


CONFIGURATION Config0

  RESOURCE Res0 ON PLC
    TASK task0(INTERVAL := T#20ms,PRIORITY := 0);
    PROGRAM instance0 WITH task0 : program0;
  END_RESOURCE
END_CONFIGURATION
 
I goto the web interface and upload it to the runtime it compiles and fails with:
 
Optimizing ST program...
Generating C files...
POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c
Moving Files...
Compiling for Raspberry Pi
Generating object files...
In file included from Config0.c:10:
POUS.h:13:3: error: ‘SM_BAS’ does not name a type
   13 |   SM_BAS SM_BAS0;
      |   ^~~~~~
Error compiling C files
Compilation finished with errors!
 
Does anyone know what is wrong I selected the Sequent Microsystems hardware layer. Is there something that I am missing? Is there a step that I missed when setting up the runtime that is causing this?
Reply 0 0
thiagoralves
Make sure you have the latest version of the runtime installed in your board. Have you cloned it from the master branch recently? 
Reply 0 0
HBleier
Yes I cloned it yesterday, I built it with './install.sh rpi', then when it finished I installed wiringpi latest from the GitHub.com/wiringpi repo. Then rebooted, when it came back up I logged into openplc runtime went to the hardware layer page and selected the 'sequent hats' and pressed save it compiled and I again rebooted to make sure everything loaded up properly. Then I tried the *.st file that the editor created it compiled but gave me the error that you see on my last post.

There isn't any other steps that I am missing? Like before the hardware layer I saw that you guys were using psm layer and you had to cut and paste some python code to do what the hardware layer does now. Or at least that's how I think the hardware layer works now.

I have tried tinkering with the runtime now, I found in the core directory the hardware_layers.cpp and I found 'sprintf(filename, "/dev/i2c-0");'. I changed it to '/dev/i2c-2' to match what I was doing with sequent's cli util. But I don't think that is the problem now, it looks like the runtime can't find an entry for the sm_bas functional block. Please let me know what I should try next.

Thanks for the quick reply @thiagoralves
Reply 0 0
thiagoralves
Yes, most likely the Sequent driver is broken. Sequent themselves wrote and maintain the driver. I only accept pull requests 😅 
I will take a look to see if it is an easy obvious fix. If it isn't, then we will have to wait for them to chime in. I'm pretty sure this does not have anything to do with the fact that you are on a different platform - the driver was written for the Raspberry Pi. The error you're getting is in the driver lib itself, so it should be broken even on the Pi.
Reply 0 0
thiagoralves
#if defined(__linux__) && defined(__arm__) && defined(SEQUENT)
    #include "sm_cards.h"
#endif
I was wrong... the driver explicitly checks if this is running on a Raspberry Pi to include the driver file. Most likely your ifdef should be __aarch64__ instead of __arm__. Or maybe even removing the ifdef entirely should work for you.
Reply 0 0
HBleier
Thank you! As soon as I get back to the office in a bit I will give it a try. Thanks so much for looking into it. I will let you know if this fixes it, also for anyone else crazy enough to use a different board to substitute for RPi. This is why I like open source if this wasn't all open source these changes would be almost impossible to do without sequent's help directly.

I was using a contemporary controls hat and couldn't get RPi's to drive them. So I was trying to edit their comm cli util to support rockchip and they would work with me. I offered to buy access to their source and even sign a NDA not to ever release it and they wouldn't budge. I was spending tens of thousands of dollars buying hardware from them (not no more). Long story short I am never using a product again in our production that is not fully open source. It's just not worth it things change so rapidly with product availability you need to be able to make quick changes like this on your own to make stuff work. Now I am gonna have to rip their hats out and replace them with these sequent hats. During some power outages their mcu locks up and cuts comm with the arm board they were using the gpio uart and not i2c like the sequent ones do, to talk back to the host. In my testing with sequent hats on RPi on my bench test I have not been able to lock them up. So I am pretty confident that this will get rid of my issues once I have it working on the rockchip that are on the job site.

Thank you Thaigo for creating such an awesome and very useful project. I have been contributing on patreon because I want to see this project keep going. Keep up the awesome work my friend!
Reply 1 0
Reply