Skip to content

Commit fdcb50e

Browse files
committed
Added support for ST nucleo devices.
Nucleo boards using the same endpoint for IN and OUT (1). This patch fix it.
1 parent c84d8fa commit fdcb50e

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

49-stlinkv2-1.rules

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# stm32 nucleo boards, with onboard st/linkv2-1
2+
# ie, STM32F0, STM32F4.
3+
# STM32VL has st/linkv1, which is quite different
4+
5+
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", \
6+
MODE:="0666", \
7+
SYMLINK+="stlinkv2-1_%n"
8+
9+
# If you share your linux system with other users, or just don't like the
10+
# idea of write permission for everybody, you can replace MODE:="0666" with
11+
# OWNER:="yourusername" to create the device owned by you, or with
12+
# GROUP:="somegroupname" and mange access using standard unix groups.

src/stlink-common.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*
1+
/*
22
* File: stlink-common.h
33
* Bulk import from stlink-hw.h
4-
*
4+
*
55
* This should contain all the common top level stlink interfaces, regardless
66
* of how the backend does the work....
77
*/
@@ -24,6 +24,7 @@ extern "C" {
2424
#define USB_ST_VID 0x0483
2525
#define USB_STLINK_PID 0x3744
2626
#define USB_STLINK_32L_PID 0x3748
27+
#define USB_STLINK_NUCLEO_PID 0x374b
2728

2829
// STLINK_DEBUG_RESETSYS, etc:
2930
#define STLINK_OK 0x80
@@ -67,7 +68,7 @@ extern "C" {
6768
#define STLINK_DEBUG_WRITEDEBUGREG 0x0f
6869
#define STLINK_DEBUG_ENTER_SWD 0xa3
6970
#define STLINK_DEBUG_ENTER_JTAG 0x00
70-
71+
7172
// TODO - possible poor names...
7273
#define STLINK_SWD_ENTER 0x30
7374
#define STLINK_SWD_READCOREID 0x32 // TBD
@@ -144,8 +145,8 @@ extern "C" {
144145
uint32_t sram_size;
145146
uint32_t bootrom_base, bootrom_size;
146147
} chip_params_t;
147-
148-
148+
149+
149150
// These maps are from a combination of the Programming Manuals, and
150151
// also the Reference manuals. (flash size reg is normally in ref man)
151152
static const chip_params_t devices[] = {
@@ -324,7 +325,7 @@ static const chip_params_t devices[] = {
324325
},
325326
};
326327

327-
328+
328329
typedef struct {
329330
uint32_t r[16];
330331
uint32_t s[32];
@@ -341,7 +342,7 @@ static const chip_params_t devices[] = {
341342
} reg;
342343

343344
typedef uint32_t stm32_addr_t;
344-
345+
345346
typedef struct _cortex_m3_cpuid_ {
346347
uint16_t implementer_id;
347348
uint16_t variant;
@@ -431,7 +432,7 @@ static const chip_params_t devices[] = {
431432
#define STM32L_SRAM_SIZE (16 * 1024)
432433
stm32_addr_t sram_base;
433434
size_t sram_size;
434-
435+
435436
// bootloader
436437
stm32_addr_t sys_base;
437438
size_t sys_size;
@@ -476,7 +477,7 @@ static const chip_params_t devices[] = {
476477
int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr);
477478
int stlink_fwrite_sram(stlink_t *sl, const char* path, stm32_addr_t addr);
478479
int stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *data, uint32_t length);
479-
480+
480481
// PUBLIC
481482
uint32_t stlink_chip_id(stlink_t *sl);
482483
void stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid);
@@ -502,7 +503,7 @@ static const chip_params_t devices[] = {
502503

503504

504505
#include "stlink-sg.h"
505-
#include "stlink-usb.h"
506+
#include "stlink-usb.h"
506507

507508

508509

src/stlink-usb.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ stlink_t* stlink_open_usb(const int verbose, int reset) {
782782
if (desc.idVendor!=USB_ST_VID) continue;
783783
if (devBus && devAddr)
784784
if ((libusb_get_bus_number(list[cnt])!=devBus) || (libusb_get_device_address(list[cnt])!=devAddr)) continue;
785-
if (desc.idProduct == USB_STLINK_32L_PID) break;
785+
if ( (desc.idProduct == USB_STLINK_32L_PID) || (desc.idProduct == USB_STLINK_NUCLEO_PID) ) break;
786786
if (desc.idProduct == USB_STLINK_PID) {
787787
slu->protocoll = 1;
788788
break;
@@ -843,9 +843,14 @@ stlink_t* stlink_open_usb(const int verbose, int reset) {
843843
WLOG("libusb_alloc_transfer failed\n");
844844
goto on_libusb_error;
845845
}
846+
846847
// TODO - could use the scanning techniq from stm8 code here...
847848
slu->ep_rep = 1 /* ep rep */ | LIBUSB_ENDPOINT_IN;
848-
slu->ep_req = 2 /* ep req */ | LIBUSB_ENDPOINT_OUT;
849+
if (desc.idProduct == USB_STLINK_NUCLEO_PID) {
850+
slu->ep_req = 1 /* ep req */ | LIBUSB_ENDPOINT_OUT;
851+
} else {
852+
slu->ep_req = 2 /* ep req */ | LIBUSB_ENDPOINT_OUT;
853+
}
849854

850855
slu->sg_transfer_idx = 0;
851856
// TODO - never used at the moment, always CMD_SIZE

0 commit comments

Comments
 (0)