* STM32F401xx (STM32 Nucleo-F401RE board)
* STM32F030R8T6 (STM32 Nucleo-F030R8 board)
* STM32F072RBT6 (STM32 Nucleo-F072RB board)
+* STM32F103RB (STM32 Nucleo-F103RB board)
+* STM32F334R8 (STM32 Nucleo-F334R8 board)
Please report any and all known working combinations so I can update this!
#include <sys/types.h>
#include "stlink-common.h"
+#define DEBUG_LOG_LEVEL 100
+#define STND_LOG_LEVEL 50
+
enum st_cmds {DO_WRITE = 0, DO_READ = 1, DO_ERASE = 2};
struct opts
{
stm32_addr_t addr;
size_t size;
int reset;
+ int log_level;
};
static void usage(void)
{
- puts("stlinkv1 command line: ./flash [--reset] {read|write} /dev/sgX path addr <size>");
- puts("stlinkv1 command line: ./flash /dev/sgX erase");
- puts("stlinkv2 command line: ./flash [--reset] {read|write} path addr <size>");
- puts("stlinkv2 command line: ./flash erase");
+ puts("stlinkv1 command line: ./st-flash [--debug] [--reset] {read|write} /dev/sgX path addr <size>");
+ puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase");
+ puts("stlinkv2 command line: ./st-flash [--debug] [--reset] {read|write} path addr <size>");
+ puts("stlinkv2 command line: ./st-flash [--debug] erase");
puts(" use hex format for addr and <size>");
}
static int get_opts(struct opts* o, int ac, char** av)
{
- /* stlinkv1 command line: ./flash {read|write} /dev/sgX path addr <size> */
- /* stlinkv2 command line: ./flash {read|write} path addr <size> */
+ /* stlinkv1 command line: ./st-flash {read|write} /dev/sgX path addr <size> */
+ /* stlinkv2 command line: ./st-flash {read|write} path addr <size> */
unsigned int i = 0;
if (ac < 1) return -1;
+ if (strcmp(av[0], "--debug") == 0)
+ {
+ o->log_level = DEBUG_LOG_LEVEL;
+ ac--;
+ av++;
+ }
+ else
+ {
+ o->log_level = STND_LOG_LEVEL;
+ }
+
if (strcmp(av[0], "--reset") == 0)
{
o->reset = 1;
if (o.devname != NULL) /* stlinkv1 */
{
- sl = stlink_v1_open(50, 1);
+ sl = stlink_v1_open(o.log_level, 1);
if (sl == NULL) goto on_error;
- sl->verbose = 50;
+ sl->verbose = o.log_level;
}
else /* stlinkv2 */
{
- sl = stlink_open_usb(50, 1);
+ sl = stlink_open_usb(o.log_level, 1);
if (sl == NULL) goto on_error;
- sl->verbose = 50;
+ sl->verbose = o.log_level;
}
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE)
" <property name=\"blocksize\">0x20000</property>" //128kB
" </memory>"
" <memory type=\"ram\" start=\"0x40000000\" length=\"0x1fffffff\"/>" // peripheral regs
+ " <memory type=\"ram\" start=\"0x60000000\" length=\"0x7fffffff\"/>" // AHB3 Peripherals
" <memory type=\"ram\" start=\"0xe0000000\" length=\"0x1fffffff\"/>" // cortex regs
" <memory type=\"rom\" start=\"0x1fff0000\" length=\"0x7800\"/>" // bootrom
" <memory type=\"rom\" start=\"0x1fffc000\" length=\"0x10\"/>" // option byte area
sl->sys_base = params->bootrom_base;
sl->sys_size = params->bootrom_size;
+ //medium and low devices have the same chipid. ram size depends on flash size.
+ //STM32F100xx datasheet Doc ID 16455 Table 2
+ if(sl->chip_id == STM32_CHIPID_F1_VL_MEDIUM_LOW && sl->flash_size < 64 * 1024){
+ sl->sram_size = 0x1000;
+ }
+
ILOG("Device connected is: %s, id %#x\n", params->description, chip_id);
// TODO make note of variable page size here.....
ILOG("SRAM size: %#x bytes (%d KiB), Flash: %#x bytes (%d KiB) in pages of %zd bytes\n",
sl->chip_id == STM32_CHIPID_F4_LP || sl->chip_id == STM32_CHIPID_F4_HD || (sl->chip_id == STM32_CHIPID_F411RE)){
loader_code = loader_code_stm32f4;
loader_size = sizeof(loader_code_stm32f4);
- } else if (sl->chip_id == STM32_CHIPID_F0 || sl->chip_id == STM32_CHIPID_F0_CAN || sl->chip_id == STM32_CHIPID_F0_SMALL) {
+ } else if (sl->chip_id == STM32_CHIPID_F0 || sl->chip_id == STM32_CHIPID_F04 || sl->chip_id == STM32_CHIPID_F0_CAN || sl->chip_id == STM32_CHIPID_F0_SMALL) {
loader_code = loader_code_stm32f0;
loader_size = sizeof(loader_code_stm32f0);
} else if (sl->chip_id == STM32_CHIPID_L0) {
#define STM32_CHIPID_L0 0x417
#define STM32_CHIPID_F1_CONN 0x418
#define STM32_CHIPID_F4_HD 0x419
-#define STM32_CHIPID_F1_VL_MEDIUM 0x420
+#define STM32_CHIPID_F1_VL_MEDIUM_LOW 0x420
#define STM32_CHIPID_F3 0x422
#define STM32_CHIPID_F4_LP 0x423
#define STM32_CHIPID_F0_SMALL 0x444
+#define STM32_CHIPID_F04 0x445
+
#define STM32_CHIPID_F0_CAN 0x448
/*
.bootrom_base = 0x1fffb000,
.bootrom_size = 0x4800
},
- {
- .chip_id = STM32_CHIPID_F1_VL_MEDIUM,
- .description = "F1 Medium-density Value Line device",
+ {//Low and Medium density VL have same chipid. RM0041 25.6.1
+ .chip_id = STM32_CHIPID_F1_VL_MEDIUM_LOW,
+ .description = "F1 Medium/Low-density Value Line device",
.flash_size_reg = 0x1ffff7e0,
.flash_pagesize = 0x400,
- .sram_size = 0x2000,
+ .sram_size = 0x2000,//0x1000 for low density devices
.bootrom_base = 0x1ffff000,
.bootrom_size = 0x800
},
.bootrom_base = 0x1fffec00, // "System memory" starting address from Table 2
.bootrom_size = 0xC00 // "System memory" byte size in hex from Table 2
},
+ {
+ //Use this as an example for mapping future chips:
+ //RM0091 document was used to find these paramaters
+ .chip_id = STM32_CHIPID_F04,
+ .description = "F04x device",
+ .flash_size_reg = 0x1ffff7cc, // "Flash size data register" (pg735)
+ .flash_pagesize = 0x400, // Page sizes listed in Table 4
+ .sram_size = 0x1000, // "SRAM" byte size in hex from Table 2
+ .bootrom_base = 0x1fffec00, // "System memory" starting address from Table 2
+ .bootrom_size = 0xC00 // "System memory" byte size in hex from Table 2
+ },
{
//Use this as an example for mapping future chips:
//RM0091 document was used to find these paramaters
#include <sys/time.h>
#include <sys/types.h>
#include <libusb.h>
+#include <errno.h>
#include "stlink-common.h"
#include "stlink-usb.h"
} else {
int error = libusb_open(list[cnt], &slu->usb_handle);
if( error !=0 ) {
- WLOG("Error %d opening ST-Link/V2 device %03d:%03d\n", error, libusb_get_bus_number(list[cnt]), libusb_get_device_address(list[cnt]));
+ WLOG("Error %d (%s) opening ST-Link/V2 device %03d:%03d\n",
+ error, strerror (errno), libusb_get_bus_number(list[cnt]), libusb_get_device_address(list[cnt]));
goto on_error;
}
}
if (reset) {
stlink_reset(sl);
}
- stlink_load_device_params(sl);
stlink_version(sl);
-
- error = 0;
+ error = stlink_load_device_params(sl);
on_libusb_error:
if (devs != NULL) {
libusb_exit(slu->libusb_ctx);
if (sl != NULL) free(sl);
if (slu != NULL) free(slu);
- return 0;
+ return NULL;
}