Hi,
it is a little late for the existing libraries, but it might be worth considering for future-developments:
On ARM it is more efficient to use structs instead of constants to acces registers, as soon you access more than one in a function.
For example, to access the Hardware-Serial, you have several direct reads and writes to the hardware. GCC needs to load the adress of each register indepently.
More efficient (faster - and less code) is to use structs. This way, GCC need the adress of the struct only, and can use the offsets/displacements for subsequent accesses.
A short example for GPIO:
Now, an registeraccess looks like :
GPIO_D->PDDR = 1;
GPIO_D->PDOR = 1;
This way, it loads the 32-Bit address only one time (and uses the offset to 0x400FF0C0), instead of loading it twice.
In some cases, this can lead to huge speed-improvements, too.
it is a little late for the existing libraries, but it might be worth considering for future-developments:
On ARM it is more efficient to use structs instead of constants to acces registers, as soon you access more than one in a function.
For example, to access the Hardware-Serial, you have several direct reads and writes to the hardware. GCC needs to load the adress of each register indepently.
More efficient (faster - and less code) is to use structs. This way, GCC need the adress of the struct only, and can use the offsets/displacements for subsequent accesses.
A short example for GPIO:
Code:
struct sGPIO {
uint32_t PDOR; //Port Data Output Register
uint32_t PSOR; //Port Set Output Register
uint32_t PCOR; //Port Clear Output Register
uint32_t PTOR; //Port Toggle Output Register
uint32_t PDIR; //Port Data Input Register
uint32_t PDDR; //Port Data Direction Register
};
volatile struct sGPIO * const GPIO_D = (struct sGPIO *)0x400FF0C0;
Now, an registeraccess looks like :
GPIO_D->PDDR = 1;
GPIO_D->PDOR = 1;
This way, it loads the 32-Bit address only one time (and uses the offset to 0x400FF0C0), instead of loading it twice.
In some cases, this can lead to huge speed-improvements, too.
Last edited: