Reply
Posts: 12
Registered: ‎01-21-2016
Accepted Solution

about FLASH

[ Edited ]

Hi,everyone!

When download the code to the EFM8SB10F8G, it cannot run to LINE 5 for the first time in Simplicity Studio V4.Why?

 

temp_byte = FLASH_ByteRead (START_ADDRESS);
if (temp_byte != CONBYTE)
{
// Initially erase the test page of flash
FLASH_PageErase (START_ADDRESS);//LINE 5
// Check if able to Write and Read the flash--------------------------------
FLASH_ByteWrite (START_ADDRESS, CONBYTE);
FLASH_ByteWrite (START_ADDRESS + 1, 0x07);
FLASH_ByteWrite (START_ADDRESS + 2, 0xD0);
Counter = 2000;
}
else
{
Counter = FLASH_ByteRead (START_ADDRESS + 1);
Counter = Counter << 8;
Counter |= FLASH_ByteRead (START_ADDRESS + 2);
}
 

Best Regards,

Jason Cai

Posts: 2,312
Registered: ‎10-14-2014

Re: about FLASH

I suggest you upload the whole project to see if other could reproduce the issue for you. the code you uploaded is too short to figure out the reason.

what address you are trying to write and erase? do you have some page locked for your device, etc?

 

My views are my own and do not necessarily represent the views of Silicon Labs

WeiguoLu
Posts: 12
Registered: ‎01-21-2016

Re: about FLASH

Hi,Weiguo Lu

The Start Address is 0x1F00, and the code is less then 6000 bytes.

Jason Cai

Posts: 12
Registered: ‎01-21-2016

Re: about FLASH

Hi, Weiguo Lu

May I have your email?

Jason Cai

Posts: 201
Registered: ‎07-27-2016

Re: about FLASH


Caiyoufa wrote:

Hi,everyone!

When download the code to the EFM8SB10F8G, it cannot run to LINE 5 for the first time in Simplicity Studio V4.Why?

 

 



What do you mean by "it cannot run"? If you added a breakpoint to line 5, does the compiler skip it? Also, I did not understand what you meant by the "first time"? If you restart the code execution in your debugger, does it work then?

 

~Manasa

Posts: 12
Registered: ‎01-21-2016

Re: about FLASH

Hi,

Even if I add a breakpoint or use "Run to line" command,it cannot run to LINE 5. If I restart the code execution in your debugger, it doesn't work too.

 

Jason Cai

Posts: 67
Registered: ‎09-15-2015

Re: about FLASH

It's still not clear what is happening. Are you saying the "if" statement on line 4 evaluates to "false" so it skips over lines 5-9 and starts executing the "else" statement?

Or are you saying the program hangs on line 4?

Sometimes stepping over functions during debugging doesn't seem to be reliable, so if things get weird, I'll set breakpoints to see if the MCU ever hits it.

If that doesn't fix it, post your entire code as an attachment or as formatted source code in a message and someone here will look through it.
Posts: 332
Registered: ‎09-22-2009

Re: about FLASH

Yea the first question is what does the statement (temp_byte != CONBYTE) evaluate to?

Posts: 12
Registered: ‎01-21-2016

Re: about FLASH

Hi,

Please see attachment.

Thanks.

 

Jason Cai

Posts: 67
Registered: ‎09-15-2015

Re: about FLASH

Jason, I ran your code, and it works perfectly. However, here's what I think the issue is:

 

You probably don't realize this, but your MCU is allowed to run "for a little bit" before the debugger attaches to it and resets it. So, the first time you hit the "debug" button, Simplicity Studio flashed your MCU (which started running your code -- programming CONBYTE (0x5A) to START_ADDRESS (0x1F00). Then, the debugger attached, entered reset mode, and dumped you on the main() breakpoint. You probably stepped through your code and thought your if(temp_byte != CONBYTE) was never executing. It was, though -- just really quickly before your debugger attached! Robot Happy

 

What I did was used the memory explorer to manually zero out (well, actually "FF"-out) the 1F00 segment of flash memory before line 4. And sure enough, as you can see, your if() statement gets executed, and your program writes some data to START_ADDRESS:

 

 

studio_2017-06-14_00-07-27.png

 

By the way, a lot of people really forget how powerful Simplicity Studio is. Need to massage a bit of flash memory to get stuff working properly? No problem -- just put your cursor in the window, start typing, and as soon as you press "enter" the changes will be flashed to your MCU; all without it knowing anything happened Robot Happy

 

Posts: 12
Registered: ‎01-21-2016

Re: about FLASH

Hi Ninja,

How may I forbid my MCU to run "for a little bit"?My debugger is EC6, and it is always connected to my board.

 

Jason Cai

Highlighted
Posts: 3,092
Registered: ‎02-07-2002

Re: about FLASH

I guess that will require a new version of the firmware inside the debug adapter to be made by SiLabs.

Posts: 67
Registered: ‎09-15-2015

Re: about FLASH

You can't prevent the code from running before the debugger attaches. Either add a start up delay (or a GPIO poller) to your code, or just use the memory editor to reset the flash to whatever state you want it to be in. You'll probably be using the memory editor anyway to verify different configurations/states; it's really easy and fast to use, so it should work OK for you.
Posts: 8,134
Registered: ‎08-13-2003

Re: about FLASH

what I have done in other cases would work here:

 

GLOBAL char volatile catch = 1;

 

in the code

#ifdef DEBUG_MODE

if (catch)

{

while (1);

}

#endif

 

 

set a breakpoint on the while, when it breaks set 'catch' to zero

 

 

PS I do not know, about SS but some softwares have a testable flag for DEBUG_MODE (with whatever name) that is automatically set

erik