francoiscampbell / CLionArduinoPlugin

A plugin for CLion that enables arduino-cmake integration.
155 stars 42 forks source link

Unable to set mega2560 (or mega1280) #9

Open ronny332 opened 8 years ago

ronny332 commented 8 years ago

Hi,

it seems there is a kind of bug if you try to set the board type to a Atmega2560 or Atmega1280. I've searched the whole evening for the reason, but the problem seems to be located at the cmake parser file, which tries to separate the different board types. It is started from the Arduino.cmake file by "include(CMakeParseArguments)".

My boards.txt has the type "mega" for a board with Atmega1280 AND Atmega2560. It is impossible to make a real decision for one of the types and at least the mcu values is blank afterwards (what results in a missing compiler flag: -mmcu).

The issue can easily be validated, just run print_board_settings(mega) from your CMakeLists.txt. The .mcu value is missing. print_board_settings(uno) shows it in the right way.

The type megaADK for instance is exclusively an Atmega2560, the mcu value is present and the compilation works out of the box.

For now I can bypass the issue by inserting "set(mega.build.mcu atmega2560)" to my CMakeLists.txt, but this is of cause nothing more than a bad hack.

As final result for this evening, these lines are working with my 2560 for compiling and uploading:

cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
set(PROJECT_NAME avr_test)
project(${PROJECT_NAME})
set(${CMAKE_PROJECT_NAME}_BOARD mega)
set(${CMAKE_PROJECT_NAME}_PORT /dev/tty.usbmodem142141)
set(${CMAKE_PROJECT_NAME}_SKETCH avr_test.ino)
set(mega.build.mcu atmega2560)
set(mega.upload.protocol wiring)
set(mega.upload.speed 115200)
generate_arduino_firmware(${CMAKE_PROJECT_NAME})
jgenender commented 8 years ago

Yep... I get it too for the nano (atmega328p). The only fix (after setting the _BOARD, _PORT) is the following:

set(nano.build.mcu atmega328p)
set(nano.upload.protocol arduino)
set(nano.upload.speed 57600)

This is definitely a bug and a hack to work around it.

francoiscampbell commented 8 years ago

Sorry for the absence, I've been super busy lately. This is an issue with the arduino-cmake project I use in the plugin. That project is super fragmented right now and hasn't been updated in over a year, so I've got my own fork now to try to collect all the fixes and maybe get development going again. Anyways, as a workaround, I use set(${CMAKE_PROJECT_NAME}_BOARD megaADK) personally and it works fine for my mega2560.

mucamaca commented 8 years ago

With this code:

cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
set(PROJECT_NAME Arduino_C_things)
project(${PROJECT_NAME})
set(${CMAKE_PROJECT_NAME}_BOARD mega)
set(${CMAKE_PROJECT_NAME}_PORT COM8)
set(${CMAKE_PROJECT_NAME}_SKETCH Arduino_C_things.ino)
set(mega.build.mcu atmega2560)
set(mega.upload.protocol wiring)
set(mega.upload.speed 115200)
generate_arduino_firmware(${CMAKE_PROJECT_NAME})

The code compiles and downloads on original Arduino Mega, but after that, code is not executed on Arduino. Tested it with simple Serial.println() and nothing appeared in serial monitor. Also tried flashing the onboard LED with no result. Tried setting to megaADK board but results were the same.

P.S. I'm on Windows