Skip to content

Commit d738cac

Browse files
authored
Merge pull request #508 from fuzzyTew/robotis-opencm
Add makefile for Robotis OpenCM
2 parents ba96840 + 5bcb64a commit d738cac

File tree

11 files changed

+406
-6
lines changed

11 files changed

+406
-6
lines changed

Arduino.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
# Original Arduino adaptation by mellis, eighthave, oli.keller
2121
#
22-
# Current version: 1.5.2
22+
# Current version: 1.6.0
2323
#
2424
# Refer to HISTORY.md file for complete history of changes
2525
#

HISTORY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ The following is the rough list of changes that went into different versions.
55
I tried to give credit whenever possible. If I have missed anyone, kindly add it to the list.
66

77
### In Development
8+
- TBC
9+
10+
### 1.6.0 (2017-07-11)
811
- Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278)
912
- Fix: Do not include the Arduino header when calling generate_assembly on .cpp files. (https://github.com/Batchyx)
1013
- Fix: Auto-detect F_CPU on Teensy from boards.txt (https://github.com/DaWelter)
1114
- Fix: params typo in PuTTY section (issue #487) (https://github.com/ericdand)
1215
- Fix: Fixed sed expression to properly format show_submenu (issue #488) (https://github.com/cbosdo)
13-
- New: Add support for good old cu as monitor command (issue #492) (https://github.com/mwm)
1416
- Tweak: Removed tilde from documentation (issue #497). (https://github.com/sej7278)
17+
- New: Add support for good old cu as monitor command (issue #492) (https://github.com/mwm)
1518
- New: Add a documentation how to setup Makefile for 3rd party boards (issue #499). (https://github.com/MilanV)
19+
- New: Add support for Robotis OpenCM boards
1620

1721
### 1.5.2 (2017-01-11)
1822

OpenCM.mk

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
########################################################################
2+
#
3+
# Support for Robotis OpenCM boards
4+
#
5+
# http://en.robotis.com/index/product.php?cate_code=131010
6+
#
7+
# You must install the OpenCM IDE for this Makefile to work:
8+
#
9+
# http://support.robotis.com/en/software/robotis_opencm/robotis_opencm.htm
10+
#
11+
# Based on work that is copyright Jeremy Shaw, Sudar, Nicholas Zambetti,
12+
# David A. Mellis & Hernando Barragan.
13+
#
14+
# This file is free software; you can redistribute it and/or modify it
15+
# under the terms of the GNU Lesser General Public License as
16+
# published by the Free Software Foundation; either version 2.1 of the
17+
# License, or (at your option) any later version.
18+
#
19+
# Adapted from Teensy 3.x makefile which was adapted from Arduino 0011
20+
# Makefile by M J Oldfield
21+
#
22+
# Original Arduino adaptation by mellis, eighthave, oli.keller
23+
#
24+
########################################################################
25+
26+
ifndef ARDMK_DIR
27+
ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
28+
endif
29+
30+
# include Common.mk now we know where it is
31+
include $(ARDMK_DIR)/Common.mk
32+
33+
ARDUINO_DIR = $(OPENCMIDE_DIR)
34+
35+
ifndef ARDMK_VENDOR
36+
ARDMK_VENDOR = robotis
37+
endif
38+
39+
ifndef ARDUINO_CORE_PATH
40+
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/robotis/cores/robotis
41+
endif
42+
43+
ifndef BOARDS_TXT
44+
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/boards.txt
45+
endif
46+
47+
ifndef PARSE_OPENCM
48+
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
49+
PARSE_OPENCM = $(shell grep -v "^\#" "$(BOARDS_TXT)" | grep $(1).$(2) | cut -d = -f 2- )
50+
endif
51+
52+
ifndef F_CPU
53+
F_CPU := $(call PARSE_OPENCM,$(BOARD_TAG),build.f_cpu)
54+
endif
55+
56+
# if boards.txt gets modified, look there, else hard code it
57+
ARCHITECTURE = $(call PARSE_OPENCM,$(BOARD_TAG),build.architecture)
58+
ifeq ($(strip $(ARCHITECTURE)),)
59+
ARCHITECTURE = arm
60+
endif
61+
62+
AVR_TOOLS_DIR = $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/$(ARCHITECTURE))
63+
64+
# Robotis has moved the platform lib dir to their root folder
65+
ifndef ARDUINO_PLATFORM_LIB_PATH
66+
ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/libraries
67+
$(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR))
68+
endif
69+
70+
ifndef ARDUINO_HEADER
71+
ARDUINO_HEADER = wirish.h
72+
endif
73+
74+
########################################################################
75+
# command names
76+
77+
ifndef CC_NAME
78+
CC_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.gcc)
79+
ifndef CC_NAME
80+
CC_NAME := arm-none-eabi-gcc
81+
else
82+
$(call show_config_variable,CC_NAME,[COMPUTED])
83+
endif
84+
endif
85+
86+
ifndef CXX_NAME
87+
CXX_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.g++)
88+
ifndef CXX_NAME
89+
CXX_NAME := arm-none-eabi-g++
90+
else
91+
$(call show_config_variable,CXX_NAME,[COMPUTED])
92+
endif
93+
endif
94+
95+
ifndef AS_NAME
96+
AS_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.as)
97+
ifndef AS_NAME
98+
AS_NAME := arm-none-eabi-as
99+
else
100+
$(call show_config_variable,AS_NAME,[COMPUTED])
101+
endif
102+
endif
103+
104+
ifndef OBJDUMP_NAME
105+
OBJDUMP_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.objdump)
106+
ifndef OBJDUMP_NAME
107+
OBJDUMP_NAME := arm-none-eabi-objdump
108+
else
109+
$(call show_config_variable,OBJDUMP_NAME,[COMPUTED])
110+
endif
111+
endif
112+
113+
ifndef AR_NAME
114+
AR_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.ar)
115+
ifndef AR_NAME
116+
AR_NAME := arm-none-eabi-ar
117+
else
118+
$(call show_config_variable,AR_NAME,[COMPUTED])
119+
endif
120+
endif
121+
122+
ifndef SIZE_NAME
123+
SIZE_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.size)
124+
ifndef SIZE_NAME
125+
SIZE_NAME := arm-none-eabi-size
126+
else
127+
$(call show_config_variable,SIZE_NAME,[COMPUTED])
128+
endif
129+
endif
130+
131+
ifndef NM_NAME
132+
NM_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.nm)
133+
ifndef NM_NAME
134+
NM_NAME := arm-none-eabi-nm
135+
else
136+
$(call show_config_variable,NM_NAME,[COMPUTED])
137+
endif
138+
endif
139+
140+
ifndef OBJCOPY_NAME
141+
OBJCOPY_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.objcopy)
142+
ifndef OBJCOPY_NAME
143+
OBJCOPY_NAME := arm-none-eabi-objcopy
144+
else
145+
$(call show_config_variable,OBJCOPY_NAME,[COMPUTED])
146+
endif
147+
endif
148+
149+
# processor stuff
150+
ifndef MCU
151+
MCU := $(call PARSE_OPENCM,$(BOARD_TAG),build.family)
152+
endif
153+
154+
ifndef MCU_FLAG_NAME
155+
MCU_FLAG_NAME=mcpu
156+
endif
157+
158+
########################################################################
159+
# FLAGS
160+
ifndef USB_TYPE
161+
USB_TYPE = USB_SERIAL
162+
endif
163+
164+
CPPFLAGS += -DBOARD_$(call PARSE_OPENCM,$(BOARD_TAG),build.board)
165+
CPPFLAGS += -DMCU_$(call PARSE_OPENCM,$(BOARD_TAG),build.mcu)
166+
CPPFLAGS += -DSTM32_MEDIUM_DENSITY -DVECT_TAB_FLASH
167+
168+
CPPFLAGS += $(call PARSE_OPENCM,$(BOARD_TAG),build.option)
169+
170+
CXXFLAGS += -fno-rtti
171+
172+
CXXFLAGS += $(call PARSE_OPENCM,$(BOARD_TAG),build.cppoption)
173+
ifeq ("$(call PARSE_OPENCM,$(BOARD_TAG),build.gnu0x)","true")
174+
CXXFLAGS_STD += -std=gnu++0x
175+
endif
176+
177+
ifeq ("$(call PARSE_OPENCM,$(BOARD_TAG),build.elide_constructors)", "true")
178+
CXXFLAGS += -felide-constructors
179+
endif
180+
181+
CPPFLAGS += -mthumb -march=armv7-m -nostdlib -Wl,--gc-sections -Wall
182+
183+
LDFLAGS += -T$(ARDUINO_DIR)/hardware/robotis/cores/robotis/CM900/flash.ld
184+
LDFLAGS += -L$(ARDUINO_CORE_PATH)
185+
LDFLAGS += -mthumb -Xlinker --gc-sections -Wall
186+
187+
OTHER_LIBS += -lstdc++
188+
189+
########################################################################
190+
# Reset is handled by upload script
191+
override RESET_CMD =
192+
193+
########################################################################
194+
# Object conversion & uploading magic, modified from Arduino.mk
195+
override TARGET_HEX = $(OBJDIR)/$(TARGET).bin
196+
197+
ifndef AVRDUDE
198+
AVRDUDE := $(shell which robotis-loader 2>/dev/null)
199+
ifndef AVRDUDE
200+
AVRDUDE = $(ARDMK_DIR)/bin/robotis-loader
201+
endif
202+
endif
203+
204+
override avr_size = $(SIZE) --target=binary $(2)
205+
206+
override AVRDUDE_COM_OPTS =
207+
ifeq ($(CURRENT_OS), WINDOWS)
208+
override AVRDUDE_ARD_OPTS = $(COM_STYLE_MONITOR_PORT)
209+
else
210+
override AVRDUDE_ARD_OPTS = $(call get_monitor_port)
211+
endif
212+
213+
override AVRDUDE_UPLOAD_HEX = $(TARGET_HEX)
214+
215+
########################################################################
216+
# automatically include Arduino.mk
217+
218+
include $(ARDMK_DIR)/Arduino.mk
219+
220+
########################################################################
221+
# Object conversion & uploading magic, modified from Arduino.mk
222+
223+
$(OBJDIR)/%.bin: $(OBJDIR)/%.elf $(COMMON_DEPS)
224+
@$(MKDIR) $(dir $@)
225+
$(OBJCOPY) -v -Obinary $< $@
226+
@$(ECHO) '\n'
227+
$(call avr_size,$<,$@)
228+
ifneq ($(strip $(HEX_MAXIMUM_SIZE)),)
229+
@if [ `$(SIZE) --target=binary $@ | awk 'FNR == 2 {print $$2}'` -le $(HEX_MAXIMUM_SIZE) ]; then touch $@.sizeok; fi
230+
else
231+
@$(ECHO) "Maximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $@ is less then $(BOARD_TAG)\'s flash memory"
232+
@touch $@.sizeok
233+
endif
234+
235+
# link fails to plug _sbrk into libc if core is a lib, seems a bug in the linker
236+
CORE_LIB = $(CORE_OBJS)

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,17 @@ For Teensy 3.x support you must first install [Teensyduino](http://www.pjrc.com/
279279

280280
See examples/BlinkTeensy for example usage.
281281

282+
## Robotis OpenCM
283+
284+
For Robotis OpenCM support you must first install [the OpenCM IDE](http://support.robotis.com/en/software/robotis_opencm/robotis_opencm.htm)
285+
286+
See examples/BlinkOpenCM for example usage.
287+
288+
For large Robotis projects, [libmaple](https://github.com/Rhoban/Maple) may be more appropriate, as the OpenCM IDE uses a very old compiler release.
289+
282290
## Versioning
283291

284-
The current version of the makefile is `1.5.2`. You can find the full history in the [HISTORY.md](HISTORY.md) file
292+
The current version of the makefile is `1.6.0`. You can find the full history in the [HISTORY.md](HISTORY.md) file
285293

286294
This project adheres to Semantic [Versioning 2.0](http://semver.org/).
287295

ard-reset-arduino.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH ARD-RESET-ARDUINO "1" "January 2017" "ard-reset-arduino 1.5.2" "Arduino CLI Reset"
1+
.TH ARD-RESET-ARDUINO "1" "January 2017" "ard-reset-arduino 1.6.0" "Arduino CLI Reset"
22

33
.SH NAME
44
ard-reset-arduino - Reset Arduino board

bin/robotis-loader

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/python
2+
3+
# This script sends a program on a robotis board (OpenCM9.04 or CM900)
4+
# using the robotis bootloader (used in OpenCM IDE)
5+
#
6+
# Usage:
7+
# python robotis-loader.py <serial port> <binary>
8+
#
9+
# Example:
10+
# python robotis-loader.py /dev/ttyACM0 firmware.bin
11+
#
12+
# https://github.com/Gregwar/robotis-loader
13+
14+
import serial, sys, os, time
15+
16+
print('~~ Robotis loader ~~')
17+
print('')
18+
19+
# Reading command line
20+
if len(sys.argv) != 3:
21+
exit('! Usage: robotis-loader.py <serial-port> <binary>')
22+
pgm, port, binary = sys.argv
23+
24+
# Helper to prints a progress bar
25+
def progressBar(percent, precision=65):
26+
threshold=precision*percent/100.0
27+
sys.stdout.write('[ ')
28+
for x in xrange(0, precision):
29+
if x < threshold: sys.stdout.write('#')
30+
else: sys.stdout.write(' ')
31+
sys.stdout.write(' ] ')
32+
sys.stdout.flush()
33+
34+
# Opening the firmware file
35+
try:
36+
stat = os.stat(binary)
37+
size = stat.st_size
38+
firmware = file(binary, 'rb')
39+
print('* Opening %s, size=%d' % (binary, size))
40+
except:
41+
exit('! Unable to open file %s' % binary)
42+
43+
# Opening serial port
44+
try:
45+
s = serial.Serial(port, baudrate=115200)
46+
except:
47+
exit('! Unable to open serial port %s' % port)
48+
49+
print('* Resetting the board')
50+
s.setRTS(True)
51+
s.setDTR(False)
52+
time.sleep(0.1)
53+
s.setRTS(False)
54+
s.write('CM9X')
55+
s.close()
56+
time.sleep(1.0);
57+
58+
print('* Connecting...')
59+
s = serial.Serial(port, baudrate=115200)
60+
s.write('AT&LD')
61+
print('* Download signal transmitted, waiting...')
62+
63+
# Entering bootloader sequence
64+
while True:
65+
line = s.readline().strip()
66+
if line.endswith('Ready..'):
67+
print('* Board ready, sending data')
68+
cs = 0
69+
pos = 0
70+
while True:
71+
c = firmware.read(2048)
72+
if len(c):
73+
pos += len(c)
74+
sys.stdout.write("\r")
75+
progressBar(100*float(pos)/float(size))
76+
s.write(c)
77+
for k in range(0,len(c)):
78+
cs = (cs+ord(c[k]))%256
79+
else:
80+
break
81+
print('')
82+
s.setDTR(True)
83+
print('* Checksum: %d' % (cs))
84+
s.write(chr(cs))
85+
print('* Firmware was sent')
86+
else:
87+
if line == 'Success..':
88+
print('* Success, running the code')
89+
print('')
90+
s.write('AT&RST')
91+
s.close()
92+
exit()
93+
else:
94+
print('Board -> '+line)

0 commit comments

Comments
 (0)