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.

TMS470R1B1M -> Flash_Compact_B goes to infinit loop?

Other Parts Discussed in Thread: TMS470R1B1M

Hi,

first of all, I am pretty new to programming microcontollers as well as C, so please, bear with me ;)

My goal is to write a boot loader for the TMS470R1B1M. For this purpose, I somehow have to erase and programm the flash.

Following the F05 Flash Module Guide I have to start with a Flash_Compat_B on the to be erases sector.

Unfortunately my microcontollers goes to an infinite loop instead of returning a 0 for success or a 1 for failure.

Here is my code:

#includes

int pass; // save failure success

FLASH_STATUS_ST status; // I am not setting any values here as this AFAIK only used to return values to me

FLASH_ARRAY_ST cntl; // I have no idea what I have this for, spec says this is a a base address but I have no idea which one?

UINT32 start 0x00010000; // I am trying to do a compact on Core 0, Sector 1. As my sectors a 64kb or 0xFFFF in size, sector 1 should start at this address

//btw, why is this a UINT32? shouldn't I have a char* (which is a UINT32 itself) for memorey addressing?

UINT32 delay = 12;

//used the highes wait time from spec but lower values lead to the same result

pass = Flash_Compact_B(&start, FLASH_CORE0, FLASH_SECT1, delay, cntl, &status);

//call the function with all the arguments given above

//unfortunately this goes to an infinit loop

Send(pass); //send is one of my functions for seriell communication

I know my information is not that great but I have no idea what I am doing wrong or where I can find additional information to learn how to do it right.

With best regards,

pininety

  • Hi,

    okay, first error:

    I have to call Flash_Match_Key_B before Flash_Compat_B

    Flash_Match_Key_B also returns 1, so it works.

    Now, Flash_Compact_B does run threw but still returns 0 so something is still wrong

  • Hello Frederik,

    What are the values being returned in your status variable?

  • Hi,

    the values should be

    stat1 = 0

    stat2 = 12

    stat3 = 0

    stat4 = 0

    I used the jlink to look into them at runtime. I hope this is the correct way.

    With best regards

    Frederik

  • Based on this information, the command is failing for max compaction pulses.  Some of the reasons I can think of that would be causing this is the Flash on the device is bad or the device is not in a privileged mode when trying to execute the command.  The Flash API functions must be called while the device is in a privileged mode like system or supervisor and not in user mode.

  • Hi,

    well, the flash should be fine as it can be programmed with the jlink but system mode?

    How can I check this once I am in C? I have to access M[0:4] from CPSR but I cannot find it in the definitions nor in the spec.

    If I look at the assembler start up code however, I see this:

    bic     r0,r0,#MODE_BITS                    ; Clear the mode bits
    orr     r0,r0,#SYS_MODE                     ; Set System mode bits
    ;orr     r0,r0,#SVC_MODE                     ; Set System mode bits
    msr     cpsr_c,r0                           ; Change the mode
    ldr     sp,=SFE(CSTACK) & 0xFFFFFFF8        ; End of CSTACK

    Shouldn't this set it to system mode already?

    How can I access the CPSR from my programm to check if it is in the right mode?

    Have a nice evening,

    Frederik

  • Since you are using a JLINK I would assume that you are not using TI's Code Composer Studio (CCS) toolset?  If you are using IAR, you should be able to find the source code for their flash loader project in the directory \arm\src\flashloader\TexasInstruments\FlashSM470R1B1M where EWARM is installed.  Each toolset tends to have its own variation of compiler intrinsics that would let you read the CPSR. In CCS, this would be how to read the CPSR from C:

    usigned int dst;

    dst = unsigned int _get_CPSR( );

    The M[4:0] bits in the CPSR would be 0x10 for user mode.  All other values should be privilege mode, where supervisor is 0x13 and system is 0x1F.

  • Hi,

    I checked if it is in system mode and yes, it is so it must be another error.

    So I went back and started to play with Flash_Match_Key_B and played arround with it.

    I had to notice that what ever key values I gave it, it always returned true.

    So my guess was that I choose the wront FLASH_ARRAY_ST value.

    Looking into Flash protection keys_modifying (spna094), I tried FLASH_ARRAY_ST = 0xFFE88000UL(this is the value in the manual for the TMS470R1x and in the TMS470R1B1M Device Manual this address is labeled with FLASH CONTROL REGISTER, spns194a, page 19, so I assume this should be correct) and now it always returns False. To my knowledge, the flash keys have not been altered so they should have the default value of 0xFFFFFFFF and the function should return True instead.

    I really have no idea what is going wrong here...