Accesing flash memory


#1

Hello all.

I’m trying to save some data into the flash memory of a wismo gprs modem, but i’m having some trouble. When I do “adl_flhExist(APNHandle, T2R_MYAPN_ID)” I get -23 as an answer (which I think it’s a “WM_BUS_NO_MORE_HANDLE_FREE” error).
If I delete this line and try to subscribe the handler using "adl_flhSubscribe (APNHandle, 1) " I get a -4 (“ADL_RET_ERR_ALREADY_SUBSCRIBED” I think). Can someone lend me a hand with this? I’m writing parts of the code just below.

#define T2R_MYAPN_ID 1
ascii MyAPN[50];
ascii APNHandle[4] = “APN\0”; //I already tried with ascii *APNHandle = “APN”
void Cmdt2rusr_Handler ( adl_atCmdPreParser_t *param );

void adl_main (adl_InitType_e InitType){

s32 length;

if (!adl_flhExist(APNHandle, T2R_MYAPN_ID)) //Here i get the -23
adl_flhSubscribe (APNHandle, 1); //Here the -4 if i comment the “if” above

if ((length = adl_flhExist (APNHandle, T2R_MYAPN_ID)) > 0)
//length is -23 again
adl_flhRead ( APNHandle, T2R_MYAPN_ID, length, MyAPN );

adl_atCmdSubscribe (“AT+T2RUSR”, Cmdt2rusr_Handler,
ADL_CMD_TYPE_PARA | ADL_CMD_TYPE_TEST);
}

void Cmdt2rusr_Handler (adl_atCmdPreParser_t *param){

u16 length = 0;
ascii localAPN[50];
ascii *cmdStr;

if (param->Type == ADL_CMD_TYPE_PARA){
cmdStr = param->StrData;
wm_strGetParameterString ( localAPN, cmdStr, 1 );
strcpy ( MyAPN, localAPN );
if ((length = adl_flhExist (APNHandle, T2R_MYAPN_ID)) > 0){
//Here length is 65513 :S
adl_flhWrite (APNHandle, T2R_MYAPN_ID, length, localAPN);
//adl_flhWrite returns another -23…
}
}
}

Thanks in advance for your help :slight_smile:


#2
adl_flhSubscribe (APNHandle, 1);

This creates a group of files under the name “APN”. This group contains 1 file, because the second parameter is 1. The files are indexed from 0 up. So, you only created a file that could be named “APN[0]”.

#define T2R_MYAPN_ID 1
adl_flhRead ( APNHandle, T2R_MYAPN_ID, length, MyAPN );

Here, you try to access a file that could be named “APN[T2R_MYAPN_ID]” or “APN[1]”. That file does not exist.
So, you can either change

#define T2R_MYAPN_ID 1

to

#define T2R_MYAPN_ID 0

or increase the number of files in the adl_flhSubscribe() call to 2 or more.
Remember that once you subscribe a name, “APN” here, the number of files cannot be changed, until you erase the flash using “AT+WOPEN=3”. So I suggest subscribing to more files than you really need, to enable backward compatibility.