pgmspace.h is not supported?

I’m getting errors of file not found for this code:

#include <avr/pgmspace.h>

Or the folder \hardware\tools\avr\avr\include\avr where the file exists is not included on the search path for load?

maple has FLASH, e.g., uint32_t array[] FLASH = {0, 1, 2}; but that doesn't seem to work for DUE gcc. :(

But another thread in this Due forum notes that declaring things "const" puts them in flash ... :)

Is there a way to add some other directory to the lib global search path?

It works if I put the all directory to the file like this:

#include <C:\arduino-1.5\hardware\tools\avr\avr\include\avr\pgmspace.h>

So this must be a missing search path to the directory where these files are normaly like on previous IDE.

Yeah, you don’t need pgmspace any more. The Due and other arduinos are of different architecture, and with the due simply declaring const will put it in the program space.

This is what I have put at the top of one of my library files to make the two compatible:

#ifndef __arm__
#include <avr/pgmspace.h>
#define PROGMEM const
#define F(x) x

And then for example you can use it like:

PROGMEM byte myArray[500] = {1,2,3,4,5,6, ...};

The advantage of doing it this way is that when you are using an avr, the #include statement will be valid.

#include <C:\arduino-1.5\hardware\tools\avr\avr\include\avr\pgmspace.h>

including an avr-specific include file (anything starting with “avr/” in an ARM project would be an extremely bad idea!

It would be nice if there were an Arduino “flashmem.h” or something that would hide some ugly conditional compilation similar to what Tom has done.

Here is the “pgmspace.h” that Teensy 3.0 uses to (hopefully) make most AVR-specific code compile and work:

#ifndef __PGMSPACE_H_
#define __PGMSPACE_H_ 1

#include <inttypes.h>

#define PROGMEM
#define PGM_P  const char *
#define PSTR(str) (str)

typedef void prog_void;
typedef char prog_char;
typedef unsigned char prog_uchar;
typedef int8_t prog_int8_t;
typedef uint8_t prog_uint8_t;
typedef int16_t prog_int16_t;
typedef uint16_t prog_uint16_t;
typedef int32_t prog_int32_t;
typedef uint32_t prog_uint32_t;

#define strcpy_P(dest, src) strcpy((dest), (src))
#define strcat_P(dest, src) strcat((dest), (src))
#define strcmp_P(a, b) strcmp((a), (b))

#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
#define pgm_read_float(addr) (*(const float *)(addr))

#define pgm_read_byte_near(addr) pgm_read_byte(addr)
#define pgm_read_word_near(addr) pgm_read_word(addr)
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
#define pgm_read_float_near(addr) pgm_read_float(addr)
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
#define pgm_read_word_far(addr) pgm_read_word(addr)
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
#define pgm_read_float_far(addr) pgm_read_float(addr)


I’m still refining this and lots of other AVR compatibility stuff. But so far, it seems to be working for the most common usages.

That works well if you put it in the folder:

<Arduino Dir>\hardware\arduino\sam\libraries\avr\avr\

One query though, aren’t you missing the const keyword? In which case surely everything gets stuck in the RAM, or have I missed something.

In which case should you define ‘PROGMEM’ as ‘const’
#define PROGMEM const
I suppose the problem with that is if people put the PROGMEM term after the variable name in which case it wont work.

Thanks Paul, including your code for now stoped givving errors regarding pgmspace but let’s see further down since now I’m stucked on the port conversion, the lib referes to PORTA for example witch is not defined for DUO and I can’t find where the new definitions exist or what I can use insted.

Tom, for now I just put the pgmspace.h file from Paul on the current lib dir and all previous #include <avr/pgmspace.h> I change them to #include “pgmspace.h”.

You mention "the lib". What is that?

That's the library I'm trying to port, actualy it's the UTFT from Henning Karlsen so I can use the TFT and touch with the DUO.

If you put it in the folder I suggested, you can just use:

#include <avr/pgmspace.h>

to include it in your library, meaning you can use the same stement for both due and avr.

Baltasar: That's the library I'm trying to port, actualy it's the UTFT from Henning Karlsen so I can use the TFT and touch with the DUO.

Where could I buy a display that is known to work with UTFT using the serial interface? I found the UTFT page and clicked links to the displays claimed to work. All were out of stock, or 16 bit parallel interface, or had no significant info.

Paul, usualy I get them from here: but the sometimes show up on eBay.

I think all of them from taht link work with Henning library, I use the ITDB02-3.2WD.

Do you know where I can find info reagardin the DUO ports, since now I have to change all of that part of the code for the reconizes DUO ports, like for example this part:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
        PORTA = VH;
        pulse_low(P_WR, B_WR);
        PORTA = VL;
        pulse_low(P_WR, B_WR);
        PORTD = VH;
        pulse_low(P_WR, B_WR);
        PORTD = VL;
        pulse_low(P_WR, B_WR);

PORTA and the rest are not beeing reconized since probably they are not defined.

Sorry Paul, I just realised now that you wore refering to the serial ones, those I don’t really know. :~


While struggling with port definition, theres a file called variant.cpp that as the pin NAMES.

However, when trying to set the port with this:

//DB08 on PIN22 PIO_PB26=(VH & 0x01);

it returns:

D:\Docs\Arduino\arduino-1.5\libraries\UTFT\/HW_ARM.h:67: error: lvalue required as left operand of assignment

Line 67 is :

PIO_PB26=(VH & 0x01);

Why is this happening? why can't I set this port bit with the LSB bit value of VH ?

I purchased a couple LCDs from iTead. It'll probably be 2-3 weeks until I actually get them.

      //DB08 on PIN22

PIO_PB26=(VH & 0x01);

The PIO_PB26 definitions are typical of Atmel, and merely define bitmasks like “(1 << 26)” rather than useful structures that you can assign a value to (this is consistent with things like “PB4” on the AVR, by the way.)
They’re in hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/pio/pio_sam3x8e.h
“direct port access” on some ARM chips is not very direct, because the “General purpose IO” peripherals are quite complex. I haven’t read the Atmel manual to see how it works.