prog_uint32_t help

Hello,
I have used the program memory successfully in the past for 8 and 16bit constants. However, for 32 bit constants I cannot seem to make it work. Can someone please tell me what I am doing wrong here? I am using an Arduino UNO btw

#include <avr/pgmspace.h>

void setup() {

  Serial.begin(115200);  
  Serial.write("Here we go...\n");
  static prog_uint32_t TESTCONSTANT=4000000;

  Serial.write("TESTCONSTANT=");
  Serial.println(pgm_read_dword_near(&TESTCONSTANT));
}

void loop() {
}

Result: (I am expecting to see TESTCONSTANT=4000000)

Here we go...
TESTCONSTANT=1620315872

try

static prog_uint32_t TESTCONSTANT=4000000UL; // UL = unsigned long

does that help?

robtillaart:
try

static prog_uint32_t TESTCONSTANT=4000000UL; // UL = unsigned long

does that help?

unfortunately not. Here is the test case and result

code:

#include <avr/pgmspace.h>

void setup() {

  Serial.begin(115200);  
  Serial.write("Here we go...\n");
  static prog_uint32_t TESTCONSTANT1=4000000L;
  static prog_uint32_t TESTCONSTANT2=4000000;
  static prog_uint32_t PROGMEM  MAX_U32=4294967200;

  Serial.write("TESTCONSTANT1=");
  Serial.println(pgm_read_dword_near(&TESTCONSTANT1));
  Serial.write("TESTCONSTANT2=");
  Serial.println(pgm_read_dword_near(&(TESTCONSTANT2)));
  Serial.write("MAX_U32=");
  Serial.println(pgm_read_dword_near(&MAX_U32));
}

void loop() {
}

result (notice the huge MAX_U32 is working for some reason)...

Here we go 
TESTCONSTANT1=29885333
TESTCONSTANT2=2484002864
MAX_U32=4294967200

Functionally equivalent and works correctly...

void setup() {

  Serial.begin(115200);  
  Serial.write("Here we go...\n");
  const uint32_t TESTCONSTANT = 4000000;

  Serial.write("TESTCONSTANT=");
  Serial.println( TESTCONSTANT );
}

void loop() {
}

PROGMEM is required...

#include <avr/pgmspace.h>

void setup() {

  Serial.begin(115200);  
  Serial.write("Here we go...\n");
  static prog_uint32_t TESTCONSTANT PROGMEM = 4000000;

  Serial.write("TESTCONSTANT=");
  Serial.println(pgm_read_dword_near(&TESTCONSTANT));
}

void loop() {
}

Yes but does TESTCONSTANT get saved in program memory? If so that is all I need

That worked - thanks!!!

memotick:
Yes but does TESTCONSTANT get saved in program memory? If so that is all I need

In the form of four LDI machine instructions.