Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with reserved register bits of an ARM chip

I am working with the registers of an ARM Cortex M3. In the documentation, some of the bits may be "reserved". It is unclear to me how I should deal with these reserved bits when writing on the registers.

Are these reserved bits even writeable? Should I be cautious to not touch them? Will something bad happen if I touch them?

like image 428
Randomblue Avatar asked Dec 16 '22 02:12

Randomblue


1 Answers

This is a classic embedded world problem as to what to do with reserved bits! First, you should NOT write randomly into it lest your code becomes un-portable. What happens when the architecture assigns a new meaning to the reserved bits in future? Your code will break. So the best mantra when dealing with registers having reserved bits is Read-Modify-Write. i.e read the register contents, modify only the bits you want and then write back the value so that reserved bits are untouched ( untouched, does not mean we dont write into them, but in the sense, that we wrote that which was there before )

For example, say there is a register in which only the LSBit has meaning and all others are reserved. I would do this

ldr r0,=memoryAddress
ldr r1,[r0]
orr r1,r1,#1
str r1,[r0]
like image 69
Pavan Manjunath Avatar answered Feb 05 '23 19:02

Pavan Manjunath