# Should I define default register values in start up code?

It has come to my attention that some ARM programmers set some CPU registers with values that are the same default values of the register on microcontroller reset.

For example: the default value of IOCON_PIO2_9, parameter MODE on LCP1114 is 0x02 (pull-up resistor enabled). In Olimex's example code this value is set to 0x02 in software initialization but this is already the default value.

This behavior occurs with many other registers.

Why would someone do that? In my opinion, this extra code just pollutes everything and make code readability worse. Is this a good programming practice?

-
I'm not a person to be talking about "best practice", but especially on a platform like ARM, where all peripheral functionality is on the manufacturer and you might find yourself jumping between manufacturers, it seems like this practice would enhance portability. –  Scott Seidman Jan 20 at 14:11
You ever heard the quote "Assumption is the mother of all f***kups"? Never assume anything, even the default values can change if there is a brownout or somesuch so never rely on anything to be in any state unless you set it yourself. –  John U Jan 20 at 19:07

It may be worth noting that if FOO->CTL has a default value of 0x12345678, and one only cares about having the lower bits set to 8, there's a clarity/code-space/performance trade-off between writing the entire register to 0x12345678, versus using something like maskedwrite32(&(FOO->CTL), BLAH_MASK, BLAH_MODE8);. If the masked-write routine includes code to make it atomic in case of interrupts, that may make it slower than it needs to be, but improve the code's generality. –  supercat Jan 20 at 17:27