diff --git a/CCDebugger.c b/CCDebugger.c index 6f17a1c..80335f7 100644 --- a/CCDebugger.c +++ b/CCDebugger.c @@ -39,9 +39,9 @@ /** * Local properties */ - int pinRST=24; - int pinDC=28; - int pinDD=29; + int pinRST= PIN_RST; + int pinDC= PIN_DC; + int pinDD= PIN_DD; uint8_t errorFlag=0; uint8_t ddIsOutput=false; uint8_t inDebugMode=false; @@ -72,16 +72,16 @@ void cc_delay_calibrate( ); int cc_init( int pRST, int pDC, int pDD ) { + if(pRST>=0) pinRST=pRST; + if(pDC>=0) pinDC=pDC; + if(pDD>=0) pinDD=pDD; + if(wiringPiSetup() == -1){ printf("no wiring pi detected\n"); return 0; } cc_delay_calibrate(); - pinRST=pRST; - pinDC=pDC; - pinDD=pDD; - // Prepare CC Pins pinMode(pinDC, OUTPUT); pinMode(pinDD, OUTPUT); diff --git a/CCDebugger.h b/CCDebugger.h index aa0123b..edd6b41 100644 --- a/CCDebugger.h +++ b/CCDebugger.h @@ -7,6 +7,18 @@ #define CC_ERROR_NOT_DEBUGGING 2 #define CC_ERROR_NOT_WIRED 3 +// defaŭltaj valoroj por pingloj +// por restarigi al pinglo 35, DC al pinglo 36, DD al pinglo 38 +#define PIN_RST 24 +#define PIN_DC 27 +#define PIN_DD 28 + +// alternativaj valoroj por pingloj +// por restarigi al pinglo 3, DC al pinglo 11, DD al pinglo 13 +// Utila por pi 1. +//#define PIN_RST 8 +//#define PIN_DC 0 +//#define PIN_DD 2 int cc_init( int pinRST, int pinDC, int pinDD ); void cc_delay( unsigned char d ); diff --git a/README.md b/README.md index 0454cc6..25a80a8 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ git clone https://github.com/jmichault/flash_cc2531.git ``` Connect the following pins of the debug port to the GPIO port : 1. pin 1 (GND) --> pin 39 (GND) -2. pin 7 (reset) --> pin 35 (GPIO24, BCM19) -3. pin 3 (DC) --> pin 36 (GPIO27, BCM16) -4. pin 4 (DD) --> pin 38 (GPIO28, BCM20) +2. pin 7 (reset) --> pin 35 (wPi 24, BCM19) +3. pin 3 (DC) --> pin 36 (wPi 27, BCM16) +4. pin 4 (DD) --> pin 38 (wPi 28, BCM20) and insert the usb dongle in a port. @@ -51,6 +51,30 @@ To flash file to cc2531 : ``` (takes around 3 minutes). +## Using other pins +all commands accept following arguments : + -c pin : change pin_DC (default 27) + -d pin : change pin_DD (default 28) + -r pin : change reset pin (default 24) + +the pin numbering used is that of wiringPi. Use "gpio readall" to have the layout on your pi (wPi column). + +example, if you want to use pins 3, 11 and 13 : +Connect the following pins of the debug port to the GPIO port : +1. pin 1 (GND) --> pin 14 (GND) +2. pin 7 (reset) --> pin 3 (wPi 8, BCM2) +3. pin 3 (DC) --> pin 11 (wPi 0, BCM17) +4. pin 4 (DD) --> pin 13 (wPi 2, BCM27) + +and now you can read chip id, save flash content, erase flash, and write flash with following commands : +```bash +./cc_chipid -r 8 -c 0 -d 2 +./cc_read -r 8 -c 0 -d 2 save.hex +./cc_erase -r 8 -c 0 -d 2 +./cc_write -r 8 -c 0 -d 2 CC2531ZNP-Pro.hex +``` + +You can also change default values in CCDebugger.h and recompile executables with make. ## License diff --git a/cc_chipid b/cc_chipid index 3b89c44..3427c93 100755 Binary files a/cc_chipid and b/cc_chipid differ diff --git a/cc_chipid.c b/cc_chipid.c index 32fab6a..53d59b0 100644 --- a/cc_chipid.c +++ b/cc_chipid.c @@ -20,13 +20,46 @@ #include #include #include +#include #include "CCDebugger.h" -int main() +void helpo() { + fprintf(stderr,"usage : cc_chipid [-d pin_DD] [-c pin_DC] [-r pin_reset]\n"); + fprintf(stderr," -c : change pin_DC (default 27)\n"); + fprintf(stderr," -d : change pin_DD (default 28)\n"); + fprintf(stderr," -r : change reset pin (default 24)\n"); +} + +int main(int argc,char *argv[]) +{ + int opt; + int rePin=-1; + int dcPin=-1; + int ddPin=-1; + while( (opt=getopt(argc,argv,"d:c:r:h?")) != -1) + { + switch(opt) + { + case 'd' : // DD pinglo + ddPin=atoi(optarg); + break; + case 'c' : // DC pinglo + dcPin=atoi(optarg); + break; + case 'r' : // restarigi pinglo + rePin=atoi(optarg); + break; + case 'h' : // helpo + case '?' : // helpo + helpo(); + exit(0); + break; + } + } // initialize GPIO and debugger - cc_init(24,27,28); + cc_init(rePin,dcPin,ddPin); // enter debug mode cc_enter(); // get ChipID : diff --git a/cc_erase b/cc_erase index c106499..c04436a 100755 Binary files a/cc_erase and b/cc_erase differ diff --git a/cc_erase.c b/cc_erase.c index 752a962..5e52464 100644 --- a/cc_erase.c +++ b/cc_erase.c @@ -20,13 +20,46 @@ #include #include #include +#include #include "CCDebugger.h" -int main() +void helpo() { + fprintf(stderr,"usage : cc_erase [-d pin_DD] [-c pin_DC] [-r pin_reset]\n"); + fprintf(stderr," -c : change pin_DC (default 27)\n"); + fprintf(stderr," -d : change pin_DD (default 28)\n"); + fprintf(stderr," -r : change reset pin (default 24)\n"); +} + +int main(int argc,char *argv[]) +{ + int opt; + int rePin=-1; + int dcPin=-1; + int ddPin=-1; + while( (opt=getopt(argc,argv,"d:c:r:h?")) != -1) + { + switch(opt) + { + case 'd' : // DD pinglo + ddPin=atoi(optarg); + break; + case 'c' : // DC pinglo + dcPin=atoi(optarg); + break; + case 'r' : // restarigi pinglo + rePin=atoi(optarg); + break; + case 'h' : // helpo + case '?' : // helpo + helpo(); + exit(0); + break; + } + } // initialize GPIO and debugger - cc_init(24,27,28); + cc_init(rePin,dcPin,ddPin); // enter debug mode cc_enter(); // get ChipID : diff --git a/cc_read b/cc_read index ca572da..0efd9e3 100755 Binary files a/cc_read and b/cc_read differ diff --git a/cc_read.c b/cc_read.c index 7788fe5..b0c1c44 100644 --- a/cc_read.c +++ b/cc_read.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "CCDebugger.h" @@ -59,13 +60,45 @@ void read1k(int bank,uint16_t offset,uint8_t * buf) } } -int main(int argc,char **argv) +void helpo() { - if( argc <2 ) { fprintf(stderr,"usage : %s outfile\n",argv[0]); exit(1); } - FILE * ficout = fopen(argv[1],"w"); - if(!ficout) { fprintf(stderr," Can't open file %s.\n",argv[1]); exit(1); } + fprintf(stderr,"usage : cc_read [-d pin_DD] [-c pin_DC] [-r pin_reset] out_file\n"); + fprintf(stderr," -c : change pin_DC (default 27)\n"); + fprintf(stderr," -d : change pin_DD (default 28)\n"); + fprintf(stderr," -r : change reset pin (default 24)\n"); +} + +int main(int argc,char *argv[]) +{ + int opt; + int rePin=-1; + int dcPin=-1; + int ddPin=-1; + while( (opt=getopt(argc,argv,"d:c:r:h?")) != -1) + { + switch(opt) + { + case 'd' : // DD pinglo + ddPin=atoi(optarg); + break; + case 'c' : // DC pinglo + dcPin=atoi(optarg); + break; + case 'r' : // restarigi pinglo + rePin=atoi(optarg); + break; + case 'h' : // helpo + case '?' : // helpo + helpo(); + exit(0); + break; + } + } + if( optind >= argc ) { helpo(); exit(1); } + FILE * ficout = fopen(argv[optind],"w"); + if(!ficout) { fprintf(stderr," Can't open file %s.\n",argv[optind]); exit(1); } // initialize GPIO ports - cc_init(24,27,28); + cc_init(rePin,dcPin,ddPin); // enter debug mode cc_enter(); // get ChipID : diff --git a/cc_write b/cc_write index 48ed5c8..615ed1a 100755 Binary files a/cc_write and b/cc_write differ diff --git a/cc_write.c b/cc_write.c index 70ccc6c..2fa6166 100644 --- a/cc_write.c +++ b/cc_write.c @@ -217,13 +217,45 @@ int writePage(int page) } -int main(int argc,char **argv) +void helpo() { - if( argc <2 ) { fprintf(stderr,"usage : %s file_to_flash\n",argv[0]); exit(1); } - FILE * ficin = fopen(argv[1],"r"); - if(!ficin) { fprintf(stderr," Can't open file %s.\n",argv[1]); exit(1); } + fprintf(stderr,"usage : cc_write [-d pin_DD] [-c pin_DC] [-r pin_reset] file_to_flash\n"); + fprintf(stderr," -c : change pin_DC (default 27)\n"); + fprintf(stderr," -d : change pin_DD (default 28)\n"); + fprintf(stderr," -r : change reset pin (default 24)\n"); +} + +int main(int argc,char *argv[]) +{ + int opt; + int rePin=24; + int dcPin=27; + int ddPin=28; + while( (opt=getopt(argc,argv,"d:c:r:h?")) != -1) + { + switch(opt) + { + case 'd' : // DD pinglo + ddPin=atoi(optarg); + break; + case 'c' : // DC pinglo + dcPin=atoi(optarg); + break; + case 'r' : // restarigi pinglo + rePin=atoi(optarg); + break; + case 'h' : // helpo + case '?' : // helpo + helpo(); + exit(0); + break; + } + } + if( optind >= argc ) { helpo(); exit(1); } + FILE * ficin = fopen(argv[optind],"r"); + if(!ficin) { fprintf(stderr," Can't open file %s.\n",argv[optind]); exit(1); } // on initialise les ports GPIO et le debugger - cc_init(24,27,28); + cc_init(rePin,dcPin,ddPin); // entrée en mode debug cc_enter(); // envoi de la commande getChipID :