Error "ADL_RET_ERR_PARAM" while reading from flash

Hi guys,

I am trying to write and then read data from flash. My code is the following: Flash subscription and writting work just fine (both give “OK” in return) but flash reading always returns ADL_RET_ERR_PARAM. Why is that? The thing is that I want the variable “PinCode” to be in ASCII and not to u8 form. How is this possible? I tried both ways but it still didn’t work! Any help please?

Thanks!

#define FLASH_LOCATION   0

static const ascii* flash_test_var = "some_flash";
s8 rc;
//static const ascii * PinCode;
u8  * PinCode;
static const ascii * PIN;

adl_flhSubscribe( flash_test_var, 18 );  
adl_flhWrite(flash_test_var, FLASH_LOCATION, 4,PIN);
if ((length = adl_flhExist (flash_test_var, FLASH_LOCATION)) > 0)
                      
                   {   rc=adl_flhRead(flash_test_var,FLASH_LOCATION,length,PinCode);

				    switch ( rc )
				   {
				   case OK:
						 TRACE((TraceLevel,"flash read rc = OK" ));
						 break;
				   case ADL_RET_ERR_PARAM:
						 TRACE((TraceLevel,"ADL_RET_ERR_PARAM" ));
						 break;
				   case ADL_RET_ERR_UNKNOWN_HDL:
						 TRACE((TraceLevel,"ADL_RET_ERR_UNKNOWN_HDL" ));
						 break;
				   case ADL_FLH_RET_ERR_ID_OUT_OF_RANGE:
						 TRACE((TraceLevel,"ADL_FLH_RET_ERR_ID_OUT_OF_RANGE" ));
						 break;
				   case ADL_RET_ERR_FATAL:
						 TRACE((TraceLevel,"ADL_RET_ERR_FATAL" ));
						 break;
				   case ADL_FLH_RET_ERR_OBJ_NOT_EXIST:
						 TRACE((TraceLevel,"ADL_FLH_RET_OBJ_NOT_EXIST" ));
						 break;
				   case ADL_RET_ERR_SERVICE_LOCKED:
						 TRACE((TraceLevel,"ADL_FLH_RET_ERR_SERVICE_LOCKED" ));
						 break;
				   //default:
				   }

PinCode is a pointer - but you haven’t set it to point to anything ! :open_mouth:

Yes, it is just a pointer, which I want through the “read” funtion to point him to the content of what the function is reading. Isn’t this the way the function works? I mean, the " u8 * read " containts finally the data which were read from flash?

Hiya,

Not quite.

The function definition is as follows:

s8 adl_flhRead (ascii* Handle, u16 ID, u16 Len, u8 *ReadData )

The parameters are the handle of the flash object, the ID of the Flash Object to read, the length of data to read, and the string allocated to store the read flash object.
In other words, the adl_flhRead() function DOES NOT allocate RAM before COPYING Len bytes from flash into the RAM buffer.

You need to allocate the ReadData buffer before calling adl_flhRead(). The buffer can either be a constant length array, (i.e. u8 myByffer[20] ); or can be dynamically allocated on the heap ( i.e. u8 *myBuffer = adl_memGet(sizeof(u8) * 20); … ; adl_memRelease(myBuffer) ).

You can use the length value returned from adl_flhExist() to work out how many bytes to allocate for your ReadBuffer.

I guess you have been lucky that you haven’t been getting CPU Exceptions from trying to write to an invalid area of RAM, or from scribbling over something else.

Hope this helps.

ciao, Dave

Dave, thank you very much! That really helped!

Hiya,

No problems. Glad that you got things going.

ciao, Dave