Browse Source

* Unify pin number definition

* add arguments to allow pin change on command line
master
Jean Michault 5 years ago
parent
commit
413c39205a
11 changed files with 191 additions and 24 deletions
  1. +7
    -7
      CCDebugger.c
  2. +12
    -0
      CCDebugger.h
  3. +27
    -3
      README.md
  4. BIN
      cc_chipid
  5. +35
    -2
      cc_chipid.c
  6. BIN
      cc_erase
  7. +35
    -2
      cc_erase.c
  8. BIN
      cc_read
  9. +38
    -5
      cc_read.c
  10. BIN
      cc_write
  11. +37
    -5
      cc_write.c

+ 7
- 7
CCDebugger.c View File

@@ -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);


+ 12
- 0
CCDebugger.h View File

@@ -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 );


+ 27
- 3
README.md View File

@@ -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



BIN
cc_chipid View File


+ 35
- 2
cc_chipid.c View File

@@ -20,13 +20,46 @@
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>

#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 :


BIN
cc_erase View File


+ 35
- 2
cc_erase.c View File

@@ -20,13 +20,46 @@
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>

#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 :


BIN
cc_read View File


+ 38
- 5
cc_read.c View File

@@ -20,6 +20,7 @@
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>

#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 :


BIN
cc_write View File


+ 37
- 5
cc_write.c View File

@@ -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 :


Loading…
Cancel
Save