Electronics > Microcontrollers

[ARM] [Sam] Uh is it a good idea to map registers to structs

(1/10) > >>

Simon:
So trying to write code for something like a counter that has 3 modes is becoming hard work as though bare metal programming is not already hard work but in my view better as you understand the chip. I see that the SAM ARM chips no longer have header files that create these struct like they did for the mega 0 series.

I've read around and found just about everyone condemning the idea in blogs, but microchips own developer help tell you to do this. So what is the verdict.

You will find me hence forth in an undisclosed location in fear of my life for the reactions this topic is certain to get  :-DD

Ian.M:
This: https://blog.feabhas.com/2019/01/peripheral-register-access-using-c-structs-part-1/ covers *some* of why mapping structs to peripheral registers can be a really bad idea.   Also, the compiler may silently generate multiple accesses to the volatile register, with unexpected side effects to satisfy what the programmer sees as a simple write to a bitfield.

The manufacturers can do it in their supplied headers, as they can be (and should be) qualified by the manufacturer with their recommended/supplied compiler to ensure that there are either no undesirable side effects, or that they are well documented, and workarounds provided.   Write your own struct to register mapping, and *YOU* take on that heavy responsibility.   You should definitely emit a warning, or even an error if the compiler and its version don't match one you have tested with your structs.

Simon:
Well microchip are so good that they make a mess of explaining registers. Boy is the TC CTRLA register a damn nightmare. I have to first set the counter to the one of three modes I want so that I can write to registers that otherwise do not exist but then I cannot set the pre-scaler unless I do it when I enable the counter. Apparently non of the bits I want to write are synchronised but something weird is happening and it took trial and error.

And no having the sum total of the "clear" instructions on how this works broken up into little titbits of information spread across 1'500 pages.

emece67:
cmsis does map registers into structs. Would be interesting to work with a compiler that breaks that.

What MCU are you using? I'm working now with a SAM4 and the header files are freely available, as many others, from the Keil website.

Simon:
I'm using the SAMC, the link on there for that just takes you to microchip and an install file.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version