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

Improvements and fixes of the flash loaders, unification of the reset function #1124

Merged
merged 18 commits into from
Apr 13, 2021
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
7 changes: 4 additions & 3 deletions doc/dev/developer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,19 @@ Description:
Backend: "jtag_reset"
Arguments:
sl: Pointer to the stlink data structure, returned by stlink_v1_open() or stlink_open_usb()
value: 0: drive low, 1: drive high, 2: ????
value: 0: drive low, 1: drive high, 2: pulse
Return: -1 for error. 0 for success.


Include: inc/stlink.h
Prototype: int stlink_run(stlink_t *sl);
Prototype: int stlink_run(stlink_t *sl, enum run_type type);
Definition: src/common.c
Description:
Just calls the backend "run" procedure.
Backend: "run"
Arguments:
sl: Pointer to the stlink data structure, returned by stlink_v1_open() or stlink_open_usb()
sl: Pointer to the stlink data structure, returned by stlink_v1_open() or stlink_open_usb()
type: RUN_NORMAL - run target, RUN_FLASH_LOADER - run target with masking interrupts
Return: -1 for error. 0 for success.

Include: inc/stlink.h
Expand Down
6 changes: 3 additions & 3 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
| --flash=n[k][m] | st-flash | One can specify `--flash=128k` for example, to override the default value of 64k for the STM32F103C8T6<br />to assume 128k of flash being present. This option accepts decimal (128k), octal 0200k, or hex 0x80k values.<br />Leaving the multiplier out is equally valid, e.g.: `--flash=0x20000`. The size may be followed by an optional<br />"k" or "m" to multiply the given value by 1k (1024) or 1M respectively. | v1.4.0 |
| --freq=n[k][m] | st-info<br />st-flash<br />st-util | The frequency of the SWD/JTAG interface can be specified, to override the default 1800 kHz configuration.<br />This option solely accepts decimal values (5K or 1.8M) with the unit `Hz` being left out. Valid frequencies are:<br />`5K, 15K, 25K, 50K, 100K, 125K, 240K, 480K, 950K, 1200K, 1800K, 4000K(4M)`. | v1.6.1 |
| --opt | st-flash | Optimisation can be enabled in order to skip flashing empty (0x00 or 0xff) bytes at the end of binary file.<br />This may cause some garbage data left after a flash operation. This option was enabled by default in earlier releases. | v1.6.1 |
| --reset | st-flash | Trigger a reset both before and after flashing. The default uses the hardware reset through `NRST` pin.<br />A software reset (via `AIRCR`; since v1.5.1) is used, if the hardware reset failed (`NRST` pin not connected). | v1.0.0 |
| --connect-under-reset | st-info<br />st-flash | Connect under reset. Option makes it possible to connect to the device before code execution. This is useful<br />when the target contains code that lets the device go to sleep, disables debug pins or other special code. | v1.6.1 |
| --hot-plug | st-info<br />st-util | Connect to the target without reset. | v1.6.2 |
| --reset | st-flash | Trigger a reset after flashing. The default uses the hardware reset through `NRST` pin.<br />A software reset (via `AIRCR`; since v1.5.1) is used, if the hardware reset failed (`NRST` pin not connected). | v1.0.0 |
| --connect-under-reset | st-info<br />st-flash<br />st-util | Connect under reset. Option makes it possible to connect to the device before code execution. This is useful<br />when the target contains code that lets the device go to sleep, disables debug pins or other special code. | v1.6.1 |
| --hot-plug | st-info<br />st-flash<br />st-util | Connect to the target without reset. | v1.6.2 |
| --probe | st-info | Display hardware information about the connected programmer and target MCU. | v1.2.0 |
| --version | st-info<br />st-flash<br />st-util | Print version information. | v1.3.0 |
| --help | st-flash<br />st-util | Print list of available commands. | |
Expand Down
2 changes: 1 addition & 1 deletion flashloaders/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ stm32vl.o: stm32f0.s
$(CC) stm32f0.s $(CFLAGS_ARMV7_M) -o stm32vl.o

# generic rule for all other ARMv7-M
%.o: *.s
%.o: %.s
$(CC) $< $(CFLAGS_ARMV7_M) -o $@

clean:
Expand Down
6 changes: 2 additions & 4 deletions flashloaders/stm32f0.s
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ copy:
ldr r5, flash_off_sr
add r5, r5, r7

# FLASH_CR |= 0x01 (set PG)
ldr r7, =0x1
ldr r4, [r6]
orrs r4, r4, r7
# FLASH_CR = 0x01 (set PG)
ldr r4, =0x1
str r4, [r6]

loop:
Expand Down
6 changes: 3 additions & 3 deletions flashloaders/stm32l4.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.global copy
copy:
ldr r12, flash_base
ldr r10, flash_off_bsy
ldr r10, flash_off_sr
add r10, r10, r12

loop:
Expand Down Expand Up @@ -44,5 +44,5 @@ exit:
.align 2
flash_base:
.word 0x40022000
flash_off_bsy:
.word 0x12
flash_off_sr:
.word 0x10
2 changes: 1 addition & 1 deletion inc/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
int (*core_id) (stlink_t * stl);
int (*reset) (stlink_t * stl);
int (*jtag_reset) (stlink_t * stl, int value);
int (*run) (stlink_t * stl);
int (*run) (stlink_t * stl, enum run_type type);
int (*status) (stlink_t * stl);
int (*version) (stlink_t *sl);
int (*read_debug32) (stlink_t *sl, uint32_t addr, uint32_t *data);
Expand Down
36 changes: 31 additions & 5 deletions inc/stlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ enum target_state {
#define STLINK_JTAG_READDEBUG_32BIT 0x36
#define STLINK_JTAG_DRIVE_NRST 0x3C

/* NRST pin states */
#define STLINK_JTAG_DRIVE_NRST_LOW 0x00
#define STLINK_JTAG_DRIVE_NRST_HIGH 0x01
#define STLINK_JTAG_DRIVE_NRST_PULSE 0x02

#define STLINK_DEBUG_APIV2_SWD_SET_FREQ 0x43

#define STLINK_APIV3_SET_COM_FREQ 0x61
Expand Down Expand Up @@ -137,6 +142,8 @@ typedef uint32_t stm32_addr_t;
typedef struct flash_loader {
stm32_addr_t loader_addr; // loader sram addr
stm32_addr_t buf_addr; // buffer sram address
uint32_t rcc_dma_bkp; // backup RCC DMA enable state
uint32_t iwdg_kr; // IWDG key register address
} flash_loader_t;

typedef struct _cortex_m3_cpuid_ {
Expand Down Expand Up @@ -171,6 +178,25 @@ enum transport_type {
TRANSPORT_TYPE_INVALID
};

enum connect_type {
CONNECT_HOT_PLUG = 0,
CONNECT_NORMAL = 1,
CONNECT_UNDER_RESET = 2,
};

enum reset_type {
RESET_AUTO = 0,
RESET_HARD = 1,
RESET_SOFT = 2,
RESET_SOFT_AND_HALT = 3,
};

enum run_type {
RUN_NORMAL = 0,
RUN_FLASH_LOADER = 1,
};


typedef struct _stlink stlink_t;

#include <backend.h>
Expand Down Expand Up @@ -229,10 +255,8 @@ int stlink_exit_debug_mode(stlink_t *sl);
int stlink_exit_dfu_mode(stlink_t *sl);
void stlink_close(stlink_t *sl);
int stlink_core_id(stlink_t *sl);
int stlink_reset(stlink_t *sl);
int stlink_jtag_reset(stlink_t *sl, int value);
int stlink_soft_reset(stlink_t *sl, int halt_on_reset);
int stlink_run(stlink_t *sl);
int stlink_reset(stlink_t *sl, enum reset_type type);
int stlink_run(stlink_t *sl, enum run_type type);
int stlink_status(stlink_t *sl);
int stlink_version(stlink_t *sl);
int stlink_read_debug32(stlink_t *sl, uint32_t addr, uint32_t *data);
Expand Down Expand Up @@ -297,7 +321,9 @@ int stlink_fwrite_option_bytes(stlink_t *sl, const char* path, stm32_addr_t addr

int stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl);
int stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t addr, uint8_t* base, uint32_t len);
int stlink_flashloader_stop(stlink_t *sl);
int stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl);

int stlink_target_connect(stlink_t *sl, enum connect_type connect);

#include <sg.h>
#include <usb.h>
Expand Down
Loading