stm32l4: Use buffered direct write to flash.
This commit is contained in:
parent
891d6de8eb
commit
b59bbac0b2
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Black Magic Debug project.
|
||||
*
|
||||
* Copyright (C) 2015 Black Sphere Technologies Ltd.
|
||||
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "stub.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* No STM32L4 definitions in libopencm3 yet */
|
||||
#define FLASH_SR ((volatile uint32_t *) 0x40022010)
|
||||
#define FLASH_SR_EOP (1 << 0)
|
||||
#define SR_ERROR_MASK 0xC3FA
|
||||
#define FLASH_SR_BSY (1 << 16)
|
||||
|
||||
#define FLASH_CR ((volatile uint32_t *) 0x40022014)
|
||||
#define FLASH_CR_PG (1 << 0)
|
||||
#define FLASH_CR_EOPIE (1 << 24)
|
||||
#define FLASH_CR_ERRIE (1 << 25)
|
||||
#define FLASH_SR_EOP (1 << 0)
|
||||
|
||||
void __attribute__((naked))
|
||||
stm32l4_flash_write_stub(uint32_t *dest, uint32_t *src, uint32_t size)
|
||||
{
|
||||
if ((size & 7) || ((uint32_t)dest & 7))
|
||||
stub_exit(1);
|
||||
for (int i = 0; i < size; i += 8) {
|
||||
*FLASH_CR = FLASH_CR_EOPIE | FLASH_CR_ERRIE | FLASH_CR_PG;
|
||||
*dest++ = *src++;
|
||||
*dest++ = *src++;
|
||||
__asm("dsb");
|
||||
while (*FLASH_SR & FLASH_SR_BSY)
|
||||
;
|
||||
if ((*FLASH_SR & SR_ERROR_MASK) || !(*FLASH_SR & FLASH_SR_EOP))
|
||||
stub_exit(1);
|
||||
*FLASH_SR |= FLASH_SR_EOP;
|
||||
}
|
||||
*FLASH_CR = 0;
|
||||
stub_exit(0);
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
0x1C04, 0x4314, 0x2300, 0x0764, 0xD011, 0xBE01, 0xE00F, 0x4C11, 0x6825, 0x03ED, 0xD4FB, 0x6826, 0x4D0F, 0x422E, 0xD115, 0x6825, 0x07ED, 0xD512, 0x2601, 0x6825, 0x3308, 0x4335, 0x6025, 0x4C0B, 0x4293, 0xD20C, 0x4D0A, 0x6025, 0x58CC, 0x50C4, 0x18CC, 0x6865, 0x18C4, 0x6065, 0xF3BF, 0x8F4F, 0xE7E1, 0xBE01, 0xE7EA, 0x2300, 0x6023, 0xBE00, 0x2010, 0x4002, 0xC3FA, 0x0000, 0x2014, 0x4002, 0x0001, 0x0300,
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of the Black Magic Debug project.
|
||||
*
|
||||
* Copyright (C) 2015, 2017 Uwe Bonnes
|
||||
* Copyright (C) 2015, 2017, 2018 Uwe Bonnes
|
||||
* Written by Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -112,14 +112,6 @@ static const char stm32l4_driver_str[] = "STM32L4xx";
|
|||
#define DBGMCU_IDCODE 0xE0042000
|
||||
#define FLASH_SIZE_REG 0x1FFF75E0
|
||||
|
||||
/* This routine is uses double word access.*/
|
||||
static const uint16_t stm32l4_flash_write_stub[] = {
|
||||
#include "flashstub/stm32l4.stub"
|
||||
};
|
||||
|
||||
#define SRAM_BASE 0x20000000
|
||||
#define STUB_BUFFER_BASE ALIGN(SRAM_BASE + sizeof(stm32l4_flash_write_stub), 8)
|
||||
|
||||
struct stm32l4_flash {
|
||||
struct target_flash f;
|
||||
uint32_t bank1_start;
|
||||
|
@ -258,12 +250,24 @@ static int stm32l4_flash_erase(struct target_flash *f, target_addr addr, size_t
|
|||
static int stm32l4_flash_write(struct target_flash *f,
|
||||
target_addr dest, const void *src, size_t len)
|
||||
{
|
||||
/* Write buffer to target ram call stub */
|
||||
target_mem_write(f->t, SRAM_BASE, stm32l4_flash_write_stub,
|
||||
sizeof(stm32l4_flash_write_stub));
|
||||
target_mem_write(f->t, STUB_BUFFER_BASE, src, len);
|
||||
return cortexm_run_stub(f->t, SRAM_BASE, dest,
|
||||
STUB_BUFFER_BASE, len, 0);
|
||||
target *t = f->t;
|
||||
target_mem_write32(t, FLASH_CR, FLASH_CR_PG);
|
||||
target_mem_write(t, dest, src, len);
|
||||
/* Wait for completion or an error */
|
||||
uint32_t sr;
|
||||
do {
|
||||
sr = target_mem_read32(t, FLASH_SR);
|
||||
if (target_check_error(t)) {
|
||||
DEBUG("stm32l4 flash write: comm error\n");
|
||||
return -1;
|
||||
}
|
||||
} while (sr & FLASH_SR_BSY);
|
||||
|
||||
if(sr & FLASH_SR_ERROR_MASK) {
|
||||
DEBUG("stm32l4 flash write error: sr 0x%" PRIu32 "\n", sr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool stm32l4_cmd_erase(target *t, uint32_t action)
|
||||
|
|
Loading…
Reference in New Issue