# Writing and reading from Flash

**URL:** <https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286>\
**Category:** Open AT\
**Created:** [February 14, 2006, 6:10pm UTC](https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286 "2006-02-14T18:10:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 14, 2006, 6:10pm UTC](https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286/1 "2006-02-14T18:10:36Z")

</div>

Hi, IÂ´ve been trying to write and read from Flash memory… but didnÂ´t have enough results… so I hope you people could give me a hand…

HereÂ´s the code IÂ´m trying:

```auto
s8 memoria_flash;
static const ascii * flash_handle = "";

void atualiza_flash ( u8 id, ascii ** ParamStr, bool bWrite )
{

    if ( bWrite )
    {

        if ( *ParamStr != NULL )
        {

			TRACE((1, ParamStr));
            adl_flhWrite ( flash_handle, id, wm_strlen ( *ParamStr ) + 1, *ParamStr );
        }
        else
        {

            adl_flhErase ( flash_handle, id );
        }
    }
    else
    {

        s32 Length = adl_flhExist ( flash_handle, id );

        

        if ( Length >= 0 )
        {

            if ( *ParamStr != NULL )
            {

                adl_memRelease ( *ParamStr );
            }
            

            *ParamStr = adl_memGet ( Length );
            

            adl_flhRead ( flash_handle, id, Length, *ParamStr );

        }
    }
}
```

HereÂ´s the how IÂ´m trying to write and read, calling the function above:

```auto
ascii word_test[30];
	atualiza_flash ( 0, "Just a test", TRUE );
	atualiza_flash(0,word_test,FALSE);
```

But word\_test never receives the “Just a test” string…

Any ideas?

Best Regards,

Henrique

---

<div class="post-metadata">

**Author:** ![jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jan](https://forum.sierrawireless.com/u/jan)\
**Post date:** [February 15, 2006, 7:52am UTC](https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286/2 "2006-02-15T07:52:35Z")

</div>

Hi Henrique,

I’m not sure if that’s the problem, but I wouldn’t use an empty string for the flash handle…

```auto
static const ascii * flash_handle = "";
```

Also, the adl\_flh\*\*\* functions do return error codes. Maybe you should look at those to determine if there was an error…

Best Regards,  
Jan

---

<div class="post-metadata">

**Author:** ![Piedos](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@Piedos](https://forum.sierrawireless.com/u/Piedos)\
**Post date:** [February 15, 2006, 1:08pm UTC](https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286/3 "2006-02-15T13:08:32Z")

</div>

> [@](#):
>
> \*ParamStr = adl\_memGet ( Length );

I think the error is with the ascii word\_test[30];

you can’t use memGet or memRelease with an array

please use  
ascii \* word\_test;  
word\_test = adl\_memGet(30);

instead…

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 15, 2006, 4:56pm UTC](https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286/4 "2006-02-15T16:56:21Z")

</div>

Following the two advices hereÂ´s the code:

```auto
word_test = adl_memGet(32);
atualiza_flash(0, "Testing a String", TRUE);
atualiza_flash(0,word_test,FALSE);
TRACE((1, gps_string));
```

But I canÂ´t get TRACE response as: “Testing String”.

What might be wrong?

Best Regards,

Henrique

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 15, 2006, 5:39pm UTC](https://forum.sierrawireless.com/t/writing-and-reading-from-flash/286/5 "2006-02-15T17:39:13Z")

</div>

I replaced the Pointer programming with Global variables and everything is just fine now.  
??? donÂ´t know why didnÂ´t worked… ???

I have one more question:

adl\_flhGetIDCount() function retrieves the instant ID count, right?

Does the ID counts only for manual FLASH recording or ADL already uses this function internally?

I want to know because IÂ´m trying to parse “FLASH ID Count + 1” as a parameter to the function I save the data.

Like:

```auto
atualiza_flash (adl_flhGetIDCount(flash_handle)+1, word_test,TRUE );
```

Before the line code above, I tryed to display the FLASH Count ID and it says : 1024.

But inside the “atualiza\_flash()” function I once again displayed the “id” variable that came through the first parameter.

And now it says: “1”

Is there anything I should do?

Best Regards,

Henrique
