Part Number: TMS320F28035
Other Parts Discussed in Thread: C2000WARE
Hi, Why the project C2000Ware_3_04_00_00\device_support\f2803x\examples\c28\flash_programming return error code 31 when it come to programming?Is the project error?
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.
Part Number: TMS320F28035
Other Parts Discussed in Thread: C2000WARE
Hi, Why the project C2000Ware_3_04_00_00\device_support\f2803x\examples\c28\flash_programming return error code 31 when it come to programming?Is the project error?
Jammy,
Typically if CCS cannot program a device, the the device CSM(password) is non-zero value. I'd like to make sure we are separating the act of programming the device, from connecting, etc. If you are using the "debug" icon in CCS to launch the session, it will attempt to do many things automatically; connect to the XDS pod, connect to the C28x CPU, Reset the device, download the flash image, etc.
In CCS can you "right click' on the target config file(the ccxml file) associated with your session and select "launch selected configuration". If that succeeds then manually connect to the C28x CPU in the new window that pops up(right click on the C28x CPU and connect).
You'll then want to open a memory browser(View->memory browser) and go to address 0x3F7FF8. If you see all 0x0000 in this space, it means the device is locked with a non 0xFFFF password and that is the issue.
Let me know how far you get on the above and we can debug from there.
Best,
Matthew
Yes,the device is unlocked ,and Flash_Erase() return sucess,but after execute Flash_Program,why return error code 31 ?
Jammy,
This error occurs when there is a bit that is a "0" that CCS tries to program to a "1". This can only be done by the erase function, which is done by the sector.
I'm wondering if some of the code falls in the OTP address space. This is one time programmable memory, so once it is written to a "0" it cannot be erased by the device.
Can you check the .cmd file to see if any of your program is allocated to the user OTP address range:0x3D7800-0x3D7BFF?
Best,
Matthew
Matthew,
This is project of C2000Ware_3_04_00_00\device_support\f2803x\examples\c28\flash_programming.I think regardedness CMD.
Jammy,
Sorry I didn't re-look at your initial post that this is using one of our examples. If the flash erase is working correctly I'm not sure why error code 31 would happen.
When you are connected to the board go to Tools->On-Chip Flash. Once this new window opens, can you confirm that the button is on for "erase/program/verify". If you just want to take a screen shot of that tool window and the settings and post it back that will help.
Best,
Matthew
Jammy,
Yes, these are correct. Can you comment if this happens with any flash project and/or every time trying to load the code?
Is it possible to try a different device/board to see if this happens on multiple devices?
Lastly, going back to one of the comments in my initial reply on manually connecting to the device, etc. If you connect to the device in this way, then load the .out file with Run->Load Program do you see the same error(I'm assuming you are using the debug button to launch/program the device).
Best,
Matthew

Hi Matthew,
I connect to the device in this way, then load the .out file with Run->Load Program I cann't see the error.But if i simulate like above picture,everytime flash_program return status code 31.Why?Could you simulate OK at your office?
Jammy,
I ran the program on my controlCARD, and I realized that there is something special about this example. There are intentional portions of code that will generate the error codes on purpose to demonstrate that you cannot program a 0 to a 1 or attempt to write to locations outside the flash address, etc
This is the first example that has an intentional error at line 494 which will generate error code 31. I believe that the code won't continue past this, so if you want to see the other examples of errors you would need to comment that section out.
// If a bit has already been programmed, it cannot be brought back to a 1
// by the program function. The only way to bring a bit back to a 1 is by
// erasing the entire sector that the bit belongs to. This example shows
// the error that program will return if a bit is specified as a 1 when it
// has already been programmed to 0.
//
//
// Example: Program a single 16-bit value 0x0002, in Flash Sector B
//
Flash_ptr = Sector[2].StartAddr+1;
i = 0x0002;
Length = 1;
Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
if(Status != STATUS_SUCCESS)
{
Example_Error(Status);
}
//
// Example: This will return an error!! Can't program 0x0001
// because bit 0 in the the location was previously programmed
// to zero!
//
i = 0x0001;
Length = 1;
Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
//
// This should return a STATUS_FAIL_ZERO_BIT_ERROR
//
if(Status != STATUS_FAIL_ZERO_BIT_ERROR)
{
Example_Error(Status);
}
I had thought that the loading of the code was giving this error from the CCS automatic programming of the flash, forgetting that this example is intended to show the proper use of the API, etc.
So, this example is working as it intended, errors and all.
Best,
Matthew

Hi Matthew,
No, The flash_program() return Status 31 at line 400 before line 494 .I don't known why this happen?
Jammy,
Can you look at the top of the code for where the variable "WORDS_IN_FLASH_BUFFER" is defined? It should be of size 0x400; I think there may be some older versions of this example where this was assigned a size of 0x100 incorrectly.
Best,
Matthew
Hi Matthew,
Yes! I see. Why it return Status 31 rather than like exceed buffer range ? This mistake me.
I think this issue will be resolved.
Jammy,
I'm not completely sure what occurs in the compiled code if the size of the buffer exceeds the declared size, I think it depends on where the buffer was located in memory and if there was an unused memory space or not. This could have been corrupting the main program(by overwriting it).
I will file an internal ticket to make sure this is resolved in our examples(as this example is re-used on other devices).
Best,
Matthew