]> git.gag.com Git - fw/stlink/commitdiff
Merge branch 'master' of https://github.com/texane/stlink
authorKarl Palsson <karlp@tweak.net.au>
Fri, 4 Nov 2011 02:51:15 +0000 (02:51 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Fri, 4 Nov 2011 02:51:15 +0000 (02:51 +0000)
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.

1  2 
Makefile
doc/tutorial/tutorial.pdf
doc/tutorial/tutorial.tex
src/stlink-common.c
src/stlink-common.h
src/stlink-usb.c

diff --cc Makefile
index 646dde12df5e84ac4799af48c378d4b8dabda8ed,943302e0487fdfcb20358f82179e05d5137464db..d35b3c4f1b57739972fdabb0ba8ec86e0ee34532
+++ 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
index 70546cb813a4c8b4f4a6d2ca15587a88e6ad88da,648138732a728963e6a538c2a9a5825a42055e45..856977bc7ce42517c50a390be589c18d46fb9b8e
Binary files differ
index 4aafa20242563a7060bd5618b3fca15367670e70,0437119c1351ed910d1d02a78078b0ab6f80c602..c3615df7818a1dad9f4d08a35ae8639217d9b42d
@@@ -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
index 8f3431a23ea3679145cfd7228dbef2afb453f0c8,a44e6e020031682e4f3e37ec6ee6a8c2aa515fa9..f58c34405e01f1b2e0fe4d04009122ed4650b184
  
  
  #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
Simple merge
index a81676936772ff8c0f7865f3f89b0cd5c39d7368,4fb3a1c3204d91dc81f9e67b5a75b89eaae4d439..785f7beca46647fa9eebf99b146eddebab292a73
@@@ -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;
          
      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: