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.

Program freezing after Flash write

Other Parts Discussed in Thread: EK-TM4C1294XL

Hello all,

  I am using the EK-TM4C1294XL board to develop my project and I am facing a problem when writing on flash. Also, I am using the driverlib and ti-rtos.

  I need to persist some data on flash and, on the first load of the program, I write the data direct to the flash but, after this write, the program freezes in the next command, in my case, a simple System_printf. The debug just stops on this command and does not goes forward.  I also started a single program just to nake sure I have no other problems in the original project. My new project does almost nothing in the main.

  Please, see the attached code below.

#define FLASH_CONFIG_SECTOR 0xC0000

typedef struct {
	uint32_t programmed;			// The default value for a programmed section is 0x0000ABCD
	uint32_t serverIpAddress[4];	// Server IPAddress
	uint32_t serverPort;			// Server Port
	uint32_t localServerPort;		// Local server port
	uint32_t equipmentId[8];		// Equipment ID
	uint32_t serialNumber[14];		// Equipment SerialNumber
	uint32_t partNumber[16];		// Equipment PartNumber
	uint32_t reserved[467];			// (512 - number of items above)
} RemottaConfig;


int main(void)
{
	uint32_t clock;
	unsigned int programmed;
	RemottaConfig rc;

	// Usar 120MHZ de clock
	clock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();

    programmed = HWREG(FLASH_CONFIG_SECTOR);
    if (programmed == 0xFFFFFFFF) {
        System_printf("First RUN.\n");
        System_flush();

    	rc.programmed = FLASH_PROGRAMMED;
    	rc.serverIpAddress[0] = 192;
    	rc.serverIpAddress[1] = 168;
    	rc.serverIpAddress[2] = 10;
    	rc.serverIpAddress[3] = 122;
    	rc.serverPort = 5000;
    	rc.localServerPort = 8000;
    	memset(rc.equipmentId, 0, sizeof(rc.equipmentId));
    	memset(rc.serialNumber, 0, sizeof(rc.serialNumber));
    	memset(rc.partNumber, 0, sizeof(rc.partNumber));
    	memset(rc.reserved, 0, sizeof(rc.reserved));

    	FlashErase(FLASH_CONFIG_SECTOR);
	FlashProgram((uint32_t *)&rc, FLASH_CONFIG_SECTOR, sizeof(RemottaConfig));

    }

    System_printf("Here is where my code stops\n");
    System_flush();

  ...

After FlashProgram, I see in the MemoryBrowser the data correctly stored in the flash, as expected.

When I remove the code that uses flash, everything goes ok.

What m I doing wrong?

Hi,

Just to trying to do something different, I added the following code before the line: programmed = HWREG(FLASH_CONFIG_SECTOR);

protection = FlashProtectGet(FLASH_CONFIG_SECTOR);
switch(protection) {
case FlashReadWrite:
  System_printf("We can read and write on flash");
  break;
case FlashReadOnly:
  System_printf("Just for reading");
  break;
case FlashExecuteOnly:
  System_printf("just for executing");
  break;
}
System_flush();


And I am receiving the value FlashReadWrite.

Tks in advance.
Leandro

  • Hi,

    Just to trying to do something different, I added the following code before the line: programmed = HWREG(FLASH_CONFIG_SECTOR);

    protection = FlashProtectGet(FLASH_CONFIG_SECTOR);
    switch(protection) {
    case FlashReadWrite:
    System_printf("We can read and write on flash");
    break;
    case FlashReadOnly:
    System_printf("Just for reading");
    break;
    case FlashExecuteOnly:
    System_printf("just for executing");
    break;
    }
    System_flush();

    And I am receiving the value FlashReadWrite.

    Tks in advance.
    Leandro
  • Hello Leandro,

    If you halt the CPU, where does the CPU execution show it is?

    Regards
    Amit
  • It is like the debug stops to "debug" my code line by line. The highligth on the line with debug just disappear. It is like, for example, when I am in a infinite loop.
    It is very strange.

    But, I am afraid it is not the flash problem.

    The problem is more inside the structure I am using because now I removed all flash code and I am using just the structure as it is and after my first set os values, I have the same behaviour. Weird.

  • HI Amit,

    Aparently the problem occurs when I use sizeof(). I don't know why but the RTOS does not like of the sizeof.
    I will perform some further investigation on this behaviour. Now I fixed the problem changing sizeof by a fixed number.
  • May we note you are employing the famed KISS practice - but in reverse!
    Earlier I was going to suggest that you limit all code just to that "failing" System_printF().
    Test/Verifying ONE function at a time - most always - serves as the shortest (and fastest) distance between a program and its desired completion!
  • Hello Leandro,

    Can you check what is the value being passed by sizeof?

    Regards
    Amit
  • And we note that KISS - which limits to just ONE function - would have (far faster) placed that value in highlight!
  • Hello friends,

    Just to close this issue, after some headache, I fixed it.
    Instead of the call

    FlashProgram((uint32_t *)&rc, FLASH_CONFIG_SECTOR, sizeof(RemottaConfig));

    This call below worked fine:

    FlashProgram((uint32_t *)&rc, FLASH_CONFIG_SECTOR, 512);

    Now I can write and read (using HWREG) the data into flash successfuly.

    Thank you very much of your attention and the next problema, for sure, I will aply the KISS principle. In factm I usually use KISS but sometimes our brain freezes together the cpu.. hehe

    Regards,

  • Hello Leandro,

    While it worked, i would like to know what "sizeof" passed the value to the API.

    Regards
    Amit
  • I will do a test here with a small project but I guess that the sizeof(RemottaConfig) is 512*4, where 4 is the sizeof(uint32_t).
  • Hello Leandro,

    And if you were to divide the value by 4 and then apply it to the program it should work!

    Regards
    Amit
  • Yes, it should. I will do it.

    Reards
    L.
  • Hello Leandro

    OK. Let us know the results.

    Regards
    Amit
  • Hello Amit,

    As expected, it worked with sizeof(RemottaConfig)/sizeof(uint32_t), but I did a little bit more. I have changed my structure to the following:


    typedef struct {
    uint32_t programmed; // Deve ter um valor 0x0000ABCD quando programada e não podemos zerar
    uint32_t serverIpAddress[4]; // Endereco IP do servidor
    uint32_t serverPort; // Porta do servidor
    uint32_t localServerPort; // Porta local de configuração
    uint32_t equipmentId[8]; // ID do Equipamento
    uint32_t serialNumber[14]; // SerialNumber
    uint32_t partNumber[16]; // PartNumber
    uint32_t reserved[467]; // Reservado Scientts = (512 - Numero de uint32_t acima)
    } RemottaConfig;

    typedef union {
    uint32_t flashData[512];
    RemottaConfig configData;
    } _RemottaConfig;

    and now, I write directly on the flashdata array:

    _RemottaConfig rc;

    FlashErase(FLASH_CONFIG_SECTOR);
    FlashProgram(rc.flashData, FLASH_CONFIG_SECTOR, sizeof(rc.flashData)/sizeof(uint32_t));

    To load from flash, I used:

    flashLen = sizeof(rc.flashData)/sizeof(uint_32_t);
    for (i=0; i<flashLen; i++) {
    rc.flashData[i] = HWREG(FLASH_CONFIG_SECTOR + i*sizeof(uint32_t));
    }

    With this procedure, I have all data available in the RemottaConfig structure after reading the flash. Easier to manipulate.

    It worked fine.

    Regards
    L.
  • Hello Leandro,

    I believe that before the size was adjusted, the SRAM was being read beyond the boundary of the address map, and may be because of that the CPU was bus faulting.

    Regards
    Amit