grblHAL / SAM3X8E

grblHAL driver for Atmel SAM3X8E (Arduino Due)
Other
12 stars 11 forks source link

Compile error for GrblHAL SAM3X38E on Arduino DUE #11

Closed ozzyman closed 2 years ago

ozzyman commented 2 years ago

I have to confess that I am a complete bumblefuck when it comes to C code, but I can't get the SAM3X38 driver to compile. It fails with the following error messages:

/home/tony/snap/arduino/current/Arduino/libraries/grblHAL_Due/src/driver.c: In function 'driver_init': /home/tony/snap/arduino/current/Arduino/libraries/grblHAL_Due/src/driver.c:1663:9: error: 'i' undeclared (first use in this function) for(i = 0 ; i < sizeof(inputpin) / sizeof(input_signal_t); i++) { ^ /home/tony/snap/arduino/current/Arduino/libraries/grblHAL_Due/src/driver.c:1663:9: note: each undeclared identifier is reported only once for each function it appears in Multiple libraries were found for "grblHAL_Due.h" Used: /home/tony/snap/arduino/current/Arduino/libraries/grblHAL_Due Not used: /home/tony/snap/arduino/current/Arduino/libraries/src exit status 1 Error compiling for board Arduino Due (Programming Port).

There are some oddities: The first is that the code snippet in the error does not appear at line 1663, but does appear in several other places. It also looks like the index variable i IS declared as uint32_t a few lines above.

I have tried removing and re-adding the libraries, and compiing for the native USB port. Same problem.

ozzyman commented 2 years ago

OK, I have surprised myself, and located the problem. Index variable i does not get declared in the driver_init function if the MPG mode pin is not defined.

By changing:

ifdef MPG_MODE_PIN

// Pull down MPG mode pin until startup is completed.
**uint32_t i = 0;**
while(mpg_pin == NULL) {
    if(inputpin[i].id == Input_ModeSelect) {
        mpg_pin = &inputpin[i];
        mpg_pin->bit = 1U << mpg_pin->pin;
        PIO_Mode(mpg_pin->port, mpg_pin->bit, OUTPUT);
        BITBAND_PERI(MPG_MODE_PORT->PIO_ODSR, MPG_MODE_PIN) = 0;
    }
    i++;
}

endif

to: uint32_t i = 0;

ifdef MPG_MODE_PIN

// Pull down MPG mode pin until startup is completed.
while(mpg_pin == NULL) {
    if(inputpin[i].id == Input_ModeSelect) {
        mpg_pin = &inputpin[i];
        mpg_pin->bit = 1U << mpg_pin->pin;
        PIO_Mode(mpg_pin->port, mpg_pin->bit, OUTPUT);
        BITBAND_PERI(MPG_MODE_PORT->PIO_ODSR, MPG_MODE_PIN) = 0;
    }
    i++;
}

endif

I get it to compile.

terjeio commented 2 years ago

I fixed this a few days ago but forgot to commit it as I have been busy with other issues. Will commit the fix later today.

ozzyman commented 2 years ago

Thanks, Terje.

I'm working up a machine map for RAMPS1.4 as well.