Announcement

Collapse
No announcement yet.

spiflash_LoadImageControl not working as expected

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • spiflash_LoadImageControl not working as expected

    Hello

    I'm developoing a product with based on Gen4-uLCD-70D

    Everything worked as expected untill I decided to add a SPI flash to my project.

    I'm using a Cypress S25FL128L that is a direct replacement for the M25P128 that is currently EOL

    I moved the gci and dat file to the SPI Flash using the SPIflashdemo4 program

    But when I start the program the spiflash_LoadImageControl loads the files correctly but the screen stay black

    My understanding is that once the ImageControl is loaded the handling of it is the same no matter is I use the SD card or a SPI flash

    The only difference in the main is that I commented out the:

    hndl := file_LoadImageControl("dash.dat", "dash.gci", 1);

    and added this part:

    spiflash_SetAdd(SPI2, ImagectrlH, ImagectrlL) ;
    hndl := spiflash_LoadImageControl(SPI2, SF_PIN) ;

    The gci file was initially 35Mb and now for testing purposes is reduced to 16Mb


    This is the code I used to load the files to flash:
    Code:
    #platform "Gen4-uLCD-70D"
    
    
    // Program Skeleton 1.4 generated 5/12/2020 10:29:23 AM
    
    #inherit "4DGL_16bitColours.fnc"
    
    #inherit "VisualConst.inc"
    
    
    #constant GCIname "dash.gci" // name of GCI file when this program was created, may need changing on your computer
    #constant DATname "dash.dat" // name of DAT file when this program was created, may need changing on your computer
    
    #CONST
    EnablePin PA11
    ClockPin PA8
    SDIPin PA10
    SDOPin PA9
    //
    S25FL_4BEN 0xB7 // Enter 4 Byte Address Mode
    #END
    
    
    var sector[256] ;
    #DATA
    byte progress 0x7C, 0x2F, 0x2D, 0x5C
    #END
    
    func main()
    var i, j, k, handle, st[2], nw[2], erase, dev, err, eratm[2] ;
    txt_FontID(FONT_6) ;
    pin_HI(EnablePin) ;
    pin_Set(PIN_OUT,EnablePin) ;
    if (! SPI1_SDI_pin(SDIPin))
    print("SDI Pin Invalid\n") ;
    err := 1 ;
    endif
    if (! SPI1_SCK_pin(ClockPin))
    print("SCK Pin Invalid\n") ;
    err := 1 ;
    endif
    if (! SPI1_SDO_pin(SDOPin))
    print("SDO Pin Invalid\n") ;
    err := 1 ;
    endif
    if (! SPI1_Init(SPI_SPEED5, SPI8_MODE_5))
    print("INIT parameter Invalid\n") ;
    err := 1 ;
    endif
    
    if(err)
    repeat forever
    endif
    
    putstr("Mounting...\n");
    if (!(file_Mount()))
    while(!(file_Mount()))
    putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif
    if ((!file_Exists(DATname)) || (!file_Exists(GCIname)))
    print([STR] DATname, " and/or\n", [STR] GCIname, " not found") ;
    repeat forever
    endif
    
    i := spiflash_ID(SPI1, EnablePin) ;
    j := spiflash_SIG(SPI1, EnablePin) ;
    if (i == 0xffff) // or, possibly, if (signature == 0xFF)
    print("FLASH device not found") ;
    repeat forever
    endif
    print("Flash (JEDEC)ID:", [HEX4] i, "\n") ;
    print("Flash Signature:", [HEX4] j, "\n") ;
    if (i == 0x3016)
    erase := "200" ;
    dev := "A25L032" ;
    else if (i == 0x2016)
    erase := "80" ;
    dev := "M25P32" ;
    else if (i == 0x2018)
    erase := "250" ;
    dev := "M25P128" ;
    else if (i == 0x6019)
    erase := "138" ;
    dev := "S25FL256L" ;
    else if (i == 0x6018)
    erase := "128" ;
    dev := "S25FL128L" ;
    else
    erase := "Unknown" ;
    dev := "Unknown" ;
    endif
    print("Device:", [STR] dev, "\nBulk Erase Max:", [STR] erase, " Secs\n") ;
    
    
    // 0. Erase entire flash space
    print("Erasing Please wait..\n") ;
    pokeW(SYSTEM_TIMER_LO, 0) ; // set low word to 0
    pokeW(SYSTEM_TIMER_HI, 0) ; // so this cannot overflow
    pokeW(SYSTEM_TIMER_LO, 0) ; // while we are setting this
    spiflash_BulkErase(SPI1, EnablePin) ; // erase the entire flash, this will hang if there is no flash memory, but we should have already trapped that
    eratm[0] := sys_T() ;
    eratm[1] := sys_T_HI() ;
    if ((eratm[0] & 0xFFF0) == 0xFFF0) // if timer high about to tick over
    pause(20) ; // pause until it definitely does
    i := sys_T_HI() ; // get its new value
    if (i == eratm[1]) // if it equals its old value
    eratm[1]-- ; // then old value was one too high, so adjust it down
    endif
    endif
    print("Done in ") ;
    i := str_Ptr(eratm) ;
    str_Printf(&i, "%ld") ;
    print("ms\n") ;
    
    
    //Data space needed to store 4 bytes for odometer function
    st[0] := 0 ;
    st[1] := 0 ;
    nw[1] := 0 ;
    spiflash_SetAdd(SPI1,st[1], st[0]) ;
    print("Data at 0x", [HEX4] st[1], [HEX4] st[0], "\n") ;
    spiflash_PutW(0x1234, SPI1, EnablePin);
    spiflash_PutW(0x5678, SPI1, EnablePin);
    spiflash_PutW(0x1234, SPI1, EnablePin);
    spiflash_PutW(0x5678, SPI1, EnablePin);
    nw[0] := 10 ;
    uadd_3232(st, st, nw);
    
    
    // Copy Image control
    print("DAT at 0x", [HEX4] st[1], [HEX4] st[0], "\n") ;
    handle := file_Open(DATname,'r') ;
    if (!handle)
    print("DAT file not found") ;
    repeat forever
    endif
    j := 0 ;
    k := 0 ;
    i := file_Read(sector, 512, handle) ;
    while(i)
    spiflash_Write(sector, i, SPI1, EnablePin) ;
    nw[0] := i ;
    uadd_3232(st, st, nw);
    if (j++ == 10)
    j := 0 ;
    print([CHR] progress[k++ % 4], "\r") ;
    endif
    i := file_Read(sector, 512, handle) ;
    wend
    spiflash_PutC(0x1a, SPI1, EnablePin) ; // add eof marker
    nw[0] := 1 ;
    uadd_3232(st, st, nw);
    file_Close(handle) ;
    
    handle := file_Open(GCIname,'r') ;
    if (!handle)
    print("GCI file not found") ;
    repeat forever
    endif
    i := file_Read(sector, 512, handle) ;
    while(i)
    spiflash_Write(sector, i, SPI1, EnablePin) ;
    nw[0] := i ;
    uadd_3232(st, st, nw);
    if (j++ == 10)
    j := 0 ;
    print([CHR] progress[k++ % 4], "\r") ;
    endif
    i := file_Read(sector, 512, handle) ;
    wend
    file_Close(handle) ;
    
    
    
    print("Freespc at 0x", [HEX4] st[1], [HEX4] st[0], "\n") ;
    
    
    repeat
    forever
    endfunc




    And this is the MAIN part of the program I'm using with the declared CONSTANTS

    Code:
    #platform "Gen4-uLCD-70D"
    
    
    // Program Skeleton 1.4 generated 5/12/2020 10:29:23 AM
    
    #inherit "4DGL_16bitColours.fnc"
    
    #inherit "VisualConst.inc"
    
    #inherit "ledDigitsDisplay.inc"
    
    //#inherit "dashConst.inc" --> removed because it was causing problems with Array readbuf
    
    
    // object indexes into ImageControl
    #CONST
    S25FL_4BEN 0xB7
    iForm1 // offset 0x0
    iSmartGauge1 // offset 0xBBA00
    iSmartGauge2 // offset 0x4A7E00
    iSmartGauge3 // offset 0xC82A00
    ikmhtext // offset 0x1F1FC00
    iSmartGauge4 // offset 0x1F21200
    iSmartGauge5 // offset 0x1F40E00
    irpmtext // offset 0x1F61800
    ix1000text // offset 0x1F62200
    iSmartGauge6 // offset 0x1F62E00
    iplus // offset 0x2089E00
    icelsius // offset 0x208A200
    ideg // offset 0x208AA00
    ikmtotalhi // offset 0x208AC00
    iikmtotalhi // offset 0x208B400
    ikmtot // offset 0x208CC00
    itripodo // offset 0x208D200
    iitripodo // offset 0x208DC00
    iTripA // offset 0x208F400
    ikmtotallow // offset 0x2090000
    iikmtotallow // offset 0x2090800
    iclockh // offset 0x2092000
    iiclockh // offset 0x2093000
    iclockm // offset 0x2097800
    iiclockm // offset 0x2098800
    ihourdots // offset 0x209D000
    iSmartGauge7 // offset 0x209D400
    iSmartGauge8 // offset 0x20B9000
    ibattery // offset 0x20D9E00
    ioil // offset 0x20DB000
    iice // offset 0x20DC600
    ilampfault // offset 0x20DD800
    iTripB // offset 0x20E0200
    iForm2 // offset 0x20E0E00
    //Position on SPI FLASH of control files
    DataH 0x0000
    DataL 0x0000
    ImagectrlH 0x0000
    ImagectrlL 0x000A
    
    #END
    
    #CONST
    SF_PIN PA11



    Code:
    func main()
    /*
    //Initialize SD Card
    if (!(file_Mount()))
    while(!(file_Mount()))
    putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif
    */
    //Initialize SD Card END
    //SPI2 definition (to FLASH)
    pin_HI(SF_PIN);
    pin_Set(PIN_OUT, SF_PIN);
    SPI2_SDO_pin(PA9);
    SPI2_SDI_pin(PA10);
    SPI2_SCK_pin(PA8);
    SPI2_Init(SPI_SPEED4, SPI8_MODE_5);
    pause(200);
    //SPI2 definition END
    
    //Initialize Variables
    //hndl := file_LoadImageControl("dash.dat", "dash.gci", 1); //read from SD
    
    spiflash_SetAdd(SPI2, ImagectrlH, ImagectrlL) ;
    hndl := spiflash_LoadImageControl(SPI2, SF_PIN) ;
    if (!hndl)
    print("ImageControl Load Failed") ;
    repeat forever
    endif
    //Initialize Variables END
    
    
    //Initialize Screen
    gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    gfx_Contrast(5);
    //Static Imeges
    img_Show(hndl,iForm1) ;
    img_Show(hndl,ikmhtext) ;
    img_Show(hndl,irpmtext) ;
    img_Show(hndl,ix1000text) ;
    img_Show(hndl,iplus) ;
    img_Show(hndl,icelsius) ;
    img_Show(hndl,ideg) ;
    img_Show(hndl,ikmtot) ;
    img_Show(hndl,iTripA) ;
    img_Show(hndl,ihourdots) ;
    //END Static Imeges
    //Initialize Screen END
    
    //I2C2 definition (to SAM21D)
    I2C2_Open(I2C_MED, PA14, PA15);
    //I2C2 definition END
    
    
    //Initialize Variables for OVER RPM
    overhigh := 55;
    overlow := 37;
    underhigh := 0;
    underlow := 0;
    //END Initialize Variables for OVER RPM
    
    //Initialize Variables for PAGE MANAGEMENT
    page := 0;
    buttonstat := 0;
    currentpage := 0;
    //END Initialize Variables for PAGE MANAGEMENT
    
    //TEMPORARY set of random values -- waiting for code ----------------------------------------------NEED WORK
    ledDigitsDisplay(0, iikmtotallow, 372, 3, 1, 17, 0) ;
    ledDigitsDisplay(0, iikmtotalhi, 320, 3, 1, 17, 0) ;
    ledDigitsDisplay(0, iitripodo, 326, 4, 1, 17, 0) ;
    img_SetWord(hndl, iSmartGauge7, IMAGE_INDEX, 8) ; //ESA CONF
    img_Show(hndl,iSmartGauge7) ;
    img_SetWord(hndl, iSmartGauge8, IMAGE_INDEX, 0) ; //OIL TEMP
    img_Show(hndl,iSmartGauge8) ;
    //END TEMPORARY set of random values -- waiting for code ------------------------------------------NEED WORK
    
    // TEST RTC
    I2C1_Open(I2C_MED, PA13, PA12);
    pin_Set(PIN_INP_HI, PA6);
    
    sys_SetTimer(TIMER1, 10000);
    sys_SetTimerEvent(TIMER1, printtime);
    
    printtime();
    //END TEST RTC
    
    //Test SERIAL COMM for BT
    COM1_RX_pin(PA5);
    COM1_TX_pin(PA4);
    com_SetBaud(COM1, 960);
    com1_Init(combuf, 10, 0);
    //END Test SERIAL COMM for BT
    
    //Main LOOP
    
    infolast := 0;
    infostatus := 0;
    
    repeat
    if (pin_Read(PA6) == 0)
    readi2cdata();
    endif
    
    
    // Info button routine ----------------------------------------------NEED WORK
    if (infostatus == 1)
    changepage();
    infostatus:=0;
    endif
    if (infostatus == 2)
    // PlaceHolder for LONG press on INFO code
    infostatus:=0;
    endif
    
    
    if (buttonstat == 0 && currentpage != 0 )
    page0();
    endif
    if (buttonstat == 1 && currentpage != 1 )
    page1();
    endif
    //END Info button routine -------------------------------------------NEED WORK
    //Serial Test routine
    getSerial();
    //END Serial Test routine
    forever
    //Main LOOP END
    endfunc

  • #2
    Sorry My bad

    All my offsets in the dat file are in reference of 0x00000000 , so it was trying to load the wrong part of the file

    solved

    thank you

    Comment


    • #3
      Well solved but not solved, if the file is bigger than 24Mb it copy just fine to the spiflash but then it doesn't work. still gives me black screen

      Comment


      • #4
        And this is what I get after few seconds


        Click image for larger version

Name:	Untitled.png
Views:	21
Size:	1.08 MB
ID:	72251

        Comment

        Working...
        X