You are reading a single comment by @fanoush and its replies. Click here to read the full conversation.
  • Hey all, I've put Espruino on a smartwatch (SN80-Y from Yfit) and have figured out most of the pins and components (lcd, accel, touch) but am having trouble getting the XTX XT25F32B (4MB flash) chip to be reliable. Verified the following pins using multimeter: CS=D19, SO=D18, SI=D17, CLK=D20. Doing a wakeup, followed by getting vendor ID and capacity seems fine:

    >  spif = new SPI();
    =SPI: {  }
    >  spif.setup({sck: CLK, miso: SO, mosi: SI, mode:0, baud: 8000000});
    =undefined
    >  spif.send([0xab], CS);
    =new Uint8Array([255])
    >  print(spif.send([0x90,0,0,1,0,0], CS));
    new Uint8Array([255, 255, 255, 255, 21, 11])
    =undefined
    >  print(spif.send([0x9f,0,0,0], CS));
    new Uint8Array([254, 11, 64, 22])
    =undefined
    

    That seems fine:22 at the end should mean 2^22 bits, or 4MB. So i've included it in my board file. In the devices section I have:

      'SPIFLASH' : {
                'pin_sck' : 'D20',
                'pin_mosi' : 'D17',
                'pin_miso' : 'D18',
                'pin_cs' : 'D19',
                'size' : 4096*1024, # 4MB
                'memmap_base' : 0x60000000 # map into the address space (in software)
      }
    

    And when flashed I see:

    >require("Storage").getFree()
    =4194304
    

    I then use this test script just to read the first few blocks of 256 bytes:

    CS=D19, SO=D18; SI=D17; CLK=D20;
    
    setTimeout(()=>{
      spif = new SPI();
      spif.setup({sck: CLK, miso: SO, mosi: SI, mode:0, baud: 8000000});
      spif.send([0xab], CS);
      print(spif.send([0x90,0,0,1,0,0], CS));
      print(spif.send([0x9f,0,0,0], CS));
      let hex = (d) => { return ('0'+d.toString(16)).slice(-2);};
      let buf = new Uint8Array(256);
    
      // 3 byte address: 0x7f 0xff 0xff (0x7f = 8MB, 0x3f = 4MB, 0x1f = 2MB)
      for(let b1=0; b1 < 1; b1++) {
        for(let b2=0; b2 < 5; b2++) {
          let bufstr = '';
          for(let b3 = 0; b3 < 256; b3++) {
            res = spif.send([0x03, b1, b2, b3, 0], CS);
            buf[b3] = res[4];
            bufstr += ("0"+buf[b3].toString(16)).slice(-2)+" ";
          }
          print(`${hex(b1)} ${hex(b2)} ${hex(b3)}: ${bufstr}`); //${btoa(buf)}`);
    
        }
      }
    }, 1000);
    

    The timeout was added because I was running into issues without it. This seems to work if I save it to RAM, as I get data (remnants from previous attempts to write):

    new Uint8Array([255, 255, 255, 255, 21, 11])
    new Uint8Array([254, 11, 64, 22])
    00 00 00: 04 04 00 00 54 45 53 54 ...
    00 01 00: 64 65 65 70 20 73 6c 65 ...
    00 02 00: 4c 4b 7d 20 20 41 42 3d ...
    00 03 00: 70 69 66 2e 73 65 6e 64 ...
    

    In the first line you can see the ASCII for "TEST" which was the name of the file I attempted to write in the IDE.
    So the problem is when I try to save the test code to Storage (or Flash):

    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v12.925 (c) 2021 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >
    FW addr 0x00000000 fail
    Status 0
    Uncaught Error: File already written with different data
     at line 1 col 1106
    ...{\n    for(let b2=0",0,1349);
                                  ^
    Uncaught Error: Too much data for file size
     at line 2 col 380
    ...    }\n  }\n}, 1000);",1024);
                                  ^
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v12.925 (c) 2021 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    new Uint8Array([112, 105, 102, 46, 115, 101])
    new Uint8Array([32, 104, 101, 120])
    Uncaught SyntaxError: Unexpected end of Input
     at line 42 col 18 in TEST
        for(let b3 =
                     ^
    > 
    

    The other notable thing is that the CLK and SI lines are shared with the LCD (also SPI) and the accelerometer (I2C). However, I have not initialized either of those. In other tests, LCD works fine as does the accel, but I'm trying to leave out any issues with line sharing.

    Any pointers greatly appreciated!

  • he CLK and SI lines are shared with the LCD (also SPI) and the accelerometer (I2C). However, I have not initialized either of those.

    Maybe you could initialize it. For display at least making CS pin high may help to make sure it is not picking up the data. However the i2c device may be more probable to break stuff if SDA is shared with MISO or MOSI and clock is shared between spi and i2c too. I guess i2c device could pick up some data as i2c transfer and try to respond over SDA(?) messing up data bits randomly. just a guess.

About

Avatar for fanoush @fanoush started