# Error "ADL\_RET\_ERR\_PARAM" while reading from flash

**URL:** <https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239>\
**Category:** Open AT\
**Created:** [May 15, 2009, 12:32pm UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239 "2009-05-15T12:32:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatiana](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@tatiana](https://forum.sierrawireless.com/u/tatiana)\
**Post date:** [May 15, 2009, 12:32pm UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239/1 "2009-05-15T12:32:18Z")

</div>

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!

```auto
#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:
				   }
```

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [May 15, 2009, 12:54pm UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239/2 "2009-05-15T12:54:11Z")

</div>

> [@tatiana](#):
>
> ```auto
> u8 * PinCode;
> ```

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

---

<div class="post-metadata">

**Author:** ![tatiana](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@tatiana](https://forum.sierrawireless.com/u/tatiana)\
**Post date:** [May 17, 2009, 8:47am UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239/3 "2009-05-17T08:47:17Z")

</div>

> [@awneil](#):
>
> > [@tatiana](#):
> >
> > ```auto
> > u8 * PinCode;
> > ```
> 
> PinCode is a pointer - but you haven’t set it to point to anything ! 😮

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?

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [May 17, 2009, 11:56am UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239/4 "2009-05-17T11:56:49Z")

</div>

Hiya,

> [@tatiana](#):
>
> 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?

Not quite.

The function definition is as follows:

```auto
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

---

<div class="post-metadata">

**Author:** ![tatiana](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@tatiana](https://forum.sierrawireless.com/u/tatiana)\
**Post date:** [May 18, 2009, 12:52pm UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239/5 "2009-05-18T12:52:11Z")

</div>

> [@davidc](#):
>
> Hiya,
> 
> > [@tatiana](#):
> >
> > 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?
> 
> Not quite.
> 
> The function definition is as follows:
> 
> ```auto
> 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!

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [May 18, 2009, 10:40pm UTC](https://forum.sierrawireless.com/t/error-adl-ret-err-param-while-reading-from-flash/3239/6 "2009-05-18T22:40:32Z")

</div>

Hiya,

> [@tatiana](#):
>
> Dave, thank you very much! That really helped!

No problems. Glad that you got things going.

ciao, Dave
