Userpage Flashing Problems

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

kowalski5233
Posts: 6
Joined: Tue May 13, 2014 8:08 pm

Userpage Flashing Problems

Tue Jul 22, 2014 11:01 am

Good day everyone.

I have an issue flashing the userpage successfully. Here are my symptoms.

It seems I can erase the page, but not write to it. I can however write back what was on it, but not something else. If for instance 0x00800010 has the value 0x04 to enable the bootloader on startup if pni PA04 is high and I erase it, it will read back as 0xFF. If I write 0x04 to it again it will read back as 0x04. If I decide that I want to enable the bootloader when pin PA04 is low and want to write 0xFE to 0x00800011, it won't do it, since it was 0xFF before the erase. Strange thing is, when I power cycle, the value 0xFE will be there.

Here is an extract of my butchered code from trying this and that...

Code: Select all

                /* flash user page */
                else if (command == 'p')
                {
                    flashcalw_erase_user_page(true);
                    while(!flashcalw_is_ready());
                    delay_ms(1);
                    flashcalw_clear_page_buffer();
                    while(!flashcalw_is_ready());
                    delay_ms(1);
                    flashcalw_memset8((void*) 0x00800000, 0xFF, 0x200, true);
                    while(!flashcalw_is_ready());
                    delay_ms(1);
                    flashcalw_memcpy((void*) 0x00800000, pbuf, 0x200, false);
                    while(!flashcalw_is_ready());
                    delay_ms(1);
                    flashcalw_write_user_page();
                    while(!flashcalw_is_ready());
                    delay_ms(1);
                    jamba_TxBuff((uint8_t*) &current_number, 1);
                }
It might simply be that I understand the page buffer usage for the userpage wrong, but I can't find much in the form of examples online. There is an errata in the datasheet, so even though the flashcalw_clear_page_buffer whould make it all 0xFF, I added even another write to make everything 0xFF. Having this in or out makes no difference in the results. I also added some additional delays in case the flash needs some time to complete the action, even though I'm waiting for the ready flag.

I'm probably just misunderstanding something in the datasheet, but any guidance would be appreciated.
Last edited by kowalski5233 on Tue Jul 22, 2014 11:08 am, edited 1 time in total.
kowalski5233
Posts: 6
Joined: Tue May 13, 2014 8:08 pm

Re: Userpage Flashing Problems

Tue Jul 22, 2014 11:03 am

Also, I have found this : discussions/viewtopic.php/p,39274.html#p39274 but it suspect a completely different problem here than what I have. I am running on 8Mhz RC and still tried to slow PBB down but with the same results as before.

EDIT - Don't know where my mind was yesterday when I read it, but he made is FASTER.. If I need to run that clock that fast to be able to update the userpage, I might have some bigger problems.. :shock:
tallman
Posts: 42
Joined: Wed Mar 20, 2013 4:09 pm

Re: Userpage Flashing Problems

Fri Jul 25, 2014 8:37 pm

Just to verify, your not using the debugger to see the memory, but your program?  I had many frustrations until I realized my debugger was not updating correctly, but the chip was actually programming correctly.  I just couldn't see it unless I reset device.
Brent
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: Userpage Flashing Problems

Sat Jul 26, 2014 3:28 pm

hmm ...
From looking at the "FLASHCALW Example1" in Atmel Studio,,, seems you have more code here than you need.

Also, note that the first 8 locations in user memory are reserved for fuse settings; so your first available address in user memory is 0x00800008U

For example if you are trying to store the following var into flash user memory, at the first available address (0x00800008U)...

Code: Select all

uint8_t myVar = 0xA5;
.....

               /* flash user page */
                else if (command == 'p')
                {
                    flashcalw_memcpy((void*) 0x00800008U, &myVar, sizeof(myVar), true);

                    // check for programming error
                    if( flashcalw_is_lock_error() || flashcalw_is_programming_error() )
                    {
                          //TODO: Handle error here
                    }
                }
Not sure if this is your problem, just an observation by looking at the example code, the flashcalw_*() functions and the part data sheet.

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests