mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 20:59:42 +02:00
lpc111x-isp/: Ben-based in-system programmer (ISP) for NXP LPC111x chips (WIP)
Uses SWUART. This is just a "first contact" skeleton.
This commit is contained in:
parent
ace55ffb37
commit
eea0484a41
19
lpc111x-isp/Makefile
Normal file
19
lpc111x-isp/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
CC = mipsel-openwrt-linux-gcc
|
||||
CFLAGS = -g -Wall -O9 -I../libubb/include
|
||||
LDFLAGS = -static
|
||||
LDLIBS = -L../libubb -lubb
|
||||
|
||||
MAIN = lpc111x
|
||||
OBJS = lpc111x.o
|
||||
|
||||
.PHONY: all clean spotless
|
||||
|
||||
all: $(MAIN)
|
||||
|
||||
$(MAIN): $(OBJS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS)
|
||||
|
||||
spotless: clean
|
||||
rm -f $(MAIN)
|
105
lpc111x-isp/lpc111x.c
Normal file
105
lpc111x-isp/lpc111x.c
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* lpc111x-isp/lpc111x.c - LPC111x/LPC11Cxx ISP programmer
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <ubb/ubb.h>
|
||||
#include <ubb/swuart.h>
|
||||
|
||||
|
||||
#define TGT_nRESET UBB_CMD
|
||||
#define TGT_nISP UBB_DAT1
|
||||
#define TGT_TX UBB_DAT3
|
||||
#define TGT_RX UBB_DAT2
|
||||
|
||||
#define HOST_RX TGT_TX
|
||||
#define HOST_TX TGT_RX
|
||||
|
||||
|
||||
static void dump(uint8_t *s, int len)
|
||||
{
|
||||
const uint8_t *end = s+len;
|
||||
|
||||
for (end = s+len; s != end; s++) {
|
||||
if (*s >= ' ' && *s <= '~')
|
||||
printf("%c", *s);
|
||||
else if (*s == 10)
|
||||
printf(s+1 == end ? "\n" : "\\n");
|
||||
else if (*s == 13)
|
||||
;
|
||||
else
|
||||
printf("\\%02o", *s);
|
||||
}
|
||||
if (len && end[-1] != '\n')
|
||||
printf("...\n");
|
||||
}
|
||||
|
||||
|
||||
static void at_exit(void)
|
||||
{
|
||||
ubb_close(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint8_t reply[1000];
|
||||
int got;
|
||||
|
||||
if (ubb_open(0) < 0) {
|
||||
perror("ubb_open");
|
||||
exit(1);
|
||||
}
|
||||
atexit(at_exit);
|
||||
|
||||
ubb_power(1);
|
||||
|
||||
usleep(100*1000);
|
||||
|
||||
SET(TGT_nRESET);
|
||||
OUT(TGT_nRESET);
|
||||
|
||||
CLR(TGT_nISP);
|
||||
OUT(TGT_nISP);
|
||||
|
||||
swuart_open(HOST_TX, HOST_RX, 115200);
|
||||
|
||||
CLR(TGT_nRESET);
|
||||
usleep(10); /* DS Table 9 pg 29 says min 50 ns */
|
||||
SET(TGT_nRESET);
|
||||
|
||||
usleep(5*1000); /* UM 26.3.1 pg 408 says max 3 ms */
|
||||
|
||||
got = swuart_trx("?", 1, reply, sizeof(reply), 1000, 100);
|
||||
dump(reply, got);
|
||||
|
||||
got = swuart_trx("Synchronized\r\n", 14,
|
||||
reply, sizeof(reply), 1000, 100);
|
||||
dump(reply, got);
|
||||
|
||||
got = swuart_trx("12000\r\n", 7,
|
||||
reply, sizeof(reply), 1000, 100);
|
||||
dump(reply, got);
|
||||
|
||||
got = swuart_trx("J\r\n", 7,
|
||||
reply, sizeof(reply), 1000, 100);
|
||||
dump(reply, got);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user