flash_loader: fixed interrupt masking

pull/1124/head
anton 2021-04-06 22:03:52 +05:00
rodzic ee43e3b357
commit 6bd99d4b55
13 zmienionych plików z 38 dodań i 27 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -8,7 +8,7 @@
| --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 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 |
| --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 |

Wyświetl plik

@ -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);

Wyświetl plik

@ -191,6 +191,12 @@ enum reset_type {
RESET_SOFT_AND_HALT = 3,
};
enum run_type {
RUN_NORMAL = 0,
RUN_FLASH_LOADER = 1,
};
typedef struct _stlink stlink_t;
#include <backend.h>
@ -250,7 +256,7 @@ 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, enum reset_type type);
int stlink_run(stlink_t *sl);
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);

Wyświetl plik

@ -1791,7 +1791,7 @@ int stlink_reset(stlink_t *sl, enum reset_type type) {
return(0);
}
int stlink_run(stlink_t *sl) {
int stlink_run(stlink_t *sl, enum run_type type) {
struct stlink_reg rr;
DLOG("*** stlink_run ***\n");
@ -1804,7 +1804,7 @@ int stlink_run(stlink_t *sl) {
stlink_write_reg(sl, rr.xpsr | (1 << 24), 16);
}
return(sl->backend->run(sl));
return(sl->backend->run(sl, type));
}
int stlink_set_swdclk(stlink_t *sl, int freq_khz) {
@ -2096,7 +2096,7 @@ int stlink_trace_read(stlink_t* sl, uint8_t* buf, size_t size) {
void stlink_run_at(stlink_t *sl, stm32_addr_t addr) {
stlink_write_reg(sl, addr, 15); /* pc register */
stlink_run(sl);
stlink_run(sl, RUN_NORMAL);
while (stlink_is_core_halted(sl)) { usleep(3000000); }
}
@ -2258,7 +2258,7 @@ static void stlink_fwrite_finalize(stlink_t *sl, stm32_addr_t addr) {
// set PC to the reset routine
stlink_read_debug32(sl, addr + 4, &val);
stlink_write_reg(sl, val, 15);
stlink_run(sl);
stlink_run(sl, RUN_NORMAL);
}
int stlink_mwrite_sram(stlink_t * sl, uint8_t* data, uint32_t length, stm32_addr_t addr) {

Wyświetl plik

@ -17,7 +17,7 @@ static void cleanup(int signum) {
(void)signum;
if (connected_stlink) { // switch back to mass storage mode before closing
stlink_run(connected_stlink);
stlink_run(connected_stlink, RUN_NORMAL);
stlink_exit_debug_mode(connected_stlink);
stlink_close(connected_stlink);
}

Wyświetl plik

@ -539,7 +539,7 @@ int main(int argc, char** argv)
memset(&trace, 0, sizeof(trace));
trace.start_time = time(NULL);
if (stlink_run(stlink)) {
if (stlink_run(stlink, RUN_NORMAL)) {
ELOG("Unable to run device\n");
if (!settings.force)
return APP_RESULT_STLINK_STATE_ERROR;

Wyświetl plik

@ -74,7 +74,7 @@ static void init_cache(stlink_t *sl);
static void _cleanup() {
if (connected_stlink) {
// Switch back to mass storage mode before closing
stlink_run(connected_stlink);
stlink_run(connected_stlink, RUN_NORMAL);
stlink_exit_debug_mode(connected_stlink);
stlink_close(connected_stlink);
}
@ -252,11 +252,11 @@ int main(int argc, char** argv) {
init_cache(sl);
do { // don't go beserk if serve() returns with error
do { // don't go beserk if serve() returns with error
if (serve(sl, &state)) { usleep (1 * 1000); }
sl = connected_stlink; // in case serve() changed the connection
stlink_run(sl); // continue
sl = connected_stlink; // in case serve() changed the connection
stlink_run(sl, RUN_NORMAL); // continue
} while (state.persistent);
#if defined(_WIN32)
@ -1229,7 +1229,7 @@ int serve(stlink_t *sl, st_state_t *st) {
if (!strncmp(cmd, "resume", 6)) { // resume
DLOG("Rcmd: resume\n");
cache_sync(sl);
ret = stlink_run(sl);
ret = stlink_run(sl, RUN_NORMAL);
if (ret) {
DLOG("Rcmd: resume failed\n");
@ -1396,7 +1396,7 @@ int serve(stlink_t *sl, st_state_t *st) {
case 'c':
cache_sync(sl);
ret = stlink_run(sl);
ret = stlink_run(sl, RUN_NORMAL);
if (ret) { DLOG("Semihost: run failed\n"); }
@ -1466,7 +1466,7 @@ int serve(stlink_t *sl, st_state_t *st) {
// continue execution
cache_sync(sl);
ret = stlink_run(sl);
ret = stlink_run(sl, RUN_NORMAL);
if (ret) { DLOG("Semihost: continue execution failed with stlink_run\n"); }
} else {
@ -1806,7 +1806,7 @@ int serve(stlink_t *sl, st_state_t *st) {
}
case 'k':
// kill request - reset the connection itself
ret = stlink_run(sl);
ret = stlink_run(sl, RUN_NORMAL);
if (ret) { DLOG("Kill: stlink_run failed\n"); }
ret = stlink_exit_debug_mode(sl);

Wyświetl plik

@ -347,7 +347,7 @@ int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t targe
}
/* Run loader */
stlink_run(sl);
stlink_run(sl, RUN_FLASH_LOADER);
/* This piece of code used to try to spin for .1 second by waiting doing 10000 rounds of 10 µs.
* But because this usually runs on Unix-like OSes, the 10 µs get rounded up to the "tick"

Wyświetl plik

@ -731,8 +731,9 @@ void stlink_write_dreg(stlink_t *sl, uint32_t reg, uint32_t addr) {
}
// force the core exit the debug mode.
int _stlink_sg_run(stlink_t *sl) {
int _stlink_sg_run(stlink_t *sl, enum run_type type) {
struct stlink_libsg *sg = sl->backend_data;
(void)(type); //unused
clear_cdb(sg);
sg->cdb_cmd_blk[1] = STLINK_DEBUG_RUNCORE;
sl->q_len = 2;

Wyświetl plik

@ -590,14 +590,17 @@ int _stlink_usb_step(stlink_t* sl) {
/**
* This seems to do a good job of restarting things from the beginning?
* @param sl
* @param type
*/
int _stlink_usb_run(stlink_t* sl) {
int _stlink_usb_run(stlink_t* sl, enum run_type type) {
struct stlink_libusb * const slu = sl->backend_data;
int res;
if (sl->version.jtag_api != STLINK_JTAG_API_V1) {
res = _stlink_usb_write_debug32(sl, STLINK_REG_DHCSR, STLINK_REG_DHCSR_DBGKEY | STLINK_REG_DHCSR_C_DEBUGEN);
res = _stlink_usb_write_debug32(sl, STLINK_REG_DHCSR,
STLINK_REG_DHCSR_DBGKEY | STLINK_REG_DHCSR_C_DEBUGEN |
((type==RUN_FLASH_LOADER)?STLINK_REG_DHCSR_C_MASKINTS:0));
return(res);
}

Wyświetl plik

@ -159,7 +159,7 @@ int main(void) { // main() ripped out of old stlink-hw.c
#endif
#if 0
stlink_run(sl);
stlink_run(sl, RUN_NORMAL);
stlink_status(sl);
stlink_force_debug(sl);
stlink_status(sl);
@ -196,7 +196,7 @@ int main(void) { // main() ripped out of old stlink-hw.c
#endif
#if 0
stlink_run(sl);
stlink_run(sl, RUN_NORMAL);
stlink_status(sl);
// back to mass mode, just in case ...
stlink_exit_debug_mode(sl);

Wyświetl plik

@ -111,7 +111,7 @@ int main(int ac, char** av) {
stlink_step(sl);
printf("-- run\n");
stlink_run(sl);
stlink_run(sl, RUN_NORMAL);
printf("-- exit_debug_mode\n");
stlink_exit_debug_mode(sl);