Go Down

Topic: pgmspace.h is not supported? (Read 10850 times) previous topic - next topic

Baltasar

Oct 27, 2012, 09:43 pm Last Edit: Oct 28, 2012, 02:07 am by Baltasar Reason: 1
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?

Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

mantoui

#1
Oct 28, 2012, 01:57 am Last Edit: Oct 28, 2012, 02:01 am by mantoui Reason: 1
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 ...  :)

Baltasar

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.

Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

Tom Carpenter

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:

Code: [Select]
#ifndef __arm__
#include <avr/pgmspace.h>
#else
#define PROGMEM const
#define F(x) x
#endif


And then for example you can use it like:

Code: [Select]
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.
~Tom~

westfw

Quote
#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.


Paul Stoffregen

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

Code: [Select]

#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)

#endif



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.

Tom Carpenter

That works well if you put it in the folder:
Code: [Select]
<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.
~Tom~

Baltasar

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".



Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

Paul Stoffregen

You mention "the lib".  What is that?

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.
Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

Tom Carpenter

#10
Oct 30, 2012, 10:09 am Last Edit: Oct 30, 2012, 10:11 am by Tom Carpenter Reason: 1
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.
~Tom~

Paul Stoffregen


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.

Baltasar

Paul, usualy I get them from here: http://imall.iteadstudio.com/display/tft-lcm.html 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:

Code: [Select]
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
PORTA = VH;
pulse_low(P_WR, B_WR);
PORTA = VL;
pulse_low(P_WR, B_WR);
#else
PORTD = VH;
pulse_low(P_WR, B_WR);
PORTD = VL;
pulse_low(P_WR, B_WR);
#endif



PORTA and the rest are not beeing reconized since probably they are not defined.
Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

Baltasar

Sorry Paul, I just realised now that you wore refering to the serial ones, those I don't really know.  :~
Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

alvesjc

Hi!

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 ?
www.aqualedsource.com

Go Up