kopia lustrzana https://github.com/stlink-org/stlink
[ update ] flash support for the STM32F401XX (installed on the nucleo F4 boards)
rodzic
985cb481a7
commit
4531918c97
|
@ -143,7 +143,7 @@ static inline uint32_t read_flash_obr(stlink_t *sl) {
|
|||
|
||||
static inline uint32_t read_flash_cr(stlink_t *sl) {
|
||||
uint32_t res;
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||(sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
res = stlink_read_debug32(sl, FLASH_F4_CR);
|
||||
else
|
||||
|
@ -156,7 +156,7 @@ static inline uint32_t read_flash_cr(stlink_t *sl) {
|
|||
|
||||
static inline unsigned int is_flash_locked(stlink_t *sl) {
|
||||
/* return non zero for true */
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
return read_flash_cr(sl) & (1 << FLASH_F4_CR_LOCK);
|
||||
else
|
||||
|
@ -169,7 +169,7 @@ static void unlock_flash(stlink_t *sl) {
|
|||
an invalid sequence results in a definitive lock of
|
||||
the FPEC block until next reset.
|
||||
*/
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
stlink_write_debug32(sl, FLASH_F4_KEYR, FLASH_KEY1);
|
||||
stlink_write_debug32(sl, FLASH_F4_KEYR, FLASH_KEY2);
|
||||
|
@ -195,7 +195,7 @@ static int unlock_flash_if(stlink_t *sl) {
|
|||
}
|
||||
|
||||
static void lock_flash(stlink_t *sl) {
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
const uint32_t n = read_flash_cr(sl) | (1 << FLASH_F4_CR_LOCK);
|
||||
stlink_write_debug32(sl, FLASH_F4_CR, n);
|
||||
|
@ -208,7 +208,7 @@ static void lock_flash(stlink_t *sl) {
|
|||
|
||||
|
||||
static void set_flash_cr_pg(stlink_t *sl) {
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
uint32_t x = read_flash_cr(sl);
|
||||
x |= (1 << FLASH_CR_PG);
|
||||
|
@ -221,7 +221,7 @@ static void set_flash_cr_pg(stlink_t *sl) {
|
|||
|
||||
static void __attribute__((unused)) clear_flash_cr_pg(stlink_t *sl) {
|
||||
const uint32_t n = read_flash_cr(sl) & ~(1 << FLASH_CR_PG);
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
stlink_write_debug32(sl, FLASH_F4_CR, n);
|
||||
else
|
||||
|
@ -239,7 +239,7 @@ static void __attribute__((unused)) clear_flash_cr_per(stlink_t *sl) {
|
|||
}
|
||||
|
||||
static void set_flash_cr_mer(stlink_t *sl) {
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
stlink_write_debug32(sl, FLASH_F4_CR,
|
||||
stlink_read_debug32(sl, FLASH_F4_CR) | (1 << FLASH_CR_MER));
|
||||
|
@ -249,7 +249,7 @@ static void set_flash_cr_mer(stlink_t *sl) {
|
|||
}
|
||||
|
||||
static void __attribute__((unused)) clear_flash_cr_mer(stlink_t *sl) {
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
stlink_write_debug32(sl, FLASH_F4_CR,
|
||||
stlink_read_debug32(sl, FLASH_F4_CR) & ~(1 << FLASH_CR_MER));
|
||||
|
@ -259,7 +259,7 @@ static void __attribute__((unused)) clear_flash_cr_mer(stlink_t *sl) {
|
|||
}
|
||||
|
||||
static void set_flash_cr_strt(stlink_t *sl) {
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
uint32_t x = read_flash_cr(sl);
|
||||
x |= (1 << FLASH_F4_CR_STRT);
|
||||
|
@ -276,7 +276,7 @@ static inline uint32_t read_flash_acr(stlink_t *sl) {
|
|||
|
||||
static inline uint32_t read_flash_sr(stlink_t *sl) {
|
||||
uint32_t res;
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
res = stlink_read_debug32(sl, FLASH_F4_SR);
|
||||
else
|
||||
|
@ -286,7 +286,7 @@ static inline uint32_t read_flash_sr(stlink_t *sl) {
|
|||
}
|
||||
|
||||
static inline unsigned int is_flash_busy(stlink_t *sl) {
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD))
|
||||
return read_flash_sr(sl) & (1 << FLASH_F4_SR_BSY);
|
||||
else
|
||||
|
@ -931,7 +931,7 @@ int stlink_fread(stlink_t* sl, const char* path, stm32_addr_t addr, size_t size)
|
|||
size_t off;
|
||||
int num_empty = 0;
|
||||
unsigned char erased_pattern = (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE) ? 0:0xff;
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH) ? 0:0xff;
|
||||
|
||||
const int fd = open(path, O_RDWR | O_TRUNC | O_CREAT, 00700);
|
||||
if (fd == -1) {
|
||||
|
@ -1013,7 +1013,7 @@ uint32_t calculate_F4_sectornum(uint32_t flashaddr){
|
|||
}
|
||||
|
||||
uint32_t stlink_calculate_pagesize(stlink_t *sl, uint32_t flashaddr){
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
uint32_t sector=calculate_F4_sectornum(flashaddr);
|
||||
if (sector<4) sl->flash_pgsz=0x4000;
|
||||
|
@ -1031,7 +1031,7 @@ uint32_t stlink_calculate_pagesize(stlink_t *sl, uint32_t flashaddr){
|
|||
*/
|
||||
int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
|
||||
{
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
/* wait for ongoing op to finish */
|
||||
wait_flash_busy(sl);
|
||||
|
@ -1059,7 +1059,7 @@ int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
|
|||
fprintf(stdout, "Erase Final CR:0x%x\n", read_flash_cr(sl));
|
||||
#endif
|
||||
} else if (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE) {
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH) {
|
||||
|
||||
uint32_t val;
|
||||
|
||||
|
@ -1169,7 +1169,7 @@ int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
|
|||
|
||||
int stlink_erase_flash_mass(stlink_t *sl) {
|
||||
if (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE) {
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH) {
|
||||
/* erase each page */
|
||||
int i = 0, num_pages = sl->flash_size/sl->flash_pgsz;
|
||||
for (i = 0; i < num_pages; i++) {
|
||||
|
@ -1340,13 +1340,13 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) {
|
|||
size_t loader_size;
|
||||
|
||||
if (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE ) { /* stm32l */
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH ) { /* stm32l */
|
||||
loader_code = loader_code_stm32l;
|
||||
loader_size = sizeof(loader_code_stm32l);
|
||||
} else if (sl->core_id == STM32VL_CORE_ID || sl->chip_id == STM32_CHIPID_F3 || sl->chip_id == STM32_CHIPID_F37x) {
|
||||
loader_code = loader_code_stm32vl;
|
||||
loader_size = sizeof(loader_code_stm32vl);
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2 || sl->chip_id == STM32_CHIPID_F4 ||
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2 || sl->chip_id == STM32_CHIPID_F4 || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
sl->chip_id == STM32_CHIPID_F4_LP || sl->chip_id == STM32_CHIPID_F4_HD){
|
||||
loader_code = loader_code_stm32f4;
|
||||
loader_size = sizeof(loader_code_stm32f4);
|
||||
|
@ -1515,7 +1515,7 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t
|
|||
ILOG("Finished erasing %d pages of %d (%#x) bytes\n",
|
||||
page_count, sl->flash_pgsz, sl->flash_pgsz);
|
||||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) ||
|
||||
if ((sl->chip_id == STM32_CHIPID_F2) || (sl->chip_id == STM32_CHIPID_F4) || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
(sl->chip_id == STM32_CHIPID_F4_LP) || (sl->chip_id == STM32_CHIPID_F4_HD)) {
|
||||
/* todo: check write operation */
|
||||
|
||||
|
@ -1583,7 +1583,7 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t
|
|||
} //STM32F4END
|
||||
|
||||
else if (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE ) {
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH ) {
|
||||
/* use fast word write. todo: half page. */
|
||||
uint32_t val;
|
||||
|
||||
|
@ -1740,7 +1740,7 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
|
|||
int err;
|
||||
unsigned int num_empty = 0, index;
|
||||
unsigned char erased_pattern =(sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE )?0:0xff;
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH )?0:0xff;
|
||||
mapped_file_t mf = MAPPED_FILE_INITIALIZER;
|
||||
if (map_file(&mf, path) == -1) {
|
||||
ELOG("map_file() == -1\n");
|
||||
|
@ -1781,7 +1781,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
|
|||
}
|
||||
|
||||
if (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE ) {
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH ) {
|
||||
|
||||
size_t count = size / sizeof(uint32_t);
|
||||
if (size % sizeof(uint32_t)) ++count;
|
||||
|
@ -1804,7 +1804,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
|
|||
stlink_write_reg(sl, 0, 3); /* flash bank 0 (input) */
|
||||
stlink_write_reg(sl, fl->loader_addr, 15); /* pc register */
|
||||
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2 || sl->chip_id == STM32_CHIPID_F4 ||
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2 || sl->chip_id == STM32_CHIPID_F4 || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
sl->chip_id == STM32_CHIPID_F4_LP || sl->chip_id == STM32_CHIPID_F4_HD) {
|
||||
|
||||
size_t count = size / sizeof(uint32_t);
|
||||
|
@ -1839,7 +1839,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
|
|||
|
||||
/* check written byte count */
|
||||
if (sl->chip_id == STM32_CHIPID_L1_MEDIUM || sl->chip_id == STM32_CHIPID_L1_MEDIUM_PLUS
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH || sl->chip_id == STM32_CHIPID_L152_RE ) {
|
||||
|| sl->chip_id == STM32_CHIPID_L1_HIGH ) {
|
||||
|
||||
size_t count = size / sizeof(uint32_t);
|
||||
if (size % sizeof(uint32_t)) ++count;
|
||||
|
@ -1858,7 +1858,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
|
|||
return -1;
|
||||
}
|
||||
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2 || sl->chip_id == STM32_CHIPID_F4 ||
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2 || sl->chip_id == STM32_CHIPID_F4 || (sl->chip_id == STM32_CHIPID_F4_DE) ||
|
||||
sl->chip_id == STM32_CHIPID_F4_LP || sl->chip_id == STM32_CHIPID_F4_HD) {
|
||||
|
||||
stlink_read_reg(sl, 2, &rr);
|
||||
|
|
Ładowanie…
Reference in New Issue