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

How to Compile for Arduino Mega and Ramps 1.4 #157

Open
Technican opened this issue Apr 10, 2022 · 5 comments
Open

How to Compile for Arduino Mega and Ramps 1.4 #157

Technican opened this issue Apr 10, 2022 · 5 comments

Comments

@Technican
Copy link

I have tried to compile it for the Arduino Mega 2560 and Ramps 1.4 Board.
I changed the in the Config.h:

#include "grbl.h" // For Arduino IDE compatibility.

// Define CPU pin map and default settings.
// NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only
// one configuration file by placing their specific defaults and pin map at the bottom of this file.
// If doing so, simply comment out these two defines and see instructions below.
#define DEFAULTS_GENERIC
#define CPU_MAP_2560_INITIAL

// To use with RAMPS 1.4 Board, comment out the above defines and uncomment the next two defines
//#define DEFAULTS_RAMPS_BOARD
#define CPU_MAP_2560_RAMPS_BOARD

Is that correct?
After that , with make in the Terminal:

avr-gcc -Wall -Os -DF_CPU=16000000L -mmcu=atmega2560 -I. -ffunction-sections -flto -MMD -MP -c grbl/main.c -o build/main.o
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:160: warning: "STEP_DDR" redefined
160 | #define STEP_DDR(i) DDR(STEP_PORT##i)
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:36: note: this is the location of the previous definition
36 | #define STEP_DDR DDRA
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:162: warning: "STEP_PORT" redefined
162 | #define STEP_PORT(i) _STEP_PORT(i)
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:37: note: this is the location of the previous definition
37 | #define STEP_PORT PORTA
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:163: warning: "STEP_PIN" redefined
163 | #define STEP_PIN(i) PIN(STEP_PORT##i)
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:38: note: this is the location of the previous definition
38 | #define STEP_PIN PINA
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:174: warning: "DIRECTION_DDR" redefined
174 | #define DIRECTION_DDR(i) DDR(DIRECTION_PORT##i)
|
In file included from grbl/grbl.h:47,
from grbl/main.c:22:
grbl/cpu_map.h:45: note: this is the location of the previous definition
45 | #define DIRECTION_DDR DDRC
|

and so on. Any ideas?

@fra589
Copy link

fra589 commented Apr 10, 2022

Hi @Technican,

Your config.h update is not correct. To use an Arduino Mega with RAMPS 1.6, you need to comment the two first definitions and uncomment the two other like this:

// Define CPU pin map and default settings.
// NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only
// one configuration file by placing their specific defaults and pin map at the bottom of this file.
// If doing so, simply comment out these two defines and see instructions below.
//#define DEFAULTS_GENERIC
//#define CPU_MAP_2560_INITIAL

// To use with RAMPS 1.4 Board, comment out the above defines and uncomment the next two defines
#define DEFAULTS_RAMPS_BOARD
#define CPU_MAP_2560_RAMPS_BOARD

Then, if you have other compile error message, please, tell us what is your system, Windows or Linux, which version, which compiler and version, and any other information which can help us to help you...

@++;
Gauthier.

@Technican
Copy link
Author

Technican commented Apr 10, 2022 via email

@fra589
Copy link

fra589 commented Apr 10, 2022

I work under Linux Debian, and the current version in Debian stable is GCC 5.4.0.
Under this version, I don't have those warning. But GCC version 9 is more finicky and tell many more warning.
Regarding the source code, I don't think this will be a problem, just a missing cast between integer and boolean and should work fine.
The warning is in the code that saves and restores Grbl settings to EEPROM. If Grbl settings save and return correctly after powering down, it's working. :-)
@++;
Gauthier.

@drf5n
Copy link

drf5n commented Apr 11, 2022

grbl/eeprom.c: In function 'memcpy_to_eeprom_with_checksum': grbl/eeprom.c:133:26: warning: '<<' in boolean context, did you mean '' ? [-Wint-in-bool-context] 133 | checksum = (checksum << 1) || (checksum >> 7); | ~~~~~~~~~~^~~~~ grbl/eeprom.c: In function 'memcpy_from_eeprom_with_checksum': grbl/eeprom.c:144:26: warning: '<<' in boolean context, did you mean '' ? [-Wint-in-bool-context] 144 | checksum = (checksum << 1) || (checksum >> 7); | ~~~~~~~~~~^~~~~

That looks like it was a typo -- it squashes the checksum down to a single bit of information, when it looks like it intended to roll it right one bit, so the final checksum ends up either zero or one larger than the last character in the data:

grbl-Mega/grbl/eeprom.c

Lines 130 to 149 in df87b36

void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) {
unsigned char checksum = 0;
for(; size > 0; size--) {
checksum = (checksum << 1) || (checksum >> 7);
checksum += *source;
eeprom_put_char(destination++, *(source++));
}
eeprom_put_char(destination, checksum);
}
int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) {
unsigned char data, checksum = 0;
for(; size > 0; size--) {
data = eeprom_get_char(source++);
checksum = (checksum << 1) || (checksum >> 7);
checksum += data;
*(destination++) = data;
}
return(checksum == eeprom_get_char(source));
}

Maybe it was supposed to be

checksum = (checksum << 1) | (checksum >> 7);

That's what they use in grblHAL:

https://github.com/grblHAL/core/blob/3a84b58d301f04279268b4ef1045fd6bc0961be5/nuts_bolts.c#L267-L278

@fra589
Copy link

fra589 commented Apr 11, 2022

Very old subject... Already discussed in 2017 here :
grbl#1249 (comment)
with the choice not to correct it
@++;
Gauthier.

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

3 participants