Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emard
    @emard
    Perhaps it talks to ftdi in libusb mode hmmm. I dont remember now is -P the same as without (but before at ujprog it wasnt) so maybe -P/dev/ttyUSB0 -t could open port in unix standard mode, maybe that would be more reliable. But fujprog obviously has there a bug
    fujprog -P/dev/ttyUSB0 -t doesnt work
    ujprog -P/dev/ttyUSB0 -t works
    Lawrie Griffiths
    @lawrie
    oot@buildroot:~# cat date.sh 
    R6=`i2cget -y 0 0x6f 0x06`
    R5=`i2cget -y 0 0x6f 0x05`
    R4=`i2cget -y 0 0x6f 0x04`
    R2=`i2cget -y 0 0x6f 0x02`
    R1=`i2cget -y 0 0x6f 0x01`
    
    YY="${R6:2:2}"
    MON="$((${R5:2:2}-20))"
    DD="${R4:2:2}"
    HH="${R2:2:2}"
    MM="${R1:2:2}"
    
    echo "20$YY-$MON-$DD $HH:$MM"
    root@buildroot:~# ./date.sh 
    2020-9-22 19:40
    Lawrie Griffiths
    @lawrie
    date -s "`./date.sh`"
    emard
    @emard
    I have 12F updated everything from images but not the bitstream. my /dev/i2c-0 exists but i2cdetect wont detect anything. RTC works from ESP32 and FPGA i2c bridge. Do I need new 12F bitstream?
    (I think I have to download it :)
    Lawrie Griffiths
    @lawrie
    I believe so
    emard
    @emard
    So far i2c is not working maybe I need to try to download again and refresh
    root@buildroot:/home/root/rtc# i2cget -y 0 0x6f 0x06
    Error: Read failed
    root@buildroot:/home/root/rtc# ls -al /dev/i2c-0 
    crw-------    1 root     root       89,   0 Jan  1 00:00 /dev/i2c-0
    Lawrie Griffiths
    @lawrie
    Have you got the latest bitstream?
    emard
    @emard
    Yes right now
    root@buildroot:/home/root/rtc# uname -a
    Linux buildroot 5.0.9 #2 SMP Tue Sep 22 14:10:04 BST 2020 riscv32 GNU/Linux
    Lawrie Griffiths
    @lawrie
    Bitstream should be 484632 bytes.
    emard
    @emard
    Hmm it isnt :)
    root@buildroot:/mt/fat/linux/smp# ls -al ulx3s_12f_1core_saxonsoc.bit
    -rwxr-xr-x    1 root     root        486868 Sep 18  2020 ulx3s_12f_1core_saxonsoc.bit
    Maybe I wrong downloaded
    Dolu1990
    @Dolu1990
    you need the last bitstream, as it added the connections to the i2c
    emard
    @emard
    It was wrong download, I found the bitstream
    OOOOYEEEE now it works
    root@buildroot:/home/root/rtc# ./date.sh 
    2020-9-22 19:09:
    emard
    @emard
    R0 was missing. those regs must be AND-filetered otherwise we have this
    root@buildroot:/home/root/rtc# ./date.sh 
    2020-9-22 19:11:91
    great achievement i2c !!!!!
    emard
    @emard
    #include <stdio.h>
    #include <stdlib.h>
    
    #define I2C_SLAVE 0x703
    #define O_RDWR 2
    
    int i2c_rtc;
    
    void rtc_open(int addr)
    {
      i2c_rtc = open("/dev/i2c-0", O_RDWR);
      ioctl(i2c_rtc, I2C_SLAVE, addr);
    }
    
    void rtc_read(unsigned char *buf, int reg, int n)
    {
      buf[0] = reg;
      write(i2c_rtc, buf, 1);
      read(i2c_rtc, buf, n);
    }
    
    void i2cdemo(void)
    {
      int i;
      unsigned char buf[7];
      // mask for BCD          SEC   MIN   HOUR  WKDAY DAY   MONTH YEAR
      unsigned char mask[7] = {0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x1F, 0xFF};
    
      rtc_read(buf, 0, sizeof(buf));
      for(i = sizeof(buf)-1; i >= 0; i--)
        printf(" %02x", buf[i] & mask[i]);
      printf("\n");
    }
    
    int main(int argc, char *argv[])
    {
      int i;
      rtc_open(0x6F);
      for(i = 0; i < 60; i++)
      {
        i2cdemo();
        sleep(1);
      }
      return 0;
    }
    root@buildroot:/home/root/rtc# ./a.out 
     20 09 22 02 21 14 27
     20 09 22 02 21 14 28
     20 09 22 02 21 14 29
     20 09 22 02 21 14 30
     20 09 22 02 21 14 31
    emard
    @emard
    Everything works and I hope that also read() of multiple registers does i2c atomic read at which RTC prevents reg update until read is finished
    Dolu1990
    @Dolu1990
    Nice :D
    emard
    @emard
    great stuff, I'playing with it. Can we also have shutdown gpio :)
    Or better to say, can shutdown raise shutdown pin so board powers off really
    Dolu1990
    @Dolu1990
    So, normaly, those feature should be integrated at the opensbi level
    emard
    @emard
    Wherever you suggest is the proper place. From bitstream, this pin needs a kind of "fuze" logic in order not to be triggered at early start of bitstream when the LUTs set up and can do some glitch.. I use some counter that starts from 0 and must be clocked few times. shutdown pin is connected to MSB bit of this counter.
    Lawrie Griffiths
    @lawrie
    @emard That is impressive, doing all the i2c access from C. And it good that lcc and its library had all the features you needed. Some of them only added in the last day or two.
    Dolu1990
    @Dolu1990
    i will add a ulx3s opensbi plateform specific port
    and already try the reboot ^^
    emard
    @emard
    @lawrie great stuff this i2c really, simple and works!
    @Dolu1990 yes reboot would be first step to make. For board shutdown it needs battery, configured RTC with alarm that triggers in the future and power from US2 or from US1 with green power LED set to OFF. I can assist with this
    Dolu1990
    @Dolu1990
    Are you aware of a blackbox to instanciate in the FPGA to be able to reload the bitstream when asked ?
    Or i should use the PROGRAMN FPGA input pin via USER_PROGRAMN from the schematic
    emard
    @emard
    I actually didnt know of blackbox but pulling down programn will reload bitstream from flash. If bitstream is build as multiboot (using command ecpmulti) then programn will jump to next bitstream in FLASH
    For your this blackbox will be better if it works as it will reload current bitstream having saxonsoc in FPGA SRAM (regardless what in FLASH is)
    emard
    @emard
    @pnru_gitlab I have used your hwclock to calculate date but it does it with few days off :) https://github.com/emard/hwclock4saxonsoc can you check whats up wrong
    Paul Ruiz
    @pnru_gitlab
    Again very little time today. I indeed had an issue with being 1 day off when I did that I2C code - maybe my code in date is also off and I now have matched errors on the Cortex :^). Here is a reviewed routine. @lawrie - in this form it is not suitable for c.lib, because it does not take an argument but works on a global var.
    emard
    @emard
    No problem I will find correct formula
    its called sakamoto-gregorian something
    Paul Ruiz
    @pnru_gitlab
    I think I took the algorithm in 4.2BSD as a base (several years ago). If I look at the code at the end of function gtime(), I think my reviewed routine is essentially the same (i.e. should be good).
    emard
    @emard
    Maybe I during editing typed something wrong. I will rewrite :)
    emard
    @emard
    The rewritten version is here now it matches with date -u --date="@<unix_seconds>" https://github.com/emard/hwclock4saxonsoc/blob/master/hwclock.c#L163 I dont know why it works :)
    hwclock -s will set correct system date from RTC
    Dolu1990
    @Dolu1990
    So i checked, the linux risc-v port used do not implement restart, only shutdown XD
    So, i got the shutdown command in linux to successfully restart the FPGA