Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Problem #10

Closed
johnvanzijl opened this issue Dec 24, 2013 · 6 comments
Closed

Compile Problem #10

johnvanzijl opened this issue Dec 24, 2013 · 6 comments

Comments

@johnvanzijl
Copy link

Hi Guys,

I try to recompile the bootloader for the mega2560 because I want to adapt it for a mega2561 and a w5500. But as you can see below I get an error.

The standard libs from the arduino package do not have the memcpy_PF in pgmspace.h.

the culprit is in tftp.c:

if (FLASHEND > 0x10000)

        memcpy_PF(txBuffer, PROGMEM_OFFSET + (uint32_t)(uint16_t)tftp_unknown_error_packet, packetLength);

else

        memcpy_P(txBuffer, tftp_unknown_error_packet, packetLength);

endif

I already tried Arduino 1.05 and arduino 1.55, so I was wondering how did you compile the 2560 bootloaders?

cheers,

John

../../../../tools/avr/bin/avr-gcc -g -Wall -Wextra -Wstrict-prototypes -Os -fno-
inline-small-functions -fno-split-wide-types -mno-interrupts -mrelax -funsigned-
char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -std=gnu9
9 -mmcu=atmega2560 -DF_CPU=16000000L '-DDEBUG_MAIN=1' '-DDEBUG_NET=1' '-DDEBUG
_TFTP=1' '-DDEBUG_VALD=1' '-DBAUD_RATE=115200' -Wl,--section-start=.text=0x3e000
-Wl,--relax -Wl,--gc-sections -o ariadne_debug2560.elf main.o spi.o w5100.o tft
p.o validate.o debug.o watchdog.o serial.o util.o announce.o optiboot.o stk500bo
ot.o
tftp.o: In function tftpPoll': C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\ariadne/tftp.c:4 79: undefined reference tomemcpy_PF'
tftp.o: In function sendResponse': C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\ariadne/tftp.c:3 56: undefined reference tomemcpy_PF'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\ariadne/tftp.c:3
58: undefined reference to `memcpy_PF'
make: *** [ariadne_debug2560.elf] Error 1
rm watchdog.o w5100.o tftp.o optiboot.o spi.o stk500boot.o serial.o validate.o a
nnounce.o debug.o main.o util.o

@loathingKernel
Copy link

Arduino provided avr toolchain is lagging behind quite a few versions. To compile, i am using the latest avr toolchain as it is provided by my package manager.

I haven't tried to compile on windows but on of these might be useful:
http://winavr.sourceforge.net/
http://www.atmel.com/tools/atmelstudio.aspx

You will need to edit the Makefile to change the paths but that should be quite straight forward.

Good luck with your project and I am eager to see the results.

@johnvanzijl
Copy link
Author

Hi Stelios,

Thanks for the help, I can compile the bootloader now. I did have some
trouble downloading it into the Mega2560 Board. Finanly I discovered
that the Bootloader update function simply doesn't work on my win7 64x
with the mkII ISP. Using a separate AVRDUDE solved that problem. However
I do need some other help.

it seems that the function to set the IP and MAC has a bit of a problem.

Here the source of w5100.c that I changed a bit to debug. I simply print
the settings before and after the eprom reading. I seems that I cannot
read the registerBuffer at all!! I can boot, I can send a sketch
(serial) everything else in order. Any Ideas???

uint8_t registerBuffer[REGISTER_BLOCK_SIZE] = {
0x80, // MR Mode - reset device

 // EEPROM block starts here
 GW_ADDR,      // GWR Gateway IP Address Register
 SUB_MASK,  // SUBR Subnet Mask Register
 MAC_ADDR,     // SHAR Source Hardware Address Register
 IP_ADDR,      // SIPR Source IP Address Register
 // EEPROM block ends here

 0, 0,         // Reserved locations
 0,            // IR Interrupt Register
 0,            // IMR Interrupt Mask Register
 0x07, 0xd0,   // RTR Retry Time-value Register
 0x80,         // RCR Retry Count Register
 0x55,         // RMSR Rx Memory Size Register, 2K per socket
 0x55          // TMSR Tx Memory Size Register, 2K per socket

};

void netInit(void)
{
uint8_t i;

     DBG_NET(
     tracePGMlnNet(mDebugNet_ADDR);
     for(i = 15; i < 19; i++) {
         tracenet(registerBuffer[i]);
         if(i != 18) putch(0x2E);
     }
     tracePGMlnNet(mDebugNet_SUBN);
     for(i = 5; i < 9; i++) {
         tracenet(registerBuffer[i]);
         if(i != 8) putch(0x2E);
     }
     tracePGMlnNet(mDebugNet_GW);
     for(i = 1; i < 5; i++) {
         tracenet(registerBuffer[i]);
         if(i != 4) putch(0x2E);
     }
     tracePGMlnNet(mDebugNet_MAC);
     for(i = 9; i < 15; i++) {
         tracenet(registerBuffer[i]);
         if(i != 14) putch(0x2E);
     }
 )

 /* Pull in altered network settings, if available,
  * from AVR EEPROM (if signature bytes are set) */
 if((eeprom_read_byte(EEPROM_SIG_1) == EEPROM_SIG_1_VALUE)
     && (eeprom_read_byte(EEPROM_SIG_2) == EEPROM_SIG_2_VALUE)) {

     for(i = 0; i < EEPROM_SETTINGS_SIZE; i++)
         registerBuffer[i + 1] = eeprom_read_byte(EEPROM_DATA + i);

     DBG_NET(tracePGMlnNet(mDebugNet_EEPROM);)

 } DBG_NET(
     else tracePGMlnNet(mDebugNet_BUILTIN);
 )


 DBG_NET(
     tracePGMlnNet(mDebugNet_ADDR);
     for(i = 15; i < 19; i++) {
         tracenet(registerBuffer[i]);
         if(i != 18) putch(0x2E);
     }
     tracePGMlnNet(mDebugNet_SUBN);
     for(i = 5; i < 9; i++) {
         tracenet(registerBuffer[i]);
         if(i != 8) putch(0x2E);
     }
     tracePGMlnNet(mDebugNet_GW);
     for(i = 1; i < 5; i++) {
         tracenet(registerBuffer[i]);
         if(i != 4) putch(0x2E);
     }
     tracePGMlnNet(mDebugNet_MAC);
     for(i = 9; i < 15; i++) {
         tracenet(registerBuffer[i]);
         if(i != 14) putch(0x2E);
     }
 )

Here the output:

Main: Ariadne for Arduino Mega2560, Version 0.5
Main: Init spi comm
Spi: SPI init done
Main: Init network layer
Net: Address: 0xFF.0xFF.0xFF.0xFF
Net: Subnet: 0xFF.0xFF.0xFF.0xFF
Net: Gateway: 0xFF.0xFF.0xFF.0xFF
Net: MAC: 0xFF.0xFF.0xFF.0xFF.0xFF.0xFF
Net: Built-in settings
Net: Address: 0xFF.0xFF.0xFF.0xFF
Net: Subnet: 0xFF.0xFF.0xFF.0xFF
Net: Gateway: 0xFF.0xFF.0xFF.0xFF
Net: MAC: 0xFF.0xFF.0xFF.0xFF.0xFF.0xFF
Spi: spiWriteReg: 0x0000, 0x00FF
Spi: spiWriteReg: 0x0001, 0x00FF
Spi: spiWriteReg: 0x0002, 0x00FF
Spi: spiWriteReg: 0x0003, 0x00FF
Spi: spiWriteReg: 0x0004, 0x00FF
Spi: spiWriteReg: 0x0005, 0x00FF

cheers, John

Arduino provided avr toolchain is lagging behind quite a few versions.
To compile, i am using the latest avr toolchain as it is provided by
my package manager.

I haven't tried to compile on windows but on of these might be useful:
http://winavr.sourceforge.net/
http://www.atmel.com/tools/atmelstudio.aspx

You will need to edit the Makefile to change the paths but that should
be quite straight forward.

Good luck with your project and I am eager to see the results.


Reply to this email directly or view it on GitHub
#10 (comment).

@johnvanzijl
Copy link
Author

Hi Stelios,

Looking for an error in my compiling settings I found something strange. I looked into the online ariadne_atmega2560.lst then I removed the asm lines and compared them with the w5100.c source code. It seems that there are differences. Looks to me that not all source codes are not up to date.

Would it be possible to update all sources?

cheers,

John

LST:

void netInit(void)
{
uint8_t i;

    /* Pull in altered network settings, if available,
     * from AVR EEPROM (if signature bytes are set) */

    if((eeprom_read_byte(EEPROM_SIG_1) == EEPROM_SIG_1_VALUE)
            && (eeprom_read_byte(EEPROM_SIG_2) == EEPROM_SIG_2_VALUE)) {
             for(i = 0; i < EEPROM_SETTINGS_SIZE; i++)
                    registerBuffer[i + 1] = eeprom_read_byte(EEPROM_DATA + i);

    /* Pull in altered network settings, if available,
     * from AVR EEPROM (if signature bytes are set) */
    if((eeprom_read_byte(EEPROM_SIG_1) == EEPROM_SIG_1_VALUE)
            && (eeprom_read_byte(EEPROM_SIG_2) == EEPROM_SIG_2_VALUE)) {

            for(i = 0; i < EEPROM_SETTINGS_SIZE; i++)
            }
    )

    /** Configure Wiznet chip. Network settings */
    for(i = 0; i < REGISTER_BLOCK_SIZE; i++)
            spiWriteReg(i, registerBuffer[i]);
                    if(i != 14) putch(0x2E);
            }
    )

    /** Configure Wiznet chip. Network settings */
    for(i = 0; i < REGISTER_BLOCK_SIZE; i++)
            spiWriteReg(i, registerBuffer[i]);

    DBG_NET(tracePGMlnNet(mDebugNet_DONE);)

}

Source:

void netInit(void)
{
uint8_t i;

/* Pull in altered network settings, if available,
 * from AVR EEPROM (if signature bytes are set) */
if((eeprom_read_byte(EEPROM_SIG_1) == EEPROM_SIG_1_VALUE)
    && (eeprom_read_byte(EEPROM_SIG_2) == EEPROM_SIG_2_VALUE)) {

    for(i = 0; i < EEPROM_SETTINGS_SIZE; i++)
        registerBuffer[i + 1] = eeprom_read_byte(EEPROM_DATA + i);

    DBG_NET(tracePGMlnNet(mDebugNet_EEPROM);)

} DBG_NET(
    else tracePGMlnNet(mDebugNet_BUILTIN);
)


DBG_NET(
    tracePGMlnNet(mDebugNet_ADDR);
    for(i = 15; i < 19; i++) {
        tracenet(registerBuffer[i]);
        if(i != 18) putch(0x2E);
    }
    tracePGMlnNet(mDebugNet_SUBN);
    for(i = 5; i < 9; i++) {
        tracenet(registerBuffer[i]);
        if(i != 8) putch(0x2E);
    }
    tracePGMlnNet(mDebugNet_GW);
    for(i = 1; i < 5; i++) {
        tracenet(registerBuffer[i]);
        if(i != 4) putch(0x2E);
    }
    tracePGMlnNet(mDebugNet_MAC);
    for(i = 9; i < 15; i++) {
        tracenet(registerBuffer[i]);
        if(i != 14) putch(0x2E);
    }
)

/** Configure Wiznet chip. Network settings */
for(i = 0; i < REGISTER_BLOCK_SIZE; i++)
    spiWriteReg(i, registerBuffer[i]);

DBG_NET(tracePGMlnNet(mDebugNet_DONE);)

}

@loathingKernel
Copy link

According to my local git repo, everything is up to date and both mega and origin/mega are in sync.

Nevertheless, your problem still seems strange to me, so I will look into it in the next few days. It might take some time for me to reply, though, due to holidays.

@johnvanzijl
Copy link
Author

Hi Stelios,

I found the problem, I replaced the AVR8 Gnu toolchain in arduino with the one from winavr 2010 (4.3.2) it seems that there are some bugs in there regarding mega2560 and upper memory.

After I removed all other source lines out of the bootloader I discovered the problem. Simply reading the registerBuffer gave almost random values, looks like the adressing wasn't right.

I installed ATMEL STUDIO 6 and copied the gnu toolchain (4.4.7) over the one in arduino and I can compile a bootloader now that I can access via TFTP and Serial.

Compiling a sketch with 4.4.7 gives some errors in WString.cpp but I can fix that.

Next I will change the software in tftp and w5100 to support a w5500.

Thanks for the help,

John

@loathingKernel
Copy link

I am reopening this one since I want some more information on your issue. There have been known problems with upper program memory. Even in my current version of avr-gcc (4.8.2) i needed some workarounds for *_PF functions to be able to access progmem strings in the bootloader section of the atmega2560, which is at the end of the program memory.

The thing I find weird is that the issue is with registerBuffer, in which case the initial values are not being read by using the pgmspace.h functions but they are hardcoded in the initialization of the array. Considering that, I believe it has to do with erroneous compilation due to gcc version being old. I still have no idea what might be causing it.

loathingKernel added a commit that referenced this issue Jun 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants