Registers access and pointers

Hi all,

I'm using the Redboard Artemis Global Tracker that has the Apollo3 processor and I'm trying to access the Status register that gives the reason of a reset.

So this is the code I'm using to declare a pointer and assigning the address of the register. I'm trying to see the value inside the register but it only gives me the value of the address. I'm used to accessing registers using C on STM32 MCUs. I wonder what wrong with my code.

uint32_t *pSTAT = (uint32_t*)0x4FFFF000;
uint32_t *pINTSTAT = (uint32_t*)0x40024204;

Serial.print("Watchdog status register:  ");
Serial.println((long) pSTAT, BIN);
Serial.print("Watchdog interrupt status register:  ");
Serial.println((long) pINTSTAT, BIN);

image

You need to dereference it. And you should mark it volatile.

https://www.learncpp.com/cpp-tutorial/introduction-to-pointers/

Hello

You have to dereference the pointer, to get the value at the pointed address. See here : C++ Dereferencing

It'd be a lot more readable and reliable as

Serial.print("Watchdog status register:  ");
Serial.println(RSTGEN->STAT, BIN);

Like the AVR; the Arduino builds for the Ambiq chips include the basic chip-internal register definitions. It's just a matter of looking at, um, ...packages/SparkFun/hardware/apollo3/2.2.1/cores/mbed-os/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/sdk/CMSIS/AmbiqMicro/Include/apollo3.h to see exactly what they decided to name things. I searched for "sbl", since that seemed more likely to "hit" than "stat"

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.