Go Down

Topic: Flash Page is Locked (Read 11665 times) previous topic - next topic

IntraStellar

Thanks for this information Palliser. Does this "manip" work for you when you get a "Flash page is locked" error message ?

I did this snippet to unlock all 32 lock bits in Flash bank 0 and Flash bank 1 whatever their previous state (Not tested since I never have the above error message):
I have the same error as described in this thread. The code did not work, it can't be uploaded since the Arduino Due is locked.

Have anyone found a solution to this problem or is this game over for my Due?

ard_newbie


What was the last code you successfully uploaded ?

IntraStellar

#17
Jul 28, 2017, 03:28 pm Last Edit: Jul 28, 2017, 03:48 pm by IntraStellar
What was the last code you successfully uploaded ?
The following is the code. It does use the "DueFlashStorage.h" lib. I wonder if the lock bit was set when I started uploading a new program to the Due while it was in the process of saving to the flash. As you can see the code uses a couple of libs, I'll supply them to you shortly.
This is the code I uploaded when the error first occurred. But the last functioning program I uploaded was very similar to this as I only changed a line or two. I don't remember exactly what I changed.

Code: [Select]

// UNFINISHED::
//          CONTROL:  ctrlReset:  filename needs to be saved with DueFlashStorage.h to make it recoverable after restart
//          READ:     getPar:     add code for retrieving data from sensors
//          correct ip for setTX in this file
#include <CONTROL.h>
#include <MODE.h>
#include <TXRX.h>
//#include <MONITOR.h>
#include <READ.h>
#include <TEST.h>

#define TRUE 1
#define FALSE 0
#define STARTUP 1
#define IDLE 2
#define ACTIVE 3
#define SHUTDOWN 4
#define BYTES_PER_TX 28
#define TXS_PER_SAVE 28
#define HEATER_PIN_1 40
#define HEATER_PIN_2 42
#define SAVE_PIN 4
#define Tmin 10         // Min temperature of temperature measurment unit before heater is turned ON
#define Tmax 15         // Max temperature of temperature measurment unit before heater is turned OFF
#define SAMPLES_PER_EVENT_CHECK 10
#define TIMER_LIFTOFF 20000
#define TIMER_IDLE_CUTOFF 50000
#define TIMER_IDLE_LANDING 50000
#define TIMER_ACTIVE_AFTER_LANDING 45000
#define LANDING_ALTITUDE_LIMIT 100

TEST testClass;   // OBS! Remove before flight
MODE modeClass;
TXRX txrxClass;
//MONITOR monClass;
READ readClass;
CTRL ctrlClass(BYTES_PER_TX, TXS_PER_SAVE, HEATER_PIN_1, HEATER_PIN_2,
                SAVE_PIN, LANDING_ALTITUDE_LIMIT, TIMER_LIFTOFF,
                TIMER_IDLE_CUTOFF, TIMER_IDLE_LANDING,
                TIMER_ACTIVE_AFTER_LANDING);

File root;
long interval = 25;
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
uint8_t oldcomMode = 0;
uint8_t comByte;
int heatStatus = 0;
int mode = ACTIVE;  // OBS! Change before flight
int count = 0;
int vaiai;
char sensData1[45] = {'1','3','3','7','4','0','0','5','d','0','0','0','0','8'}; // ={info, t, heat1, heat2, infr1, cover, posx, posy, posz, wind, accx, accy, accz, press}
char sensData2[45] = {'l','e','e','t','0','0','0','0','0','0','0','0','9'};
char bufferDataRX;
char bufferComRX;
int overview = 0b10000000; // Indicates which sensor box the data was recorded


// TXRX   **********************
  // the media access control (ethernet hardware) address for the shield:
  byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0xF8, 0x5C };  
  byte ip[] = { 130, 240, 92, 1 };
  byte DNS[] = { 130, 240, 19, 2 };
  byte gateway[] = { 130, 240, 92, 1};
  byte subnet[] = {255, 255, 0, 0};
  unsigned int localPort = 1900;

  //static ip for PC
  byte remoteip2[] = { 192, 168, 42, 154 };
  byte remoteport2[] = { 112, 23, 0, 0 };

  // TCP
  byte server[] = { 130, 240, 95, 19 };
  unsigned int serverPort = 139;
//        **********************

void setup() {
  Serial.begin(9600);
  Serial.println("********************** I   A M   I N   S E T U P **********************");
  ctrlClass.initSave(SAVE_PIN);
  testClass.init(9600,SAVE_PIN);
  readClass.initREAD();
  //WDT_Restart(WDT); // Reset watchdog timer
  txrxClass.initTXRX(mac, ip, DNS, gateway, subnet, localPort, server, serverPort);
  //WDT_Restart(WDT); // Reset watchdog timer
  mode = ACTIVE;
  root = SD.open("/");
  ctrlClass.clearSD2();
  
}

void loop() {

 //       currentMillis = millis();
  
  //if(currentMillis - previousMillis >= interval) {
    
//      previousMillis = currentMillis;
//      comByte = txrxClass.getComRX();      
//      txrxClass.getDataRX(&sensData2[0], sizeof(sensData1)/sizeof(char));
//        if(comByte & 0b00011000 == 0b00011000) // if reset bit is set
    //    {
  //          ctrlClass.ctrlReset();
    //    }
      //  if((comByte >> 5) != oldcomMode) // if comMode =! oldcomMode
        //{
//          modeClass.setMode((comByte >> 5));  // set the commanded mode
          //  oldcomMode = (comByte >> 5);          
        //}

      // mode = modeClass.getMode();
      //WDT_Restart(WDT); // Reset watchdog timer
//        if(mode != STARTUP)
//        {
            readClass.getParam(sensData1);
//            txrxClass.setTX(&sensData1[0], remoteip2, remoteport2);      // send to GC
//          txrxClass.setTX(sensData1);      // send to other sensor box
//          heatStatus = ctrlClass.ctrlHeat( 30, 30, 15, 20);
 //         sensData1[1] = overview | heatStatus;
     //       if(mode == ACTIVE)
     //       {
               ctrlClass.ctrlSave(sensData1, sizeof(sensData1)/sizeof(char));
//              ctrlClass.ctrlSave(sensData2, sizeof(sensData2)/sizeof(char));
     //       }
//        }
//        if(count >= SAMPLES_PER_EVENT_CHECK){
//        //  ctrlClass.ctrlEvents(overview, 1000); // OBS! Change 2nd parameter!
//            count = 0;
//        }
//        else{
//            count = count + 1;
//        }

    testClass.dispEXISTdata(sensData1, 44);
    testClass.printDirectory2();
    testClass.dispCharFile("DATA0024.TXT");
}



Edit: You can download all the files I used here: https://www.dropbox.com/s/rb4d3s434bumqxm/lock.zip?dl=0

ard_newbie

I don't see in your code the #include <DueFlashStorage.h>.

- Did you try the workaround proposed by Palliser (this thread, #reply 13) ?

- If you push the Erase button for 3 seconds then the Reset button for 3 seconds, then select a correct programming port, can you upload this empty sketch ?:

Code: [Select]

#define LONGCALL __attribute__((long_call))
#define NOINLINE __attribute__((noinline))
#define RAMCODE __attribute__((section(".ramfunc")))

#define RAMFUNC NOINLINE LONGCALL RAMCODE

RAMFUNC
int main(void) {

}

IntraStellar

I don't see in your code the #include <DueFlashStorage.h>.

- Did you try the workaround proposed by Palliser (this thread, #reply 13) ?

- If you push the Erase button for 3 seconds then the Reset button for 3 seconds, then select a correct programming port, can you upload this empty sketch ?:
The DueFlashStorage.h is included inside another lib; CONTROL.h. You can find it in the .zip file I shared in my last post(#17).

- I haven't tried what Palliser proposed. I don't know how. I have no experience with SAM-ICE but I'm looking into it. If you know a guide of other useful info I'm happy to look into it.

- I still get the same error when trying your erase method.

Palliser

Hi IntraStellar,

Sorry to read from you about this Flash page locking issue.

In my experience with a couple of Dues, whatever the damage inside the Due, there is no way to make Arduino IDE to upload any code to the affected Due (via USB prog or native).

As I explained before, the easiest way to program the Due is using the In-system programmer software called SAM-BA via the USB native port. You could use also Atmel Studio 6x with SAM-ICE hardware but it is expensive and elaborated.

Here a link to download SAM-BA.

http://www.atmel.com/tools/atmelsam-bain-systemprogrammer.aspx

Also, this issue (in my cases) is directly related with the use of the DueFlashStorage library, especially if you exploit it (saving/retrieving in more than a dozen of memory registers).

Regards,
-p

IntraStellar

I will give it a try and get back to you. Thanks for helping me out you guys.

If you know any guide on how to do it or have explained it in another thread I'd appreciate the link to help me reset this pesky bit.

Palliser

#22
Jul 28, 2017, 11:04 pm Last Edit: Jul 28, 2017, 11:13 pm by Palliser
I am not sure if there is out there a simple procedure but here my steps to upload a sketch in Arduino Due using SAM-BA:

1. Upload or compile your sketch using the Arduino IDE. This step will generate the correspondent .bin file of your sketch.

2. Connect your computer to Arduino Due via USB native (SAM-BA doesn't recognize the USB programming port).

3. Press the Arduino Due Erase button for one second. Then press the Arduino Due Reset button for another second and finally release both buttons. This switches from the 'Arduino Due port' to the 'Bossa Program port' in the Windows Device Manager (COM ports).

4. Open SAM-BA. SAM-BA should detect and select the Arduino Due Bossa port and board type (ar91sam3x8-ek) automatically. Otherwise select the Arduino Due Bossa port.

5. Press the Connect button. Now you have connected SAM-BA with Due.

6. In the Flash tab (center of the main SAM-BA window) click the folder button of Send File Name and select the .bin file you just generated in step1. This file is usually located at C:\Users\YourName\AppData\Local\Temp\arduino_build_xxxxxx\yoursketch.ino.bin.

7. Press the Send File button. Click the 'No' button to the question about lock regions.

8. Close SAM-BA.

And that's it. Try it and let me know how it goes.

-p

IntraStellar

#23
Jul 29, 2017, 01:09 pm Last Edit: Jul 29, 2017, 01:14 pm by IntraStellar
I tried it but it didn't work  :smiley-confuse:

The windows device manager shows the bossa port but in SAM-BA I can choose from "\USBserial\COM7" or "COM7". I used "\USBserial\COM7" since the other gave me an error. I found the .bin file and sent it.

The response I get from SAM-BA is:

(sam-ba_2.16) 2 % send_file {Flash} "C:/Users/Jakob/AppData/Local/Temp/arduino_build_693572/fixDueLock.ino.bin" 0x80000 0
-I- Send File C:/Users/Jakob/AppData/Local/Temp/arduino_build_693572/fixDueLock.ino.bin at address 0x80000
 first_sector 0 last_sector 1
-I-    Writing: 0x5014 bytes at 0x0 (buffer addr : 0x20002898)
-I-    0x5014 bytes written by applet
Do not lock

I then closed SAM-BA, opend Arduino IDE and uploaded the program. I still get the response that it's locked.

edited.

Palliser

IntraStellar,

Can you try again but executing first the following three Scripts? (at the bottom of the SAM-BA window):

-Enable Flash access
-Enable Security Bit (GPNVM0)
-Erase all flash.

Then, send the file.

-p

Palliser

#25
Jul 29, 2017, 04:26 pm Last Edit: Jul 29, 2017, 04:26 pm by Palliser
I then closed SAM-BA, opend Arduino IDE and uploaded the program. I still get the response that it's locked.

edited.
I forgot to tell you that once you close samba, your Due is already programmed. DO NOT download again the sketch.

-p

IntraStellar

#26
Jul 29, 2017, 05:17 pm Last Edit: Jul 29, 2017, 05:24 pm by IntraStellar
I forgot to tell you that once you close samba, your Due is already programmed. DO NOT download again the sketch.
I can still upload a unrelated sketch like hello world? Because if this works it should be unlocked and work normally anyway if I understood this correctly. How would I otherwise check that it works?

I tried adding the three additional steps with no success.

Edit: I change from to the programming port after using SAM-BA if that makes any difference.

Palliser

#27
Jul 29, 2017, 06:08 pm Last Edit: Jul 29, 2017, 06:09 pm by Palliser
Try programming something like Serial.println("Hello World");

This way of programming Due with SAM-BA does not eliminate the issue. It is just a turnaround to program the Due.

-p

IntraStellar

I did upload a hello world sketch to the Due trough a Arduino sketch after doing the SAM-BA steps if that's what you mean.

Do you mean that if this works, I'll still have to program the Due trough SAM-BA?

Palliser

Yes. Now on, every time you need to program your 'pesky' Due, you have to use SAM-BA.
I still don't understand why Due with lock issue is bricked for Arduino IDE, even after a chip erase.

-p
 

Go Up