From: Karl Palsson Date: Fri, 4 Nov 2011 02:51:15 +0000 (+0000) Subject: Merge branch 'master' of https://github.com/texane/stlink X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c98c487fa52651505871de11d65bacaeaf1cac39;p=fw%2Fstlink Merge branch 'master' of https://github.com/texane/stlink Conflicts: Makefile doc/tutorial/tutorial.pdf example/blink/Makefile flash/main.c src/stlink-common.c src/stlink-usb.c Mostly whitespace conflicts it seems. --- c98c487fa52651505871de11d65bacaeaf1cac39 diff --cc Makefile index 646dde1,943302e..d35b3c4 --- a/Makefile +++ b/Makefile @@@ -1,13 -1,28 +1,13 @@@ -# make ... for both libusb and libsg -# -# make CONFIG_USE_LIBSG=0 ... -# for just libusb -# +# make ... for both stlink v1 and stlink v2 support +## VPATH=src -SOURCES_LIB=stlink-common.c stlink-usb.c +SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c uglylogging.c OBJS_LIB=$(SOURCES_LIB:.c=.o) -TEST_PROGRAMS=test_usb +TEST_PROGRAMS=test_usb test_sg - LDFLAGS=-lusb-1.0 -L. -lstlink + LDFLAGS=-L. -lstlink -lusb-1.0 -ifeq ($(CONFIG_USE_LIBSG),) -CONFIG_USE_LIBSG=1 -endif - -ifneq ($(CONFIG_USE_LIBSG),0) -SOURCES_LIB+=stlink-sg.c -CFLAGS+=-DCONFIG_USE_LIBSG=1 -LDFLAGS+=-lsgutils2 -TEST_PROGRAMS+=test_sg -endif - CFLAGS+=-g -CFLAGS+=-DCONFIG_USE_LIBUSB=1 CFLAGS+=-DDEBUG=1 CFLAGS+=-std=gnu99 CFLAGS+=-Wall -Wextra diff --cc doc/tutorial/tutorial.pdf index 70546cb,6481387..856977b Binary files differ diff --cc doc/tutorial/tutorial.tex index 4aafa20,0437119..c3615df --- a/doc/tutorial/tutorial.tex +++ b/doc/tutorial/tutorial.tex @@@ -162,13 -150,13 +162,12 @@@ $> continu \end{small} \paragraph{} -The board BLUE and GREEN leds should be blinking (those leds are near the user and reset buttons). - +All the LEDs on the board should now be blinking in time (those leds are near the user and reset buttons). \newpage - \section{Reading and writing to flash} + \section{Building and flashing a program} \paragraph{} - Flash memory reading and writing is done by a separate tool. A binary running in flash is assumed to - be linked against address 0x8000000. The flash tool is then used as shown below:\\ + FLASH memory reading and writing is done by a separate tool, as shown below:\\ \begin{small} \begin{lstlisting}[frame=tb] # change to the flash tool directory diff --cc src/stlink-common.c index 8f3431a,a44e6e0..f58c344 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@@ -13,17 -13,25 +13,17 @@@ #include "stlink-common.h" +#include "uglylogging.h" -void D(stlink_t *sl, char *txt) { - if (sl->verbose > 1) - fputs(txt, stderr); -} - -void DD(stlink_t *sl, char *format, ...) { - if (sl->verbose > 0) { - va_list list; - va_start(list, format); - vfprintf(stderr, format, list); - va_end(list); - } -} - +#define LOG_TAG __FILE__ +#define DLOG(format, args...) ugly_log(UDEBUG, LOG_TAG, format, ## args) +#define ILOG(format, args...) ugly_log(UINFO, LOG_TAG, format, ## args) +#define WLOG(format, args...) ugly_log(UWARN, LOG_TAG, format, ## args) +#define fatal(format, args...) ugly_log(UFATAL, LOG_TAG, format, ## args) + /* todo: stm32l15xxx flash memory, pm0062 manual */ - /* FPEC flash controller interface, pm0063 manual - */ + /* stm32f FPEC flash controller interface, pm0063 manual */ #define FLASH_REGS_ADDR 0x40022000 #define FLASH_REGS_SIZE 0x28 diff --cc src/stlink-usb.c index a816769,4fb3a1c..785f7be --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@@ -599,32 -586,52 +599,19 @@@ stlink_t* stlink_open_usb(const int ver sl->core_stat = STLINK_CORE_STAT_UNKNOWN; - /* flash memory settings */ - sl->flash_base = STM32_FLASH_BASE; - sl->flash_size = STM32_FLASH_SIZE; - sl->flash_pgsz = STM32_FLASH_PGSZ; - - /* system memory */ - sl->sys_base = STM32_SYSTEM_BASE; - sl->sys_size = STM32_SYSTEM_SIZE; - - /* sram memory settings */ - sl->sram_base = STM32_SRAM_BASE; - sl->sram_size = STM32L_SRAM_SIZE; - if (libusb_init(&(slu->libusb_ctx))) { - fprintf(stderr, "failed to init libusb context, wrong version of libraries?\n"); - goto on_error; + WLOG("failed to init libusb context, wrong version of libraries?\n"); + goto on_error; } - count = libusb_get_device_list(slu->libusb_ctx, &devs); - if (count < 0) { - printf("libusb_get_device_list\n"); - goto on_libusb_error; - } - - for (i = 0; i < count; ++i) { - dev = devs[i]; - slu->protocoll = is_stlink_device(dev, 0); - if (slu->protocoll > 0) break; - } - if (i == count) goto on_libusb_error; - - if (libusb_open(dev, &(slu->usb_handle))) { - printf("libusb_open()\n"); - goto on_libusb_error; + slu->usb_handle = libusb_open_device_with_vid_pid(slu->libusb_ctx, USB_ST_VID, USB_STLINK_32L_PID); + if (slu->usb_handle == NULL) { + // TODO - free usb context too... + free(slu); + WLOG("Couldn't find any ST-Link/V2 devices"); + return NULL; } - if (iSerial) { - unsigned char serial[256]; - struct libusb_device_descriptor desc; - int r; - - r = libusb_get_device_descriptor(dev, &desc); - if (r<0) { - printf("Can't get descriptor to match Iserial\n"); - goto on_libusb_error; - } - r = libusb_get_string_descriptor_ascii - (slu->usb_handle, desc.iSerialNumber, serial, 256); - if (r<0) { - printf("Can't get Serialnumber to match Iserial\n"); - goto on_libusb_error; - } - if (strcmp((char*)serial, iSerial)) { - printf("Mismatch in serial numbers, dev %s vs given %s\n", - serial, iSerial); - goto on_libusb_error; - } - } - if (libusb_kernel_driver_active(slu->usb_handle, 0) == 1) { int r; @@@ -675,11 -680,56 +662,57 @@@ slu->cmd_len = (slu->protocoll == 1)? STLINK_SG_SIZE: STLINK_CMD_SIZE; /* success */ + if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) { + ILOG("-- exit_dfu_mode\n"); stlink_exit_dfu_mode(sl); } + + if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) { + stlink_enter_swd_mode(sl); + } + stlink_version(sl); + + /* per device family initialization */ + stlink_core_id(sl); + if (sl->core_id == STM32L_CORE_ID) { + + /* flash memory settings */ + sl->flash_base = STM32_FLASH_BASE; + sl->flash_size = STM32_FLASH_SIZE; + sl->flash_pgsz = STM32L_FLASH_PGSZ; + + /* system memory */ + sl->sys_base = STM32_SYSTEM_BASE; + sl->sys_size = STM32_SYSTEM_SIZE; + + /* sram memory settings */ + sl->sram_base = STM32_SRAM_BASE; + sl->sram_size = STM32L_SRAM_SIZE; + + } else if (sl->core_id == STM32VL_CORE_ID) { + + /* flash memory settings */ + sl->flash_base = STM32_FLASH_BASE; + sl->flash_size = STM32_FLASH_SIZE; + sl->flash_pgsz = STM32_FLASH_PGSZ; + + /* system memory */ + sl->sys_base = STM32_SYSTEM_BASE; + sl->sys_size = STM32_SYSTEM_SIZE; + + /* sram memory settings */ + sl->sram_base = STM32_SRAM_BASE; + sl->sram_size = STM32_SRAM_SIZE; + + } else { + + fprintf(stderr, "unknown coreid: %x\n", sl->core_id); + goto on_libusb_error; + + } + error = 0; on_libusb_error: