Announcement

Collapse
No announcement yet.

Program uSD through serial connection

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

  • Program uSD through serial connection

    Hi Everyone,
    I’m new to 4DS and am evaluating it as part of a new product development project that needs a display without much dev time. I’m generally impressed, but I haven’t been able to find a way to update the uSD card through the serial programming connection, and this is an absolute critical must have feature for me, even if it takes forever.
    The display I’m using is gen4-uLCD-24PT. My GCI file to load into the uSD is tiny (<1MB). (And I’m using 4DS’s uUSB-PA5 adapter, if that matters)

    Is there a script, app note, program, etc. for this I just haven’t found?

    Thanks!

  • #2
    Hello David,

    Welcome to the forum

    There is a application called SCRIPTC which you will find in C:\Program Files (x86)\4D Labs\4D Workshop 4 IDE\DEP Once it is setup correctly it will allow you to update files on the uSD card and more. Example scripts can be found in C:\Users\Public\Documents\4D Labs\SCRIPTS

    1MB shouldn't take a ridiculously long time to transfer.

    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      Hi Paul,
      Thank you very much for your quick reply! This is helpful.
      So my understanding is this script will kill the file system on the uSD card and will write in raw format?
      Also, and more importantly, how do I generate the source .hex file for the transfer from the .dat and .gci files?

      Comment


      • #4
        Hello David,

        Can you please let me know of your intended platform that you are doing this update from as it will help in giving you the best option's for the task.

        Best regards

        Paul

        Comment


        • #5
          Windows 10 (x64). Thanks!

          Comment


          • #6
            pauleilio , any further info you can pass along on this? Thanks.

            Comment


            • #7
              Hi David,

              You may find this forum post useful http://forum.4dsystems.com.au/forum/...rd-without-ide

              It explains how it is done in RAW format.

              Best regards

              Paul

              Comment


              • #8
                Hi Paul,
                I've been buried in other stuff, so just getting back to this. Anyway, I've got a single image that if I use gc.exe to write it in RAW format to the uSD card inserted in the PC, then transfer the card to the display, it works. So to write that image through the USB-serial, this is what I'm trying:

                c:\Program Files (x86)\4D Workshop 4 IDE\DEP>SCRIPTC.EXE 4dgl\LOAD4DGLUSD.4DSCRIPT /ccom3 /dusdfile "c:\test.gci"
                No Errors, code size = 21 bytes
                Starting Script LOAD4DGLUSD.4DSCRIPT
                Opening COM3 Speed=115200 baud4dgl Attn - Goldelox - SD-HC Capacity 3,796.03MB
                WriteSectors - NAK from Write Sector
                CommPort Closed
                ABORTING Script LOAD4DGLUSD.4DSCRIPT

                So how can I fix "NAK from Write Sector" ???

                I've also tried programming the uSD in RAW while installed in the PC using graphics composer, then running READUSD.4DSCRIPT to dump it to a hex file, moving the uSD card from the PC to the display, and then using LOAD4DGLUSD.4DSCRIPT exactly the same as above to write that hex file through the USB serial. The results are the same.

                Comment


                • #9
                  Hi David,

                  Can you please tell me the Workshop programming environment that you are using for your project so we can suggest the best method for transferring the image file to the uSD card from the PC

                  Best regards

                  Paul

                  Comment


                  • #10
                    Workshop 4.5.0.8 (just updated) on Windows 10.

                    Comment


                    • #11
                      Hello David,

                      Can yo also tell me if you are using Designer, Visi or Visi-genie to create your project.

                      Best regards

                      Paul

                      Comment


                      • #12
                        Visi, but if I need to switch to Designer to make this work that's fine.

                        Comment


                        • #13
                          Hello David,

                          You might not be able to use LOAD4DGLUSD for the task of updating GCI files. This appnote explains an alternative method that you might find useful

                          http://www.4dsystems.com.au/download...0203_R_1_0.pdf

                          I hope this helps

                          Best regards

                          Paul.

                          Comment


                          • #14
                            Hi Paul,
                            I had actually looked at that appnote previously, but the program it references installs a crazy amount of drivers and "stuff." So, I wrote my own program to write bytes from the serial port to the uSD card. I'm pasting it below, in case anyone else in the future has similar requirements:

                            #platform "GOLDELOX"
                            #inherit "4DGL_16bitColours.fnc"

                            /*
                            This is a program that allows the update of images stored on the uSD card over the serial port and without removing the card from the display.
                            Written for Goldelox uOLED-96-G2 display module.
                            Generate images using graphics composer (gc.exe), make each image resolution 160x128 (16 bit color). Build as 4DGL - GCI type.
                            Once this code below has been pasted into a designer project, and compiled and loaded to the display...
                            use a com-port terminal program (e.g. realterm) at 19200 baud to send the UploadTrigger numbers below (as binary numbers, not ASCII) and the number of images that will be uploaded (e.g. 11 22 5) for 5 images.
                            After waiting a few ms, transfer the .gci file (as binary, not ASCII, again possible with Realterm) over the com port.
                            Occasionally this transfer will fail--the display will print the error, reset, and then go back to waiting for the UploadTrigger sequence.
                            Lower baud rate reduces these errors but increases time. Also, adding periodic time pauses in the upload gives the uC in the display a chance to catch up.
                            Time per image is approx 19 seconds.

                            Written by David_0.75bits, Aug 28 2017. No warranties.
                            */

                            func main()
                            var n;
                            var buffer[65];
                            var SerCmd[2];
                            #DATA
                            byte UploadTrigger 11, 22
                            #END
                            com_Init(buffer,63,0);
                            setbaud(BAUD_19200);

                            while(!media_Init())
                            gfx_Cls();
                            pause(300);
                            print("No SD card");
                            pause(300);
                            wend

                            repeat
                            if (com_Full()) //if the buffer is overrun, reset it
                            com_Init(buffer,63,0);
                            endif
                            if (com_Count() > 0) //at least one byte has been rec'd
                            n:=0;
                            while (com_Count()) //while there is serial data available...
                            SerCmd[n]:=serin(); //read it into the qualification buffer
                            if (SerCmd[n] == UploadTrigger[n]) //compare it to the expected
                            n++;
                            else
                            n :=0; //not a match, so reset comparison
                            endif
                            if (n >= sizeof(UploadTrigger))
                            Upload_Function(); //The full sequence has been matched
                            break;
                            endif
                            wend
                            endif

                            //now display one image, then the other, etc, and repeat.
                            media_SetAdd(0,0); //address offset of the first image, from the .dat file.
                            media_Image(0,0); //start drawing image in the top left corner
                            pause(1000);
                            media_SetAdd(0,0xA200); //address offset of the second image, from the .dat file.
                            media_Image(0,0);
                            pause(1000);
                            media_SetAdd(0x0001,0x4400);
                            media_Image(0,0);
                            pause(1000);
                            media_SetAdd(0x0001,0xE600);
                            media_Image(0,0);
                            pause(1000);
                            media_SetAdd(0x0002,0x8800);
                            media_Image(0,0);
                            pause(1000);
                            forever

                            endfunc


                            func Upload_Function() //this function byte copies from the serial port directly to the uSD card, starting at sector 0/ address 0.
                            var NumbOfImages;
                            var n;
                            while (com_Count()<1); //wait for a byte
                            NumbOfImages := serin(); //number of images that will be uploaded

                            while (com_Count() != 0) //clear the buffer of any garbage remaining
                            n := serin();
                            wend
                            gfx_Cls();
                            print("Uploading");
                            media_SetSector(0,0);
                            pause(1);

                            while (NumbOfImages)
                            n:=41472; //every image is composed of (160 x 128 x 2) + 512 = 41472 bytes
                            while (n)
                            while(com_Count() < 1); //wait for a byte
                            media_WriteByte(serin()); //WriteByte automatically increments address
                            if (com_Full())
                            print("\nBuffer Overrun");
                            to(COM0);
                            print("\nBuffer Overrun");
                            pause(2000);
                            SystemReset();
                            endif
                            if (com_Error())
                            print("\nGeneral Error");
                            to(COM0);
                            print("\nGeneral Error");
                            pause(2000);
                            SystemReset();
                            endif
                            n--;
                            wend
                            NumbOfImages--;
                            wend

                            media_Flush(); //finish up the write to uSD
                            print("\nExit");
                            pause(2000);
                            gfx_Cls();

                            endfunc








                            Comment


                            • #15
                              Hello David,

                              Thank you very much for sharing that on the forum. I am sure others will find it very useful. Very nice work.

                              Best regards

                              Paul

                              Comment

                              Working...
                              X