| diff -aruN stm32flash/stm32.c stm32flash_new/stm32.c |
| --- stm32flash/stm32.c 2016-06-01 14:08:24.915895726 -0700 |
| +++ stm32flash_new/stm32.c 2016-06-01 14:17:48.097561748 -0700 |
| @@ -93,6 +93,26 @@ |
| 0x04, 0x00, 0xfa, 0x05 // .word 0x05fa0004 <AIRCR_RESET_VALUE> = VECTKEY | SYSRESETREQ |
| }; |
| |
| +/* Workaround for L433VC part, check the PEMPTY bit(0x20000) in FLASH_SR register, if it is set |
| + clear it via writing 0x20000 to FLASH_SR so target will boot from flash on next reset */ |
| +static const uint8_t stml433vc_reset_code[] = { |
| + 0x07, 0x4B, // ldr r3 0x20003128 0x20003108 load FLASH_SR_ADDRESS to r3 |
| + 0x18, 0x68, // ldr r0, [r3] 0x2000310a load FLASH_SR reg to r0 |
| + 0x80, 0x22, // movs r2, #128 0x2000310c load 0x20000 to r2 |
| + 0x92, 0x02, // lsls r2, r2, #10 0x2000310e |
| + 0x10, 0x40, // ands r0 r2 0x20003110 check 0x20000 in FLASH_SR reg |
| + 0x00, 0xd0, // beq 0x20003116 0x20003112 if 0x20000 is set, set it again |
| + 0x1a, 0x60, // str r2, [r3, #0] 0x20003114 |
| + 0x02, 0x49, // ldr r1, 0x20003120 ; 0x20003116 perform system reset via AIRCR |
| + 0x02, 0x4A, // ldr r2, 0x20003124 ; 0x20003118 |
| + 0x0A, 0x60, // str r2, [r1] 0x2000311a |
| + 0xfe, 0xe7, // endless: b endless 0x2000311c |
| + 0x00, 0xbf, // nop 0x2000311e |
| + 0x0c, 0xed, 0x00, 0xe0, // .word 0xe000ed0c <AIRCR_OFFSET> = NVIC AIRCR register address 0x20003120 |
| + 0x04, 0x00, 0xfa, 0x05, // .word 0x05fa0004 <AIRCR_RESET_VALUE> = VECTKEY | SYSRESETREQ 0x20003124 |
| + 0x10, 0x20, 0x02, 0x40, // .word 0x40022010 FLASH_SR_ADDRESS 0x20003128 |
| +}; |
| + |
| static const uint32_t stm_reset_code_length = sizeof(stm_reset_code); |
| |
| extern const stm32_dev_t devices[]; |
| @@ -863,7 +883,9 @@ |
| const uint8_t *code, uint32_t code_size) |
| { |
| uint32_t stack_le = le_u32(0x20002000); |
| - uint32_t code_address_le = le_u32(target_address + 8); |
| + /* Need to add 1 to target address to indicate thumb mode |
| + because GO cmd uses BLX instruction to perform jump*/ |
| + uint32_t code_address_le = le_u32(target_address + 8 + 1); |
| uint32_t length = code_size + 8; |
| uint8_t *mem, *pos; |
| uint32_t address, w; |
| @@ -930,7 +952,10 @@ |
| { |
| uint32_t target_address = stm->dev->ram_start; |
| |
| - return stm32_run_raw_code(stm, target_address, stm_reset_code, stm_reset_code_length); |
| + if (stm->dev->id == 0x435) |
| + return stm32_run_raw_code(stm, target_address, stml433vc_reset_code, sizeof(stml433vc_reset_code)); |
| + else |
| + return stm32_run_raw_code(stm, target_address, stm_reset_code, stm_reset_code_length); |
| } |
| |
| stm32_err_t stm32_crc_memory(const stm32_t *stm, uint32_t address, |