Thread: Pointers to Special function registers

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    92

    Pointers to Special function registers

    Hello everyone,
    I am having trouble with pointers, I understand that pointers are just variables that store memory address and here is a example from ARM MCU.

    For example there is a special function register called General purpose I/O B Port Data Direction Register or just GPIOB_PDDR.

    GPIOB_PDDR has address 0x400FF054 in memory address map and what bothers me is that from a book that I learn ARM MCU author declares variable as

    Code:
    #define GPIOB_PDDR (*((volatile unsigned int*)0x400FF054))
    I understand it this variable has to be type of integer pointer since we store address in it. so part "(volatile unsigned int*)0x400FF054)" is clear to me.

    But why do we have another asterix * before the brackets?

    Could I declare it something like
    Code:
    volatile unsigned int* GPIOB_PDDR = 0x400FF054

    Also when we write

    Code:
    GPIOB_PDDR |= 0x80000;
    Do we write a value to a register which GPIOB_PDDR aka pointer points to?
    Last edited by High Voltage; 02-11-2017 at 03:18 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > But why do we have another asterix * before the brackets?
    So you can write this
    GPIOB_PDDR |= 0x80000;
    instead of this
    *GPIOB_PDDR |= 0x80000;

    It's a convenience thing.

    > Do we write a value to a register which GPIOB_PDDR aka pointer points to?
    Yes, you end up writing to the memory at address 0x400FF054
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Registers, C++
    By yanol in forum C++ Programming
    Replies: 6
    Last Post: 06-05-2008, 02:07 AM
  2. Using MMX & XMM Registers
    By HyperShadow in forum C++ Programming
    Replies: 3
    Last Post: 07-14-2007, 12:53 AM
  3. special function detection
    By zyd in forum C Programming
    Replies: 7
    Last Post: 02-28-2006, 03:25 PM
  4. memcpy with 128 bit registers
    By grady in forum Linux Programming
    Replies: 2
    Last Post: 01-19-2004, 06:25 AM
  5. Registers
    By Golden in forum C Programming
    Replies: 2
    Last Post: 09-04-2001, 11:48 AM

Tags for this Thread