Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring some code, merge st-probe and fixup #318 serial print #398

Merged
merged 3 commits into from
Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
INSTALL
Makefile.in
aclocal.m4
Expand Down
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,13 @@ target_link_libraries(st-flash ${PROJECT_NAME})
add_executable(st-info src/st-info.c)
target_link_libraries(st-info ${PROJECT_NAME})

add_executable(st-probe src/st-probe.c)
target_link_libraries(st-probe ${PROJECT_NAME})

add_executable(st-util gdbserver/gdb-remote.c
gdbserver/gdb-remote.h
gdbserver/gdb-server.c
gdbserver/gdb-server.h)
target_link_libraries(st-util ${PROJECT_NAME})

install(TARGETS ${PROJECT_NAME} st-flash st-util st-info st-probe
install(TARGETS ${PROJECT_NAME} st-flash st-util st-info
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)
Expand Down
8 changes: 3 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ SUBDIRS = . $(MAYBE_GUI)
AUTOMAKE_OPTIONS = subdir-objects

if MINGW
bin_PROGRAMS = st-flash st-util st-info st-probe
bin_PROGRAMS = st-flash st-util st-info
else
bin_PROGRAMS = st-flash st-util st-term st-info st-probe
bin_PROGRAMS = st-flash st-util st-term st-info
endif

noinst_LIBRARIES = libstlink.a

st_flash_SOURCES = flash/main.c
st_term_SOURCES = src/st-term.c
st_info_SOURCES = src/st-info.c
st_probe_SOURCES = src/st-probe.c
st_util_SOURCES = gdbserver/gdb-remote.c gdbserver/gdb-remote.h gdbserver/gdb-server.c mingw/mingw.c mingw/mingw.h

CFILES = \
src/stlink-common.c \
src/stlink-usb.c \
src/stlink-sg.c \
src/uglylogging.c \
src/st-info.c
src/uglylogging.c

if !MINGW
CFILES += src/st-term.c
Expand Down
63 changes: 54 additions & 9 deletions src/st-info.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* simple wrapper around the stlink_flash_write function */

// TODO - this should be done as just a simple flag to the st-util command line...


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "stlink-common.h"

#include <stlink-common.h>

static void usage(void)
{
Expand All @@ -16,9 +12,52 @@ static void usage(void)
puts("st-info --descr");
puts("st-info --pagesize");
puts("st-info --chipid");
puts("st-info --serial");
puts("st-info --probe");
}

static void stlink_print_info(stlink_t *sl)
{
const chip_params_t *params = NULL;

if (!sl)
return;

for (int n = 0; n < sl->serial_size; n++)
printf("%02x", sl->serial[n]);
printf("\n");

printf("\t flash: %zu (pagesize: %zu)\n", sl->flash_size, sl->flash_pgsz);
printf("\t sram: %zu\n", sl->sram_size);
printf("\tchipid: 0x%.4x\n", sl->chip_id);

for (size_t i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) {
if (devices[i].chip_id == sl->chip_id) {
params = &devices[i];
break;
}
}

if (params)
printf("\t descr: %s\n", params->description);
}

static void stlink_probe(void)
{
stlink_t **stdevs;
size_t size;

size = stlink_probe_usb(&stdevs);

printf("Found %zu stlink programmers\n", size);

for (size_t n = 0; n < size; n++)
stlink_print_info(stdevs[n]);

stlink_probe_usb_free(&stdevs, size);
}

static int print_data(stlink_t* sl, char** av)
static int print_data(stlink_t *sl, char **av)
{
int ret = 0;
if (strcmp(av[1], "--flash") == 0)
Expand All @@ -29,7 +68,13 @@ static int print_data(stlink_t* sl, char** av)
printf("0x%zx\n", sl->flash_pgsz);
else if (strcmp(av[1], "--chipid") == 0)
printf("0x%.4x\n", sl->chip_id);
else if (strcmp(av[1], "--descr")==0) {
else if (strcmp(av[1], "--probe") == 0)
stlink_probe();
else if (strcmp(av[1], "--serial") == 0) {
for (int n = 0; n < sl->serial_size; n++)
printf("%02x", sl->serial[n]);
printf("\n");
} else if (strcmp(av[1], "--descr") == 0) {
const chip_params_t *params = NULL;
for (size_t i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) {
if(devices[i].chip_id == sl->chip_id) {
Expand All @@ -51,7 +96,7 @@ stlink_t* open_sl(void)
stlink_t* sl;
sl = stlink_v1_open(0, 1);
if (sl == NULL)
sl = stlink_open_usb(0, 1, NULL);
sl = stlink_open_usb(0, 1, NULL);
return sl;
}

Expand Down
48 changes: 0 additions & 48 deletions src/st-probe.c

This file was deleted.

3 changes: 2 additions & 1 deletion src/stlink-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ extern "C" {
uint32_t chip_id;
int core_stat;

char serial[13];
char serial[16];
int serial_size;

#define STM32_FLASH_PGSZ 1024
#define STM32L_FLASH_PGSZ 256
Expand Down
Loading