building Marlin 3D printer in Atmel Studio?

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been unsuccessful looking for a reference describing how to build the Marlin 3D printer firmware in Atmel Studio.  It seems to be very deeply Arduino-based, and the makefile seems to be Linux-oriented.  I'm running Studio v. 7 and have a JTAGICE MKII to program a controller board... but I have no idea how to take this mess of source code, some from the github https://github.com/MarlinFirmware/Marlin and some apparently from various Arduino sources and build a working firmware.  Can anyone suggest a starting point?

 

In the meantime I've created a solution in Atmel Studio and am adding .h and .cpp files one at a time, but it's tough slogging.  The Marlin source code doesn't even have a main()!  So I'm open to any advice.  I just want to build it and flash a controller board for some testing.

 

 

This topic has a solution.
Last Edited: Sat. Jan 7, 2017 - 10:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you just want to build an existing Arduino project, Visual Micro for Atmel Studio is probably the way to go:

 

http://www.visualmicro.com/page/...

 

Rewriting the whole thing without Arduino libraries would be more difficult, although it does not seem to depend on Arduino libraries as much as some other/most Arduino projects. There is indeed no main() function, but look into Marlin_main.cpp - you will find typical Arduino seetup() and loop() functions, which are entry points for the code and might be a good start for you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for replying, though I don't think this is totally an Arduino project, as you mentioned.  I already put the code from loop() into main() and am calling the code from setup.  My difficulties are around the countless #include dependencies.  I know I don't need many of them from their names alone, but right now am just trying to get a full-code compile.  The majority of the application is in C++ but many of the included library source is in C.  I'm comfortable with both, but ignorant of Arduino (would rather just flash a chip with my JTAGICE MKII).  Then there are the verbose routines in digital_write.c, which I cannot understand why they're so complicated... again the divide between microcontroller programming in C versus "sketches."  But it is a very big project -- was hoping to just press F7 and get it to build.  laugh

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Marlin is an Arduino project, there is no doubt about that. You should be able to import it into Studio as an Arduino project, although I have never tried. I build Marlin using Eclipse with the Jantje Arduino plugin.

 

If you build Marlin outside of Arduino IDE, you will need to provide the same compiler flags Arduino IDE does, as well as the various Arduino core include files.

Bob.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob, thanks, the more I look at it the more I agree, no doubt it's an Arduino project.  I have never imported an Arduino project into Studio.  In the meantime, I just ordered an Arduino to hopefully at least compile to it and play with and test it on the scope.  Maybe I bit off too much of a task after a long time away from Atmel stuff in general.  I did have to add one compiler directive I think C++11 for a particular style of constructor.  That made a lot of errors go away.  The Arduino core #includes are the sticking point - they don't appear to be part of the Marlin project.  It's as though the developers of this project assume it's being built out of the Arduino environment and that they all are available.  I think I'll give that a try instead of insisting on building it in Studio.  Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't need an Arduino board in order to compile and use the code! There's plenty written on how to find the generated hex file that Arduino 'hides'. Then you use whatever tool you like to burn it into the chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have successfully imported Marlin into Atmel Studio 7 and also been able to use Atmel ICE programmer/debugger to walk through execution of the code and play with hardware, see registers, etc.  I have compiled and uploaded code for Arduino Mega/RAMPS 1.4 & Prusa i3.  I do have UM2E+ as well, which would only take a few configuration changes of the code to do that as well.

Last Edited: Thu. Oct 5, 2017 - 05:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Me too have successfully compiled Marlin 1.1.9 in Atmel Studio 6.2. Because I just don't want to use Arduino IDE. Here is what you need to do (for RAMPS-alike boards):

1. Create a new "C++ executable" project, choose atmega2560 microcontroller.

2. Create a new folder called "Marlin" in your Solution Explorer. Copy Marlin folder into your newly auto-created Marlin folder (where main cpp file and Debug folder is located)

3. Same way create a new folder called "arduino". Copy arduino folder into your project folder.

4. Include paths "..\Marlin" and "..\arduino" into your C++ compiler parameters.

Now you can try to compile all this and will get hundreds of errors. Time to fix them.

5. First of all add "-std=c++11" into your C++ compiler parameters to remove most of language-related errors.

6. Remove from Solution Explorer and delete your main project cpp file, where you have duplicate of main() function. arduino\main.cpp have main() function already.

7. Rightclick on Marlin folder in Solution Explorer, choose "Add Existing Item", select all .c and .cpp files (not h-files) and add them. Same way add .c and .cpp files of arduino folder. This will remove "undefiled reference" linker errors.

8. Remove duplicate definitions of interrupt vectors ISR(SOME_VECTOR) by removing of all c/cpp files from arduino folder branch in Solution Explorer that contains interrupt vectors definitions (HardwareSerial*.cpp, WInterrupts.c, SoftwareSerial.cpp, Tone.cpp, Arduino-usbserial.c, wiring.c).

9. #include "Marlin_main.cpp" in the beginning of arduino\main.cpp file, to provide loop() and setup() functions.

10. Remove Marlin\Marlin_main.cpp from Solution Explorer, because it is already included in arduino\main.cpp

11. Add F_CPU define at the beginning of some most importanf files (main.cpp, Marlin_main.cpp, Marlin.h, Arduino.h etc.), to remove F_CPU not defined warning inside delay.h like this:

#ifndef F_CPU
#define F_CPU 16000000UL
#endif

12. Some variable definitions, separated by comma might need a manual fix, like this:

const uint16_t table_address = blah-blah;
const uint16_t gain = blah-blah;

13. Turn off -fpack-struct checkbox in compiler optimization options, because compiler warns you that structures packing is already handled inside Marlin code by "pragma pack" compiler definitions.

 

Finally you will get a clean compilation with no errors and no warnings. Hope this will help someone.

And by the way, you most likely to have a bootoader inside your 3D-printer board, so use External Tools and AVRDude to upload your binaries into microcontroller.

Good luck!

Last Edited: Sat. Nov 9, 2019 - 06:36 PM