Build and upload

To build and upload a project,

  • Select the target All or Fast.

  • Press the button Run or press Cmd+B.

The sketch is going to be built and linked, and the resulting executable uploaded to the board and open.

At the end, the Terminal application opens a serial console.

Customise the serial port

The serial port is used for the upload of the sketches and for the console.

By default, embedXcode uses the names of the serial port defined in the board configuration file and set the speed to 9600 for the serial console.

Both parameters can be changed.

Change the upload serial port

Each platform has a different implementation of the USB port naming. Arduino uses the physical USB port of the Mac while each LaunchPad has a unique port name.

Now, two issues may appear:

  • Some USB hubs change the USB port names.

  • When Mac goes to sleep and then wakes up, USB ports are enumerated with an different name.

In either case, the following error message is displayed when trying to upload.

As a solution,

  • Open the main Makefile.

  • Uncomment the line BOARD_PORT by removing the leading #.

#BOARD_PORT = /dev/tty.usbmodem1* 
BOARD_PORT = /dev/tty.usbmodem1* 
  • Edit the line and either specify a more general name.
BOARD_PORT = /dev/tty.usbmodem*. 
  • Or enter the specific USB port name of the board.
BOARD_PORT = /dev/tty.usbmodem1403

To know the USB port name of the active board, proceed as follow:

  • Launch a Terminal window

  • Plug the board on the USB port.

  • Run the following command and note the name of the port.

$ ls /dev/tty.usb*
/dev/tty.usbmodem1403

Change the serial console speed

By default, the speed of the serial console is 9600. To change the speed,

  • Open the main Makefile.

  • Uncomment the line SERIAL_BAUDRATE and set the desired speed.

# SERIAL_BAUDRATE for the serial console, 9600 by default
# Uncomment and specify another speed
#
SERIAL_BAUDRATE = 19200

Change the optimisation options

By default, the optimisation options are set to standard. To change them,

  • Open the main Makefile.

  • Uncomment the line OPTIMISATION and set the desired options.

# OPTIMISATION for the optimisation and debugger levels
# Uncomment and specify another options
#
OPTIMISATION    = -O0 -g3

Upload when multiple boards are connected

This section requires the embedXcode+ edition.

Select among two Arduino connected boards

In case two similar boards are connected, for example two Arduino boards, a windows lists the connections and ask to select one:

The first port is the default option.

  • To select the default port, press Enter, click on the button 1 or wait 10 seconds.

  • To select the second port, click on the button 2.

The following message is added to the Log navigator:

==== 2 ports available ====
1: /dev/tty.usbmodem1411
2: /dev/tty.usbmodem1421
==== /dev/tty.usbmodem1411 port selected ====

This feature works with the Arduino boards and the boards using a serial through USB connection.

A similar option is available for the LaunchPad boards using an XDS110 programmer-debugger.

Other boards may not provide this feature, as they use a different protocol that combines different services under a single USB port.

Select among multiple boards connected through serial

As an alternative for the previous case and for other boards as well, the following procedure is valid as long as each board has a unique name for the serial port which is used to upload the executable.

  • Use the exact name of the serial through USB port the board is connected to.

In the example below, let's consider two projects: one for the Arduino Uno board and another for the Arduino Mega board.

  • Connect the first board, here the Arduino Uno board.

  • Open a Terminal window and launch ls /dev/tty.*.

% ls /dev/tty.*
/dev/tty.usbmodem1411
  • Note the serial port for the first board, here /dev/tty.usbmodem1411 for the Arduino Uno board.

  • Connect the second board, here the Arduino Mega board.

  • Perform the same ls /dev/tty.*.

% ls /dev/tty.*
/dev/tty.usbmodem1411    /dev/tty.usbmodem1421
  • Note the serial port for the second board, here /dev/tty.usbmodem1421 for the Arduino Mega board.

In the example, the Arduino Uno is connected to port /dev/tty.usbmodem1411 and the Arduino Mega to port /dev/tty.usbmodem1421.

  • Create two projects, one for the Arduino Uno board and another for the Arduino Mega board.

On the project for the Arduino Uno board,

  • Edit the Arduino Uno.xcconfig board configuration file,

  • Set BOARD_PORT to /dev/tty.usbmodem1411,

BOARD_PORT = /dev/tty.usbmodem1411
  • Run the All or Fast target.

On the project for the Arduino Mega board,

  • Edit the Arduino Mega 2560.xcconfig board configuration file,

  • Set BOARD_PORT to /dev/tty.usbmodem1421.

BOARD_PORT = /dev/tty.usbmodem1421
  • Run the All or Fast target for each project.

This feature works with the Arduino boards and other boards as well, as long as each board has a unique name for the serial port which is used to upload the executable.

Select among multiple boards connected through XDS110

In case multiple boards are connected through XDS110 and the XDS110 has been selected as uploader, a window lists the serial numbers of the boards and ask to select one.

On the example below, two CC1352 LaunchPad boards are connected.

  • Select one serial number and click on OK.

This feature works with selected LaunchPad boards with an XDS110 programmer-debugger, as long as each board has a unique serial number which is used identification when uploading the executable.

For more information,

Upload to boards with multiple USB profiles

Some boards use the USB connection to simulate a keyboard. For example, the KeyboardMessage example for the Arduino Leonardo board sends key-strokes as a keyboard.

The Arduino Leonardo board exposes two USB ports: one when connected as a serial device, and another when operating as a keyboard.

  • Connect the Arduino Leonardo board.

  • Open a Terminal window and launch ls /dev/tty.*.

  • Press the Reset button on the Arduino Leonardo board and keep running ls /dev/tty.*.

% ls /dev/tty.*
/dev/tty.usbmodem14101 
% ls /dev/tty.*
/dev/tty.usbmodemHIDPC1

The two USB ports exposed by Arduino Leonardo board are /dev/tty.usbmodem14101 when connected as a serial device, and /dev/tty.usbmodemHIDPC1 when operating as a keyboard. HID stands for Human Interface Device.

On the project for the Arduino Leonardo board,

  • Edit the Arduino Leonardo.xcconfig board configuration file,

  • Set BOARD_PORT to /dev/tty.usbmodem14101 /dev/tty.usbmodemHIDPC1.

BOARD_PORT = /dev/tty.usbmodem14101 /dev/tty.usbmodemHIDPC1
  • Run the All or Fast target.

The board will be reset on the /dev/tty.usbmodemHIDPC1 HID port and the executable uploaded through the /dev/tty.usbmodem14101 serial port.

This procedure has been tested on the Arduino Leonardo board.

Display the Report Navigator

The Report Navigator provides information about the compilation and the size of the final binary file.

  • To display the Report Navigator, call the menu View > Navigators > Show Report Navigator, or press Cmd+8 or click on the rightmost icon.

The Report Navigator provides the detail of the whole process.

Once compilation is completed, the Report Navigator displays the total size of the sketch on the flash memory and an estimation of the RAM usage.

It also provides the elapsed time spent for building and linking.

---- Size ----
Binary sketch size:  880 bytes (of a 16384 byte maximum)
Estimated SRAM used: 22 bytes (of a 512 byte maximum)
Elapsed time: 0.3 s
==== Make done ====

The embedXcode+ edition provides additional information with remaining free memory and percentages.

---- Size ----
Estimated Flash:  880 bytes used (5.3% of 16384 maximum), 15504 bytes free (94.7%)
Estimated SRAM:   22 bytes used (4.2% of 512 maximum), 490 bytes free (95.8%)
Elapsed time: 1.1 s
==== Make done ==== 

Display the serial console on a Terminal window

If the target All or Fast is selected, once the sketch is built, linked and uploaded to the board, the Terminal application opens a serial console with the screen utility.

To launch the serial console in a Terminal window,

  • Select the target Serial.

  • Click on Run.

macOS may ask for permission.

  • Click on OK.

The serial console is bi-directional: it displays data sent by the board on the Terminal window, and sends data typed in the Terminal window to the board.

For more information on the screen utility,

To close the serial connection,

  • Use the Ctrl+A Ctrl+K key sequence.

  • Then press Y to confirm.

Otherwise, the USB port is no longer listed. This is a bug on the USD drivers with macOS .

For the moment, the serial console isn't displayed on the debug pane in the main Xcode window.

On the embedXcode+ edition, an option allows not to open the serial console after the upload.