Hacker News new | ask | show | jobs
by sansnomme 2392 days ago
What does this line of code mean?

    *(volatile uint32_t *)0x40021018 = 0x00000004;
Why is a pointer being created and dereferenced at the same time?
3 comments

It's how you access memory mapped registers in C. It's writing the value 0x04 at that address using a 32-bit memory write. There is a peripheral register at that location.
You could split up the definition of the pointer and the dereferencing+assignment:

  volatile uint32_t* p = (volatile uint32_t *)0x40021018;
  *p = 0x00000004;
Thats memory mapped IO. Registers, and control registers are mapped onto certain regions of memory on ARM Coretx-M processors.