# writeUserBlock - Corrrupted values

**URL:** https://forums.digi.com/t/writeuserblock-corrrupted-values/18869
**Category:** Rabbit Software
**Tags:** c, dynamic, writeuserblock
**Created:** [November 1, 2017, 2:25pm UTC](https://forums.digi.com/t/writeuserblock-corrrupted-values/18869 "2017-11-01T14:25:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![diverdke55](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diverdke55](https://forums.digi.com/u/diverdke55)
#### Post date: [November 1, 2017, 2:25pm UTC](https://forums.digi.com/t/writeuserblock-corrrupted-values/18869/1 "2017-11-01T14:25:03Z")

</div>

I am using a BL2100 controller w/ (RCM2200) core. I am writing a block of data via WriteUserBlock. The data is:

sizeof(configtype) unsigned int 2920 (0x0B68) bytes

I am writing starting at address 0x0000;

Occasionally, on a power cycle; the values from ReadUserBlock are corrupted. This causes a system re-init, which is somewhat shocking to the customer.

As the user makes changes to the options, WriteUserBlock is used to update the configurations. This is running in a task in uC/OS-II. Is WriteUserBlock task safe or is it getting interrupted and corrupting the write process?

Results from userblock\_info.c

Does not contain mirrored ID/User blocks. A power cycle  
while the User block is being written can leave the User  
block in an inconsistent state.

Combined ID and User blocks consume 0x00004000 (16384) bytes  
at the top of the first flash.

Combined ID plus User blocks size: 0x00002000 (8192) bytes.

System ID block / area size: 0x00000084 (132) bytes.  
User block size: 0x00001F7C (8060) bytes.  
Available User block size: 0x00001C00 (7168) bytes.  
Reserved User block size: 0x0000037C (892) bytes.

---

<div class="post-metadata">

### Author: ![TomCollins](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/tomcollins/32/37_2.png) [@TomCollins](https://forums.digi.com/u/TomCollins)
#### Post date: [November 1, 2017, 5:13pm UTC](https://forums.digi.com/t/writeuserblock-corrrupted-values/18869/2 "2017-11-01T17:13:16Z")

</div>

Make sure you only call WriteUserBlock() from one of your tasks. If you were to interrupt it with another call, it’s possible you could corrupt the userblock.

Also, consider updating your device to use mirrored user blocks. By doing so, the library either writes to user block A or B, ensuring that there’s always a valid block available if a write fails.

I believe you can update to mirrored user blocks using this program from Dynamic C 9:

[https://github.com/digidotcom/DCRabbit\_9/blob/master/Samples/write\_idblock\_920\_962.c](https://github.com/digidotcom/DCRabbit_9/blob/master/Samples/write_idblock_920_962.c)

Your report is a bit confusing though, since it claims both 16K for combined blocks and 8K, which would appear to represent mirrored 8KB user blocks.

What version of Dynamic C are you using? If it isn’t 9.62, can you try the userblock report program from that release?

---

<div class="post-metadata">

### Author: ![diverdke55](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diverdke55](https://forums.digi.com/u/diverdke55)
#### Post date: [November 3, 2017, 9:16am UTC](https://forums.digi.com/t/writeuserblock-corrrupted-values/18869/3 "2017-11-03T09:16:16Z")

</div>

I am using 9.62. I will download and try the mirrored blocks routine. I am calling WriteUserBlock() from a task. Thanks
