# adl\_flhWrite hangs after 292 calls

**URL:** https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154
**Category:** Open AT
**Created:** [November 28, 2005, 8:58am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154 "2005-11-28T08:58:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pcorgier](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pcorgier](https://forum.sierrawireless.com/u/pcorgier)
#### Post date: [November 28, 2005, 8:58am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/1 "2005-11-28T08:58:50Z")

</div>

I am writing into one handle which max count is 2000.  
Then I do a loop from i=0 to 1999, writing 16 bytes at each ID=i.  
The first 292 calls are succesfull (and valid datas can be reread), then my Q2501B hangs.

The data flash remains unusable until I enter a WOPEN=3 command.

If anayone has an idea …

---

<div class="post-metadata">

### Author: ![snoooze](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@snoooze](https://forum.sierrawireless.com/u/snoooze)
#### Post date: [November 28, 2005, 10:15am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/2 "2005-11-28T10:15:14Z")

</div>

Hello,

Some questions basically about the status just before the module hangs… that might give a clue of whats causing the problem…

1. What does the adl\_flhGetFreeMem return just before that last write call?
2. What is the result code of the last adl\_flhWrite call?

/Snoooze

---

<div class="post-metadata">

### Author: ![pcorgier](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pcorgier](https://forum.sierrawireless.com/u/pcorgier)
#### Post date: [November 28, 2005, 10:23am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/3 "2005-11-28T10:23:39Z")

</div>

Hello,

adl\_flhGetFreeMem() returned 111006 and adl\_flhGetIDCount returned 2000.

adl\_flhWrite returned OK the last time … the next one never returns.

I tried with other capacity ranges (eg 350) and other cell’s size (eg 32, 64 bytes) ; it allways hang.

Philippe

---

<div class="post-metadata">

### Author: ![pcorgier](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pcorgier](https://forum.sierrawireless.com/u/pcorgier)
#### Post date: [November 28, 2005, 12:59pm UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/4 "2005-11-28T12:59:28Z")

</div>

Additionaly, I did print before each adl\_flhWrite() the result of calls :

- adl\_flhExist() --\> allways 0 (cause of my AT+WOPEN=3)
- adl\_flhGetUsedSize( …, 0, i) --\> 3796 just before thre hang

Note : the Q25 doesn’t hang forever ; it reboots after 10 seconds then hangs and so one, forever.

---

<div class="post-metadata">

### Author: ![huangyi](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@huangyi](https://forum.sierrawireless.com/u/huangyi)
#### Post date: [December 22, 2005, 5:04am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/5 "2005-12-22T05:04:06Z")

</div>

Could it be possible the reset is caused by the watchdog?

---

<div class="post-metadata">

### Author: ![OpenAT\_Fan](https://avatars.discourse-cdn.com/v4/letter/o/f07891/32.png) [@OpenAT\_Fan](https://forum.sierrawireless.com/u/OpenAT_Fan)
#### Post date: [December 22, 2005, 7:02am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/6 "2005-12-22T07:02:39Z")

</div>

Hi pcorgier,  
The problem might be due to the fact that flash write operations should not be performed repetitiously in a loop. This is because, each write operation in flash will take some time. Also, some internal processes (like garbage collection) etc will be performed on each write. Hence, as the amount of data in the flash increases, each of these operations (garbage collection etc) will take more and more time.  
Hence, as a precaution, you should subscribe to a timer after each call to adl\_flhWrite () API and only in the timer handler should you write to the flash again. This will provide enough time to ADL library to perform internal stuff (like garbage collection etc).

When you use a loop to write to flash (instead of using a timer), your Open-AT application will issue adl\_flhWrite () APIs to ADL library without any consideration for the time it takes to actually write into flash.  
This might cause stack overflow (as now ADL internal functions are in process and your applicaiton still makes calls to adl\_flhWrite ()) or may also cause watchdog reset (as OAT is not leaving the CPU).  
Hence, it is best to write to flash using a timer when the number of flash objects to write is greater than 100.

Best Regards.

---

<div class="post-metadata">

### Author: ![pcorgier](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pcorgier](https://forum.sierrawireless.com/u/pcorgier)
#### Post date: [December 22, 2005, 7:52am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/7 "2005-12-22T07:52:57Z")

</div>

I do one write per couple of seconds, called from a timer handler.

After all, I got a new starter kit (because the SIM reader did’nt work) ; since, the flash writing problem doesn’t append any more !

Now a last problem remains : I get ADL\_FLH\_RET\_ERR\_NO\_ENOUGH\_IDS error after 1600 or 2500 writes. The number of successfull writes is very variable.

---

<div class="post-metadata">

### Author: ![OpenAT\_Fan](https://avatars.discourse-cdn.com/v4/letter/o/f07891/32.png) [@OpenAT\_Fan](https://forum.sierrawireless.com/u/OpenAT_Fan)
#### Post date: [December 22, 2005, 11:42am UTC](https://forum.sierrawireless.com/t/adl-flhwrite-hangs-after-292-calls/154/8 "2005-12-22T11:42:41Z")

</div>

Hi pcorgier,  
ADL user Guide specifies that at a timer at the most 2000 object identifiers for flash memory can exist (ADL User Guide, Section 3.5.2).  
So, could you please check if your application tries to manipulate object identifiers greater than 2000.  
If possible, you can start afresh by erasing all the flash data (by executing AT+WOPEN=3 command) and then observe the behavior.

Usually ADL\_FLH\_RET\_ERR\_NO\_ENOUGH\_IDS is returned if the flash write operation fails due to limitation of number of available IDs.

Best Regards.
