Skip to content

Commit

Permalink
Merge remote branch 'karlgithub/master' into mystm32l
Browse files Browse the repository at this point in the history
Conflicts:
	build/Makefile
	gdbserver/gdb-server.c

This merges in the bulk of bravikov's work on the command line and automatic sensible defaults for
the gdb server
  • Loading branch information
karlp committed Oct 13, 2011
2 parents dc71d50 + d99d103 commit 1d8b0c6
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 9 deletions.
29 changes: 29 additions & 0 deletions INSTALL
@@ -0,0 +1,29 @@
INSTALL
=======

1) Load the sg kernel module:

$ modprobe sg

2) On Ubuntu you need to install the package libsgutils2-dev:

$ sudo apt-get install libsgutils2-dev

3) Make:

$ make -C build

4) Install or reinstall

$ sudo make install -C build

5) Run:

$ st-util port [/dev/sgX]
or
$ st-util [port]
or
$ st-util --help

6) Have fun!

86 changes: 77 additions & 9 deletions gdbserver/gdb-server.c
Expand Up @@ -69,15 +69,74 @@ int serve(stlink_t *sl, int port);
char* make_memory_map(const struct chip_params *params, uint32_t flash_size);

int main(int argc, char** argv) {
if(argc != 3) {
fprintf(stderr, "Usage: %s <port> /dev/sgX\n", argv[0]);
return 1;
}

// FIXME - hardcoded to usb....
stlink_t *sl = stlink_open_usb(argv[2], 10);
if (sl == NULL)
return 1;
stlink_t *sl = NULL;

const char * HelpStr = "Usage:\n"
"\t st-util port [/dev/sgX]\n"
"\t st-util [port]\n"
"\t st-util --help\n";

switch(argc) {

default: {
fprintf(stderr, HelpStr, NULL);
return 1;
}

case 3 : {
//sl = stlink_quirk_open(argv[2], 0);
// FIXME - hardcoded to usb....
sl = stlink_open_usb(argv[2], 10);
if(sl == NULL) return 1;
break;
}

case 2 : {
if (strcmp(argv[1], "--help") == 0) {
fprintf(stdout, HelpStr, NULL);
return 1;
}
}

case 1 : { // Search ST-LINK (from /dev/sg0 to /dev/sg99)
const int DevNumMax = 99;
int ExistDevCount = 0;

for(int DevNum = 0; DevNum <= DevNumMax; DevNum++)
{
if(DevNum < 10) {
char DevName[] = "/dev/sgX";
const int X_index = 7;
DevName[X_index] = DevNum + '0';
if ( !access(DevName, F_OK) ) {
sl = stlink_quirk_open(DevName, 0);
ExistDevCount++;
}
}
else if(DevNum < 100) {
char DevName[] = "/dev/sgXY";
const int X_index = 7;
const int Y_index = 8;
DevName[X_index] = DevNum/10 + '0';
DevName[Y_index] = DevNum%10 + '0';
if ( !access(DevName, F_OK) ) {
sl = stlink_quirk_open(DevName, 0);
ExistDevCount++;
}
}
if(sl != NULL) break;
}

if(sl == NULL) {
fprintf(stdout, "\nNumber of /dev/sgX devices found: %i \n",
ExistDevCount);
fprintf(stderr, "ST-LINK not found\n");
return 1;
}
break;
}
}

if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE)
stlink_enter_swd_mode(sl);
Expand Down Expand Up @@ -114,7 +173,16 @@ int main(int argc, char** argv) {
// memory map is in 1k blocks.
current_memory_map = make_memory_map(params, flash_size * 0x400);

int port = atoi(argv[1]);
int port;

if(argc == 1) {
// not on 64bit?
//srand((unsigned int)&port);
port = rand()/65535;
}
else {
port = atoi(argv[1]);
}

while(serve(sl, port) == 0);

Expand Down
45 changes: 45 additions & 0 deletions stm32l/src/stlink-hw.h
@@ -0,0 +1,45 @@
#ifndef STLINK_HW_H_INCLUDED
# define STLINK_HW_H_INCLUDED

// STLINK_DEBUG_RESETSYS, etc:
#define STLINK_OK 0x80
#define STLINK_FALSE 0x81
#define STLINK_CORE_RUNNING 0x80
#define STLINK_CORE_HALTED 0x81
#define STLINK_CORE_STAT_UNKNOWN -1

#define STLINK_GET_VERSION 0xf1
#define STLINK_GET_CURRENT_MODE 0xf5

#define STLINK_DEBUG_COMMAND 0xF2
#define STLINK_DFU_COMMAND 0xF3
#define STLINK_DFU_EXIT 0x07

// STLINK_GET_CURRENT_MODE
#define STLINK_DEV_DFU_MODE 0x00
#define STLINK_DEV_MASS_MODE 0x01
#define STLINK_DEV_DEBUG_MODE 0x02
#define STLINK_DEV_UNKNOWN_MODE -1

// jtag mode cmds
#define STLINK_DEBUG_ENTER 0x20
#define STLINK_DEBUG_EXIT 0x21
#define STLINK_DEBUG_READCOREID 0x22
#define STLINK_DEBUG_GETSTATUS 0x01
#define STLINK_DEBUG_FORCEDEBUG 0x02
#define STLINK_DEBUG_RESETSYS 0x03
#define STLINK_DEBUG_READALLREGS 0x04
#define STLINK_DEBUG_READREG 0x05
#define STLINK_DEBUG_WRITEREG 0x06
#define STLINK_DEBUG_READMEM_32BIT 0x07
#define STLINK_DEBUG_WRITEMEM_32BIT 0x08
#define STLINK_DEBUG_RUNCORE 0x09
#define STLINK_DEBUG_STEPCORE 0x0a
#define STLINK_DEBUG_SETFP 0x0b
#define STLINK_DEBUG_WRITEMEM_8BIT 0x0d
#define STLINK_DEBUG_CLEARFP 0x0e
#define STLINK_DEBUG_WRITEDEBUGREG 0x0f
#define STLINK_DEBUG_ENTER_SWD 0xa3
#define STLINK_DEBUG_ENTER_JTAG 0x00

#endif /* STLINK_HW_H_INCLUDED */

0 comments on commit 1d8b0c6

Please sign in to comment.