Skip to content

Instantly share code, notes, and snippets.

@durka
Created October 31, 2012 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durka/3984520 to your computer and use it in GitHub Desktop.
Save durka/3984520 to your computer and use it in GitHub Desktop.
Failure to program Launchpad
alex$ make
Generating dependencies hello_world.d from hello_world.c
Compiling hello_world.c
Linking hello_world.elf
>>>> Size of Firmware <<<<
text data bss dec hex filename
316 50 0 366 16e hello_world.elf
unix2dos: converting file hello_world.txt to DOS format ...
alex$ mspdebug rf2500
MSPDebug version 0.20 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Trying to open interface 1 on 004
Initializing FET...
FET protocol version is 30394216
Configured for Spy-Bi-Wire
Set Vcc: 3000 mV
fet: FET returned error code 4 (Could not find device (or device not supported))
fet: command C_IDENT1 failed
fet: identify failed
Trying again...
Initializing FET...
FET protocol version is 30394216
Configured for Spy-Bi-Wire
Set Vcc: 3000 mV
Device ID: 0x2553
Code start address: 0xc000
Code size : 16384 byte = 16 kb
RAM start address: 0x200
RAM end address: 0x3ff
RAM size : 512 byte = 0 kb
Device: MSP430G2553/G2403
Code memory starts at 0xc000
Number of breakpoints: 2
Chip ID data: 25 53
Available commands:
= erase isearch prog setbreak sym
alias exit load read setwatch verify
break fill locka regs setwatch_r
cgraph gdb md reset setwatch_w
delbreak help mw run simio
dis hexout opt set step
Available options:
color gdb_loop iradix
fet_block_size gdbc_xfer_size quiet
Type "help <topic>" for more information.
Press Ctrl+D to quit.
(mspdebug) prog hello_world.elf
Erasing...
Programming...
Writing 208 bytes at c000 [section: .text]...
Writing 108 bytes at c0d0 [section: .rodata]...
Writing 50 bytes at c13c [section: .data]...
Done, 366 bytes total
(mspdebug) run
fet: FET returned error code 17 (Could not run device (to breakpoint))
fet: failed to restart CPU
run: failed to start CPU
(mspdebug) ^D
Here is the Makefile... it came from the Launchpad wiki
#
# Makefile for msp430
#
# 'make' builds everything
# 'make clean' deletes everything except source files and Makefile
# You need to set TARGET, MCU and SOURCES for your project.
# TARGET is the name of the executable file to be produced
# $(TARGET).elf $(TARGET).hex and $(TARGET).txt nad $(TARGET).map are all generated.
# The TXT file is used for BSL loading, the ELF can be used for JTAG use
#
TARGET = hello_world
MCU = msp430g2553
# List all the source files here
# eg if you have a source file foo.c then list it here
SOURCES = hello_world.c
# Include are located in the Include directory
INCLUDES = -IInclude -I/usr/local/opt/msp430mcu/msp430/include
# Add or subtract whatever MSPGCC flags you want. There are plenty more
#######################################################################################
CFLAGS = -mmcu=$(MCU) -g -Os -Wall -Wunused $(INCLUDES)
ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp -Wa,-gstabs
LDFLAGS = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map -Wl,--library-path=/usr/local/opt/msp430mcu/msp430/lib/ldscripts/$(MCU) -Wl,--library-path=/usr/local/opt/msp430-libc/msp430/lib
########################################################################################
CC = msp430-gcc
LD = msp430-ld
AR = msp430-ar
AS = msp430-as
GASP = msp430-gasp
NM = msp430-nm
OBJCOPY = msp430-objcopy
RANLIB = msp430-ranlib
STRIP = msp430-strip
SIZE = msp430-size
READELF = msp430-readelf
MAKETXT = srec_cat
CP = cp -p
RM = rm -f
MV = mv
########################################################################################
# the file which will include dependencies
DEPEND = $(SOURCES:.c=.d)
# all the object files
OBJECTS = $(SOURCES:.c=.o)
all: $(TARGET).elf $(TARGET).hex $(TARGET).txt
$(TARGET).elf: $(OBJECTS)
echo "Linking $@"
$(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
echo
echo ">>>> Size of Firmware <<<<"
$(SIZE) $(TARGET).elf
echo
%.hex: %.elf
$(OBJCOPY) -O ihex $< $@
%.txt: %.hex
$(MAKETXT) -O $@ -TITXT $< -I
unix2dos $(TARGET).txt
# The above line is required for the DOS based TI BSL tool to be able to read the txt file generated from linux/unix systems.
%.o: %.c
echo "Compiling $<"
$(CC) -c $(CFLAGS) -o $@ $<
# rule for making assembler source listing, to see the code
%.lst: %.c
$(CC) -c $(ASFLAGS) -Wa,-anlhd $< > $@
# include the dependencies unless we're going to clean, then forget about them.
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPEND)
endif
# dependencies file
# includes also considered, since some of these are our own
# (otherwise use -MM instead of -M)
%.d: %.c
echo "Generating dependencies $@ from $<"
$(CC) -M ${CFLAGS} $< >$@
.SILENT:
.PHONY: clean
clean:
-$(RM) $(OBJECTS)
-$(RM) $(TARGET).*
#-$(RM) $(SOURCES:.c=.lst)
-$(RM) $(DEPEND)
And here is my little overengineered program... it is supposed to blink SOS in Morse Code.
#include <msp430.h>
#define PxX(p,x) P##p##x
#define PxOUT(p) PxX(p,OUT)
#define PxDIR(p) PxX(p,DIR)
#define PxIN(p) PxX(p,IN)
#define PxSEL(p) PxX(p,SEL)
#define LED_PORT 1
#define LED_PIN 6
#define DOT_MS 50
void sleep(unsigned int ms)
{
unsigned int m;
unsigned long i;
/* assume MCLK is running at 1MHz */
for (m = 0; m < ms; ++m)
{
/* wild, uncalibrated guess */
for (i = 0; i < 100; ++i);
}
}
void flash(int duration)
{
PxOUT(LED_PORT) |= 1<<LED_PIN;
sleep(duration);
PxOUT(LED_PORT) &= ~(1<<LED_PIN);
}
void dot()
{
flash(DOT_MS);
}
void dash()
{
flash(DOT_MS * 3);
}
char* morse_code[] = {
".-", /* A */
"-...", /* B */
"-.-.", /* C */
"-..", /* D */
".", /* E */
"..-.", /* F */
"--.", /* G */
"....", /* H */
"..", /* I */
".---", /* J */
"-.-", /* K */
".-..", /* L */
"--", /* M */
"-.", /* N */
"---", /* O */
".--.", /* P */
"--.-", /* Q */
".-.", /* R */
"...", /* S */
"-", /* T */
"..-", /* U */
"...-", /* V */
".--", /* W */
"-..-", /* Y */
"--..", /* Z */
};
void morse_send(char *code)
{
int i;
for (i = 0; code[i]; ++i)
{
switch (code[i])
{
case '.':
dot();
break;
case '-':
dash();
break;
}
}
}
void morse_char(char c)
{
if (c >= 'A' && c <= 'Z')
morse_send(morse_code[c - 'A']);
else if (c >= 'a' && c <= 'z')
morse_send(morse_code[c - 'a']);
sleep(DOT_MS);
}
void morse_str(char *s)
{
int i;
for (i = 0; s[i]; ++i)
{
switch (s[i])
{
case ' ':
sleep(DOT_MS * 6);
break;
default: /* assuming A-Za-z */
morse_char(s[i]);
sleep(DOT_MS * 3);
break;
}
}
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
DCOCTL = 0;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
PxDIR(LED_PORT) |= LED_PIN;
PxOUT(LED_PORT) &= ~(1<<LED_PIN);
while (1)
{
morse_str("SOS");
sleep(1000);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment