Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

c - How To "clear non volatile memory" on u-blox sara r410 using AT commands

I'm working on a customized device using STM32L4xx and the Sara R410m u-blox modem via UART interface. The firmware is written in C. There's an additional USB port so it's possible to send AT-Commands with a more-graphical interface via u-blox m-center to the modem after enable it using the GPIO Pins. The driver itself is not the problem.

Based on the experiences with the device there were some strange side-effects after a re-flash with new firmware in debugging context (timeouts even if device and modem is alive, config fails, etc... all that could be caused by other bugs/parameters, I know that, but back to the point). There is a new condition/feature set up by project management that the firmware, after switching on the device using GPIO, have to clear the non volatile memory before writing new parameters.

I already have found in the datasheet page 381 the list of commands storing their values in the non volatile memory: https://www.u-blox.com/sites/default/files/SARA-R4_ATCommands_%28UBX-17003787%29.pdf

I'm reading the datasheet for about a week now and can't find something as a solution to clear non volatile memory or write factory settings to it.

Maybe you guys could help me or have a recommendation?

EDIT: Trying AT&F0 or ATZ to delete Profiles, have a look to log file contents:

[15:05:21.268] rx: AT&V
[15:05:21.268] tx: AT&V
[15:05:21.283] tx:
[15:05:21.283] tx: ACTIVE PROFILE: &C: 1; &D: 1; &F: e; Q: e; V: 1; X: 1; Z: e; &S: 1; 
[15:05:21.283] tx: &W: 0; Q: 3; E: 1; L: 0; M: 0; &Y: 0; 0: 0; 50: 0; 54: 10; 55: 8; 56: 2; 
[15:05:21.283] tx: S7: 0; 58: 2; 510: 14; S3: 13; S2: 43; 512: 50; +ICE: 3,1; +IFC: 2,2; 
[15:05:21.283] tx: +IPR: 115200; +CMEE: 2; +W546: 12; +CFUN:; +UAUTHREQ: 1,0,-; +CEREG: 0; 
[15:05:21.283] tx: +CEMODE: 0; +CSCS: "IRA"; +CRC: 0;
[15:05:21.283] tx: +CGDCONT: (1,"IP","iot.lnce.net","0.0.0.0",0,0,0,0); +CGDSCONT: ; 
[15:05:21.283] tx: +CGEREP: 0,0; +CGSMS: 1; +CSMS: 0; +CMGF: 0; +CSAS: 0; +GRES: 0; 
[15:05:21.283] tx: +CSCA: "",; +CSMP: ?0,0; +CREG: 0; +CGREG: 0; +CGPIAF: 0,0,0,0; 
[15:05:21.283] tx: +CSDH: 0; +CPIN: ,; +CMER: 0,0,0,0,0; +CPMS: "ME","ME","ME";
[15:05:21.283] tx: +CNMI: 0,0,0,0,0; +CMMS: 0; +COPS: 0,0,""; +CGATT: 1; +CGACT(1,1); 
[15:05:21.283] tx: +CPOL: 0,2,-,0,0,0,0; +CPLS: 0; +CTZR: 0; +CTZU: 0; +CSDF: 1; +CUSD: 0; 
[15:05:21.283] tx: +CIND: 5,1,1,0,0,1,1,0,1,0,0,0; +CPSMS: 0,"","","",""; +CEDRXS: 0,1,""; 
[15:05:21.283] tx: +URAT: 0,0; +UMNOPROF: 0; +UPSV: 0,0
[15:05:21.283] tx:
[15:05:21.283] tx: OK
[15:05:26.776] rx: AT&F8
[15:05:26.778] tx: AT&F8
[15:05:26.778] tx:
[15:05:26.778] tx: OK
[15:05:32.146] rx: AT&V
[15:05:32.152] tx: AT&V
[15:05:32.168] tx:
[15:05:32.168] tx: ACTIVE PROFILE: &C: 1; &D: 1; &F: 0; Q: e; V: 1; X: 1; Z: 0; &S: 1; 
[15:05:32.168] tx: &W: 0; Q: 3; E: 1; L: 0; M: 0; &Y: e; 0: e; 50: e; S4: 10; S5: 8; S6: 2; 
[15:05:32.168] tx: S7: 0; S8: 2; 510: 14; S3: 13; S2: 43; 512: 50; +ICE: 3,1; +IFC: 2,2; 
[15:05:32.168] tx: +IPR: 115200; +CMEE: 2; +W546: 12; +CFUN:; +UAUTHREQ: 1,0,-; +CEREG: 0; 
[15:05:32.168] tx: +CEMODE: 0; +CSCS: "IRA"; +CRC: 0;
[15:05:32.168] tx: +CGDCONT: (1,"IP","iot.lnce.net","0.0.0.0",0,0,0,0); +CGDSCONT: ; 
[15:05:32.168] tx: +CGEREP: 0,0; +CGSMS: 1; +CSMS: 0; +CMGF: 0; +CSAS: 0; +GRES: 0; 
[15:05:32.168] tx: +CSCA: "",; +CSMP: ?0,0; +CREG: 0; +CGREG: 0; +CGPIAF: 0,0,0,0; 
[15:05:32.168] tx: +CSDH: 0; +CPIN: ,; +CMER: 0,0,0,0,0; +CPMS: "ME","ME","ME";
[15:05:32.168] tx: +CNMI: 0,0,0,0,0; +CMMS: 0; +COPS: 0,0,-; +CGATT: 1; +CGACT(1,1); 
[15:05:32.168] tx: +CPOL: 0,2,-,0,0,0,0; +CPLS: 0; +CTZR: 0; +CTZU: 0; +CSDF: 1; +CUSD: 0; 
[15:05:32.168] tx: +CIND: 5,1,1,0,0,1,1,0,1,0,0,0; +CPSMS: 0,"","","",""; +CEDRXS: 0,1,-; 
[15:05:32.168] tx: +URAT: 0,0; +UMNOPROF: 0; +UPSV: 0,0
question from:https://stackoverflow.com/questions/65925599/how-to-clear-non-volatile-memory-on-u-blox-sara-r410-using-at-commands

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As you correctly noticed, AT&F0 is not what you are looking for, as it resets to default the parameters belonging to profile 0. NVM parameters belong to a different set: in fact they are natively persistent to the HW reset without providing any further command. Profile parameters, instead, need AT&W0 command to save the current configuration in the profile 0, and AT&P0 command to make it the default profile at startup.

Some uBlox products, for example Sara N2-N3, have a specific AT command to reset the NVM parameters area: AT+UFACTORY.

Synthax:
AT+UFACTORY=<fs_op>,<nvm_op>

Where:
<fs_op> is the action performed on FS (0: no restore; 1: FS flash sectors erased, 2: all files stored in FS deleted)
<nvm_op> is the action performed on NVM parameters (0: no restore; 1: NVM flash sectors erased, 2: reserved)

So you would obtain what you need by issuing

AT+UFACTORY=0,1

Unfortunately, this command seems to be currently not supported by Sara-R4 modules. For this reason I can just suggest a workaround. This is the strategy:

  • Make an analysis of all the NVM parameters you change in your application
  • Define an array of strings with all the default values to be restored
  • Loop on all the elements of the array sending the corresponding command so that all the parameters that could ever be changed are restored

Something like

#define MAX_CMD_SIZE 50

static char DefaultNVMPars[][MAX_CMD_SIZE] = 
{
    "AT+IPR=115200", //baudrate
    "ATE0"           //echo enabled
};

void SendATCommand(char *cmd); // a function that sends to AT port the string in input, appending '
'

void ResetNVMPars(void)
{
    int i;

    for(i=0; i<(sizeof(DefaultNVMPars)/sizeof(DefaultNVMPars[0]); i++)
    {
        SendATCommand(DefaultNVMPars[i]);
    }
}

Of course in this way, in order to have DefaultNVMPars limited in size, you have to limit it and to pay attention to any new command you use in your application. On the other hand you could populate with all the commands that store parameters in NVM, but in this case the size of the array could become remarkable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...