Go Down

Topic: Standard libraries unknown in IDE V1.5.1r2 (Read 3934 times) previous topic - next topic

crazyben

Hello all,

I'am new to this forum and thats my first Post :)

Yes, I' am aware of this tread: http://arduino.cc/forum/index.php/topic,138226.0.html

I experienced the following issue:
I started the development with my brand new Arduino Due board.
My Programm is very large and it have to move it from the Mega 2560.

But all my self created classes won't work anymore.
It seems that the IDE is not including the files properly.

For example:
- Class files: Time.h / Time.cpp
- Class needs files: Ethernet.h / EthernetUdp.h / Arduino.h / Wire.h / SPI.h
- Class location: <ARDUINO>/libraries/Time/..

Is this a known issue in the 1.5.1r2 or have you changed the way of including libraries?
For example do I need to add an prefix or path?

I also experienced issues with classes from other developers where the object is declared as external. Here it was helpful to build a pointer rather than using external declaration.

Arctic_Eddie

I am the originator of the other thread. It is likely that both of our problems have a common cause in the new IDE. The source of the problem is likely known only to the IDE creator. I'm going to watch both threads for clues. Until then, I'll just continue with the Mega.

crazyben

Hello Arctic_Eddie,

It took me 1/2 pot of coffee but it is now working.
I included ALL headers in the main programm.

My class CTIME.h starts now:
#ifndef TIME_H
#define TIME_H

#include <Wire.h>
#include <SPI.h>  
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Arduino.h>

My Programm starts now:
#include <Wire.h>
#include <SPI.h>  
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>


void setup() { }

Maybe this is also the solution for your problem..

Arctic_Eddie

Just tried it and no go. I just really find it odd that compiling for the Mega works and the Due doesn't, in the same IDE.


crazyben

It seems you are right.
I'm struggling with some libraries..

I tried to compile the OneWire library and run into an very excellent handled error:
Code: [Select]
// Platform specific I/O definitions

#if defined(__AVR__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))

#elif defined(__PIC32MX__)
#include <plib.h>  // is this necessary?
#define PIN_TO_BASEREG(pin)             (portModeRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+4)) & (mask)) ? 1 : 0)  //PORTX + 0x10
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+2)) = (mask))            //TRISXSET + 0x08
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) = (mask))            //TRISXCLR + 0x04
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+8+1)) = (mask))          //LATXCLR  + 0x24
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+8+2)) = (mask))          //LATXSET + 0x28

#else
#error "Please define I/O register types here"
#endif


But never the less, i don't have the knowledge at the moment for creating the correct platform specific definitions. My opinion is that this is a good example for an incompatible library (based on platform / CPU change)

alvesjc

Hi.

I'm struggling in the same onewire lib right now.

I've made it to compile, but it doesn't work anyway.

in the defines I've this:

Code: [Select]

// Platform specific I/O definitions

#if defined(__AVR__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))

#elif defined(__SAM3X8E__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))
#include "pgmspace.h"

#elif defined(__PIC32MX__)
//- #include <plib.h>  // is this necessary?
#define PIN_TO_BASEREG(pin)             (portModeRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+4)) & (mask)) ? 1 : 0)  //PORTX + 0x10
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+2)) = (mask))            //TRISXSET + 0x08
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) = (mask))            //TRISXCLR + 0x04
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+8+1)) = (mask))          //LATXCLR  + 0x24
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+8+2)) = (mask))          //LATXSET + 0x28

#else
#error "Please define I/O register types here"
#endif


the line #include "pgmspace.h" call the attached file.

The program compiles and works, except that I don't have temperature readings.

I'm looking for understanding of this line:

Code: [Select]
#define IO_REG_ASM asm("r30")

This line is present for AVR, and since this is called in the communication functions, this might be the problem.

If anyone can explain this line, maybe I can move forward faster.

Help is appreciated, the developers of onewire doesn't seem to care about Due.

Regards,

Joao
www.aqualedsource.com

Arctic_Eddie

It looks like an assembly language reference to an I/O port register. Whatever it does in AVR is not likely the same in Due.

alvesjc

Picking this function:

Code: [Select]
uint8_t OneWire::reset(void)
{
IO_REG_TYPE mask = bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
uint8_t r;
uint8_t retries = 125;

noInterrupts();
DIRECT_MODE_INPUT(reg, mask);
interrupts();
// wait until the wire is high... just in case
do {
if (--retries == 0) return 0;
delayMicroseconds(2);
} while ( !DIRECT_READ(reg, mask));

noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
interrupts();
delayMicroseconds(500);
noInterrupts();
DIRECT_MODE_INPUT(reg, mask); // allow it to float
delayMicroseconds(80);
r = !DIRECT_READ(reg, mask);
interrupts();
delayMicroseconds(420);
return r;
}


this line

Code: [Select]
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;

Seems to be declaring 2 vars of IO_REG_TYPE (beeing uint32_t by macro defenition previously)

*reg
IO_REG_ASM

But I don't understand why the IO_REG_ASM.

Shouldn't this line be just:

Code: [Select]
volatile IO_REG_TYPE *reg = baseReg;

?
www.aqualedsource.com

Arctic_Eddie

Not able to help you much here. I did find this on Google. There are some hits using just the IO_REG_ASM search term. Keep in mind that the libraries are dealing with 8 bit AVR processors and we're trying to make them run with a Due.

http://arduino.cc/forum/index.php?topic=82859.0

Arctic_Eddie

I also found this item using the search term asm("r31"). It's a register number which has special pointer capabilities when used in pairs. This is AVR hardware specific so the Due is likely much different.

http://www.avr-asm-tutorial.net/avr_en/beginner/REGISTER.html



Arctic_Eddie

The register structure is entirely different. I'm putting mine on the shelf until this is all sorted out.

http://www.keil.com/dd/docs/datashts/arm/cortex_m3/r2p0/ddi0337g_cortex_m3_r2p0_trm.pdf

alvesjc

Humm, this might have something to do with interrupts usage...

I'll try to dig on that, thank you for the links.
www.aqualedsource.com

alvesjc

Hi again.

I've changed the defines to the code bellow:

Code: [Select]
#elif defined(__SAM3X8E__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         ((*(base)) & (mask))
#define DIRECT_MODE_INPUT(base, mask)   (base->PIO_OER &= ~mask)
#define DIRECT_MODE_OUTPUT(base, mask)  (base->PIO_OER |= mask)
#define DIRECT_WRITE_LOW(base, mask)    ((*(base)) &= ~mask)
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base)) |= mask)
#include "pgmspace.h"


Right now I'm stuck with:

Code: [Select]

#define DIRECT_MODE_INPUT(base, mask)   (base->PIO_OER &= ~mask)
#define DIRECT_MODE_OUTPUT(base, mask)  (base->PIO_OER |= mask)


The compiler complains that he doens't know member PIO_OER.

I'm looking in the files for this structures but I'm not finding them.

Anyone knows were these structures are?

The idea here, is to make the pin output, or input. If I recall right, this is done with OER.

I've previously used this registers in UTFT lib but in this format:

Code: [Select]

REG_PIOX_OER=0xXXXXX


The errors I'm getting from compiler:

"
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp: In member function 'uint8_t OneWire::reset()':
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp:128: error: request for member 'PIO_OER' in '* reg', which is of non-class type 'volatile long unsigned int'
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp:138: error: request for member 'PIO_OER' in '* reg', which is of non-class type 'volatile long unsigned int'
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp:142: error: request for member 'PIO_OER' in '* reg', which is of non-class type 'volatile long unsigned int'
"

Help appreciated. ;)
www.aqualedsource.com

jgmdavies

PIO_OER ("Output Enable Register") is used in several versions of file component_pio.h.  Look in the folders below:

    ... arduino-1.5.1r2\hardware\arduino\sam\system\CMSIS\Device\ATMEL

HTH,
Jim

alvesjc

Well, still no luck..

I've set all the registers in place same way has the other defines, but no go.

Code: [Select]

#elif defined(__SAM3X8E__)
#define PIN_TO_BASEREG(pin)             (&(digitalPinToPort(pin)->PIO_PER)) //to get Base PORT address
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+0x3c)) & mask) ? 1 : 0) /*(Pio Offset: 0x003C) Pin Data Status Register */
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+0x14)) & mask) /*(Pio Offset: 0x0014) Output Disable Register */
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+0x10)) & mask) /*(Pio Offset: 0x0010) Output Enable Register */
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+0x34)) & mask) /*(Pio Offset: 0x0034) Clear Output Data Register */
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+0x30)) & mask) /*(Pio Offset: 0x0030) Set Output Data Register */
#include "pgmspace.h"


By the way, in the line

#define DIRECT_READ(base, mask)         (((*(base+0x3c)) & mask) ? 1 : 0)   /*(Pio Offset: 0x003C) Pin Data Status Register */

what is the meaning of

Code: [Select]
? 1 : 0

?
www.aqualedsource.com

Go Up