This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

working with F28335 Flash API and hex2000

Hello.

I've got some questions about Flash API  with respect to array generated from .out file by hex2000.

First of all, Flash28335_Program function works with words buffer. But  hex2000 generated array without even number of symbols. It do it right - I checked it by .map file. For example:

 

$A328000,

BD FF AC 50 C7 61 D7 A9 35 07 AC B4 A9 A9 A9 A6 2C AC 05 3B A9 AA 00 AB                //24

AB FF C8 09 A9 63 87 A5 A6 05 A9 63 A9 A3 0C F6 A5 A5 AC 05 2C 00 9E 0D            //24

81 A9 05 A9 63 A9 AC 08 52 0B F8 BE 06 35 3B A9 AB FF AA FF 48 AB 85 AC                  //24

AB B1 AC 8D A8 00 AC A6 A9 12 06                                                                                    //11

So, if I want to program this array to device, i have to change last line to even line. As I think, i have to add FF symbol, and line will look like:

AB B1 AC 8D A8 00 AC A6 A9 12 06  FF                                                              //12

Am I right with this suggestion?

 

Secondly,  hex2000 generates two odd lines in my case (sure, all amount of symbols is even). For example:

C4 42 44 A6 F5 84 BE 06 1F 0D 3A 06 1F 0D 3C 06 06 1F 22 C0 29 68 1A 73      //24

92                                                                                                                                          //1

FF 00 00 0F FF 01 00 00 FF 02 00 00 FF 03 00 00 FF 04 00 00 FF 05 00 00              //24

----so on --------------------

 

 

80 00 00 00 FE 82 00 00 00 FF 84 00 00 FF 85 00 00 FF 79 00 10 FF 7E 00         //24

00 00 00                                                                                                                                    //3

F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33            //24

So, i have to move symbols to convert all lines to even:

C4 42 44 A6 F5 84 BE 06 1F 0D 3A 06 1F 0D 3C 06 06 1F 22 C0 29 68 1A 73    //24

92  FF 00 00 0F FF 01 00 00 FF 02 00 00 FF 03 00 00 FF 04 00 00 FF 05 00    //24                                 

----so on----

00 00 00 00 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33 F8 33  //24 , or something like that, i can miss in symbols now.

--so on

Last line will be even.

 

Is it right?

  • Unfortunately, no answers so far :/..

    I've got one more question about hex2000 today  - why it generates two completely different files from one .out file? They have same size, but different information. Of course, I can just flash my program and see it in "memory" window in CCS to find the right file from hex2000.

  • omg this crazy thing divides word in two bytes and puts them in two different files o___O

  • Michael Ivabov said:
    I've got one more question about hex2000 today  - why it generates two completely different files from one .out file? They have same size, but different information. Of course, I can just flash my program and see it in "memory" window in CCS to find the right file from hex2000.

    You might want to try some of the -boot options.  These will put the data into the format used by the boot loaders in the ROM.  It will go into one file instead of splitting odd and even bytes up into two files.  It also puts leading information like starting address and number of words in each block.   The format of the data stream is described in the boot ROM reference guide. 

    For example:

    hex2000 -boot -a  -sci8 file.out

    hex2000 -boot -a -gpio16 file.out

    Cheers

    Lori

  • Hi Lori,

    I have rewritten code to use two files from hex2000, it works fine until i get to the one point.

    My flash codepart looks like this:

    breakpoint 1                                       Flash_ptr = (Uint16 *) (workingSector._sector.startAdr + workingSector.offset);
                                                                 DINT;
                                                                Status = Flash28335_Program(Flash_ptr,workingSector.buffer,Length,&FlashStatus);
    breakpoint 2                                        EINT;  

    I have to flash 73 strings with 24 words in each, 1752 words at all. It flashes fine only 30 strings. When it receives string #31,  I successfully get to breakpoint 1, my variables look normally, like previous 30 strings. But I can not reach to the breakpoint 2.. It falls to the ILLEGAL_ISR and loops there forever. Code in the ISR after "return" statement  goes to the 0x090152 address and back to the ISR.

     At  a memory window all flash sector, which I am working with, fulled 0x0000, altough before it was partly correct flashed by my strings.  

    I have tested  it in RAM,  so I cannot disturb any code from a flash. All interrupts are off during flashing. The Status variable is equal 0, but I think it has not rewritten.  All members of  the FlashStatus structure are equal 0.

    I  tested this on two different flash sectors.

    What am I doing wrong? :)

    Regards,

    Michael.

  • Hi Michael,

    I am currently working on this, what I am going to do is to upgrade my DSP application by programming the FLASH within my application.

    To do that, I have to convert the out file into hex format, then the PC program transfers the hex file to DSP via serial link (in my case, I use SCI-C)

    then my DSP application will do the erase/program/verify process by invoking FLASH API. I haven't start the actual work.

    Can you please share your practice to me? Thanks

     

    Tim

  • Hello Tim,

    My idea was simply: there is a program in a mcu in flash and in ram. it has update functions in ram. when it receives an update signal from a computer, it starts to receive
    info and write flash with it. after that, the mcu reboots and works with new program. Unfortunately, it did not work.. You should read about the problem in my post above.
    TI has been keeping silence about this, and, because it was my free project, i gave it up. If you fix it (or just dont have such problem), please answer.

    I include my computer program on C#, please don't scold me for it :) It was the one of my earliest experiences on C#.. I hope my code've become better since then.
    I've translated some strings from russian to english where it was necessary. Program works with two files from hex2000 and one map file from the TI compiler.
    http://www43.zippyshare.com/v/53539630/file.html

    I did not use checksum while exchanging data, but you should definitely do it.

    Part of the code from a mcu looks very easy:

    vars.h
    ---------------------------------------------

    extern unsigned char softwareVersion[3];
    extern unsigned long long startAdress;
    extern unsigned long long endAdress;

    extern FLASH_ST FlashStatus;
    extern FLASH_ST VerifyStatus;

     

     

    enum machineState
    {
                               
                 ReceivedSuccessfully = 0,
                
                 Ready = 1,
                
                 NoInfo = 2,
                
                 CheckSummMistake = 3,


                 SendDeleteSector = 4,

                 SectorDeletedSuccessfully = 5,

                 SectorDeleteFAIL = 6,


                 SendWriteCommand = 7,

                 WriteSuccessfully  = 8,

                 WriteFAIL = 9,
        

                 Version = 0xA 
    };


    extern enum machineState currentState;
    extern enum machineState nextState;


    struct Message
    /* the line contains 24 symbols
     * plus start (2)
     * plus status (1)
     * plus sum (1)
     * plus stop (2)
     * so it will be  24+2+1+1+2 = 24+6 = 30
     */
    {
     char bytes[40];
     char position;
     enum machineState status;
     char checkSumm;
     char gotStart; //the position of 'T'
     char gotStop; //the position of 'I' 
     void (*clearBuf)();
    };
    extern struct Message receivedMessage;

    struct Sector
    {
    unsigned int name;
    unsigned long int startAdr;
    unsigned long int stopAdr; 

    };

    extern struct Sector Sectors[8];

    struct workSector
    {
    struct Sector _sector;
    unsigned int offset;
    Uint16 buffer[25];
    };

    extern struct workSector workingSector;

    extern Uint8 updateModeEnabled;
    extern Uint8 rowCounter;
    extern unsigned int Status;

     

    -------------------------------------------------------------
    vars.c
    ---------------------------------------------

    enum machineState currentState = NoInfo;
    enum machineState nextState = NoInfo;
    extern FLASH_ST FlashStatus = {0,0,0};
    extern FLASH_ST VerifyStatus = {0,0,0};

    struct Message receivedMessage =  {
                                           {0}, // массив
                                            0, //  текущая позиция в принятом массиве
                                            NoInfo, //статус
                                            0, //checkSumm
                                            0, //gotStart
                                            0,  //gotStop
                                            (void (*)(long))clearBuffer
                                      };
    extern unsigned char softwareVersion[3] = {0};
    extern unsigned long long startAdress = 0;
    extern unsigned long long endAdress = 0;


    /*
    #define SECTORA   (Uint16)0x0001
    #define SECTORB   (Uint16)0x0002
    #define SECTORC   (Uint16)0x0004
    #define SECTORD   (Uint16)0x0008
    #define SECTORE   (Uint16)0x0010
    #define SECTORF   (Uint16)0x0020
    #define SECTORG   (Uint16)0x0040
    #define SECTORH   (Uint16)0x0080

             (Uint16 *)0x338000,(Uint16 *)0x33FFFF,
             (Uint16 *)0x330000,(Uint16 *)0x337FFF,
             (Uint16 *)0x328000,(Uint16 *)0x32FFFF,
             (Uint16 *)0x320000,(Uint16 *)0x327FFF,
             (Uint16 *)0x318000,(Uint16 *)0x31FFFF,
             (Uint16 *)0x310000,(Uint16 *)0x317FFF,
             (Uint16 *)0x308000,(Uint16 *)0x30FFFF,
             (Uint16 *)0x300000,(Uint16 *)0x307FFF
    */
    extern struct Sector Sectors[8] = {
                                     SECTORA,0x338000,0x33FFFF,
                                        SECTORB,0x330000,0x337FFF,
                                     SECTORC,0x328000,0x32FFFF,
                                     SECTORD,0x320000,0x327FFF,
                                     SECTORF,0x318000,0x31FFFF,
                                     SECTORG,0x308000,0x30FFFF,
                                     SECTORH,0x300000,0x307FFF,
                                    };

    extern struct workSector workingSector = {0,0,0,0,
                                      
                                           0,0,0,0,0 ,0,0,0,0,0, 
                                           0,0,0,0,0 ,0,0,0,0,0,                    
                                              0,0,0,0,0                                                             
                                                     };

    extern Uint8 updateModeEnabled = 0;
    extern Uint8 rowCounter = 0;
    extern unsigned int Status = 0;
    ---------------------------------------------
    program.c
    ---------------------------------------------

    #include "vars.h"
    #include "Flash2833x_API_Library.h"
    /*
    #pragma CODE_SECTION(sendState,"ramfuncs");
    #pragma CODE_SECTION(sendMessage,"ramfuncs");
    #pragma CODE_SECTION(doWork,"ramfuncs");
    */
    void sendState(enum machineState stateToSend)
    {
    char txByte[10] = {0};
    int i =0;

    txByte[0] = 'S';
    txByte[1] = 'T';
    txByte[2] = stateToSend;
    txByte[3] = stateToSend; // для суммы
    txByte[4] = 'F';
    txByte[5] = 'I';

    for (i=0;i<6;i++)     
     {
        // txByte[i]=49+i;
      while (ScibRegs.SCICTL2.bit.TXEMPTY==0) ;
         ScibRegs.SCITXBUF = txByte[i];                
     }
     //=====================================


     
    }
    void sendMessage (enum machineState state,unsigned char msg[2])
    {
    char txByte[10] = {0};
    int i =0;
    txByte[0] = 'S';
    txByte[1] = 'T';
    txByte[2] = state;
    txByte[3] = msg[0];
    txByte[4] = msg[1];
    txByte[5] = msg[2];

    for (i = 2; i< 6; i++)

     txByte[6] +=msg[i];

    txByte[7] = 'F';
    txByte[8] = 'I';

    for (i=0;i<9;i++)     
     {
      while (ScibRegs.SCICTL2.bit.TXEMPTY==0) ;
         ScibRegs.SCITXBUF = txByte[i];                
     }
     
    }
    void doWork(void)
    {

    //unsigned int symbol = 0;
    int i =0;
    //char count= 0;
    unsigned int sectorsToErase = 0;
    unsigned long long temp = 0;
    char wordCounter = 0;

    unsigned int *Flash_ptr = 0;
    unsigned char Length = 0;

    Uint16 tempWord = 0;

        EALLOW;
        SysCtrlRegs.WDCR= 0x0068;
        EDIS;

    switch (nextState) // здесь он уже не равен currentState
                         {
                          case Version :
                           {
                             // долго и нудно узнаем текущую версию из eeprom
                             /* 0x10 год
                              * 0x11 месяц
                              * 0x12 день
                               */
                             softwareVersion[0] = eeprom_read(0x10);
                             softwareVersion[1] = eeprom_read(0x11);
                            softwareVersion[2] = eeprom_read(0x12);
                             sendMessage(Version, softwareVersion);
                            
                             break;
                            
                           }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////                       
                          case SendDeleteSector :  //стереть заданный сектор
                               {
                              
                                 currentState = SendDeleteSector;
    //Command Erase = new Command(segment.startAdress + "Q" + segment.endAdress, EMachineState.SendDeleteSector);
                               
                     
                      temp = 0;                 
                     
                      temp = receivedMessage.bytes[receivedMessage.gotStart+2];
                      temp = temp  << 16;
                      startAdress = temp; // старшая цифра, ее сдвигаем 2 раза
                    
                    
                     temp = receivedMessage.bytes[receivedMessage.gotStart+3];
                     temp = temp << 8;
                     startAdress = startAdress | temp;
                      
                      temp = receivedMessage.bytes[receivedMessage.gotStart+4];  //последняя цифра
                      startAdress = startAdress | temp;
                     
                      /////////////////////////
                      temp = 0;
                      temp = receivedMessage.bytes[receivedMessage.gotStart+5];
                      temp = temp  << 16;
                      endAdress = temp;// старшая цифра, ее сдвигаем 2 раза
                     
                      temp = receivedMessage.bytes[receivedMessage.gotStart+6] ;
                      temp  = temp << 8;
                      endAdress = endAdress | temp;
                     
                      temp = receivedMessage.bytes[receivedMessage.gotStart+7];
                      endAdress = endAdress | temp;
                     
                                     for (i = 0; i< 8; i++)// можем теоретически получить задачу на стирание
                                                           // нескольких секторов
                                     {
                                        if (
                                            (Sectors[i].startAdr <= startAdress) &&
                                            (Sectors[i].stopAdr >= startAdress)
                                           )
                                        sectorsToErase = sectorsToErase | Sectors[i].name;    
                                     }   
                                    
                                     // сохраним границы памяти для записи
                                     workingSector._sector.name = sectorsToErase;
                                     workingSector._sector.startAdr = startAdress;
                                     workingSector._sector.stopAdr = endAdress;
                                     workingSector.offset  = 0; //начали обновление нового сектора
                                    
                                                                     
                                     // хотя по-идее он их сам отключает внутри api
                                       DINT;
                                       Status = Flash28335_Erase(sectorsToErase,&FlashStatus);
               EINT;   // Enable Global interrupt INTM
               ERTM;   // Enable Global realtime interrupt DBGM
             
             /*
               if(Status != STATUS_SUCCESS)
               {
                 sendState(SectorDeleteFAIL);
               }
               else
               for (i = 0; i<10; i++)
               */
               sendState(SectorDeletedSuccessfully);                                
                                              
                                   currentState = Ready;  
                                  
                                   break;        
                               } // end del sector
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
                          case (SendWriteCommand) :
                                    { // команда на запись
                                     
                                     currentState = SendWriteCommand;
                                     
                                    // first msg is LSB
                                    // second msg is - MSB
                                     i = 0;
                                   
                                   
                                    /*
                                     for ( i = receivedMessage.gotStart + 2; i < receivedMessage.gotStop - 2; i++)
                                          {
                                   
                                                 workingSector.buffer[wordCounter] =  receivedMessage.bytes[i];
                                                    wordCounter++;
                                                                                                                          
                                          }
                                          */
                                          wordCounter = 0;
                                           for ( i = receivedMessage.gotStart + 2; i < receivedMessage.gotStop - 2; i++)
                                          {
                                                if (rowCounter==0) //LSB
                                                {
                                                 workingSector.buffer[wordCounter] = receivedMessage.bytes[i];
                                                   }
                                                if (rowCounter == 1) //MSB
                                                {
                                                 tempWord = receivedMessage.bytes[i] << 8;
                                                 workingSector.buffer[wordCounter] = workingSector.buffer[wordCounter] | tempWord;
                                                }
                                                wordCounter++;
                                                                                                                          
                                          }
                                          if (rowCounter == 0)
                                           {
                                           rowCounter = 1; 
                                           currentState = Ready;
                                           sendState(WriteSuccessfully);
                                           return;
                                           }
                                          
                                          Length = wordCounter;
                                                                            
                                         
                                         
                                          Flash_ptr = (Uint16 *) (workingSector._sector.startAdr + workingSector.offset);
                                         
                                           DINT;
                                           Status = Flash28335_Program(Flash_ptr,workingSector.buffer,Length,&FlashStatus);
                                           EINT;   // Enable Global interrupt INTM
                      ERTM;   // Enable Global realtime interrupt DBGM
                     
                                      //    if (Status != STATUS_SUCCESS) sendState(WriteFAIL);
                                         
                                          // now let's verify it
                                           //   DINT;                              
                                //           Status = Flash28335_Verify(Flash_ptr,workingSector.buffer,Length,&VerifyStatus);
                                        //   EINT;   // Enable Global interrupt INTM
                   //   ERTM;   // Enable Global realtime interrupt DBGM
                   /*  
                                          if (Status != STATUS_SUCCESS) sendState(WriteFAIL);
                                          else  sendState(WriteSuccessfully);
                                          */
                                       //   for(i = 0; i< 10; i++)
                                          sendState(WriteSuccessfully);
                                          currentState = Ready;
                                          workingSector.offset += Length;
                                          rowCounter = 0;
                                         
                                    }//end write sector
                          
                         }
     
    }
    void Reboot(void)
    {
     // Enable the watchdog
      
       EALLOW;
       SysCtrlRegs.WDCR = 0x0028;  
       EDIS;
      
       EALLOW;
       SysCtrlRegs.WDCR = 0x0020; 
       EDIS;
      
      
     
    }

    Regards,
    Michael.

  • Michael,

    Thanks for your source code. That will be a good start point for my work. And I will keep you posted if there is any progress from my side.

    And please tolerate if I keep asking questions.

    Regards

    Tim