Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flash/stm32h5x: support STM32H5x devices
Change-Id: Id6ea9dc66849e374d17e5677b6a1099b61d6dc0b Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
- Loading branch information
1 parent
c918b29
commit d4f1ae4
Showing
10 changed files
with
1,954 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/* | ||
* Copyright (C) 2022 by Tarek BOCHKATI for STMicroelectronics | ||
* <tarek.bouchkati@st.com> | ||
*/ | ||
|
||
#define OPENOCD_CONTRIB_LOADERS_FLASH_STM32_STM32H5X | ||
|
||
#include <stdint.h> | ||
#include "../../../../src/flash/nor/stm32h5x.h" | ||
|
||
static inline __attribute__((always_inline)) | ||
void copy_buffer_u32(uint32_t *dst, uint32_t *src, int len) | ||
{ | ||
for (int i = 0; i < len; i++) | ||
dst[i] = src[i]; | ||
} | ||
|
||
/* this function is assumes that fifo_size is multiple of flash_word_size | ||
* this condition is ensured by target_run_flash_async_algorithm | ||
*/ | ||
|
||
void write(volatile struct stm32h5x_work_area *work_area, | ||
uint8_t *fifo_end, | ||
uint8_t *target_address, | ||
uint32_t count) | ||
{ | ||
volatile uint32_t *flash_sr = (uint32_t *)work_area->params.flash_sr_addr; | ||
volatile uint32_t *flash_cr = (uint32_t *)work_area->params.flash_cr_addr; | ||
|
||
/* optimization to avoid reading from memory each time */ | ||
uint8_t *rp_cache = work_area->fifo.rp; | ||
|
||
/* fifo_start is used to wrap when we reach fifo_end */ | ||
uint8_t *fifo_start = rp_cache; | ||
|
||
/* enable flash programming */ | ||
*flash_cr = FLASH_PG; | ||
|
||
while (count) { | ||
/* optimization to avoid reading from memory each time */ | ||
uint8_t *wp_cache = work_area->fifo.wp; | ||
if (wp_cache == 0) | ||
break; /* aborted by target_run_flash_async_algorithm */ | ||
|
||
int32_t fifo_size = wp_cache - rp_cache; | ||
if (fifo_size < 0) { | ||
/* consider the linear fifo, we will wrap later */ | ||
fifo_size = fifo_end - rp_cache; | ||
} | ||
|
||
/* wait for at least a flash word */ | ||
while (fifo_size >= work_area->params.flash_word_size) { | ||
copy_buffer_u32((uint32_t *)target_address, | ||
(uint32_t *)rp_cache, | ||
work_area->params.flash_word_size / 4); | ||
|
||
/* update target_address and rp_cache */ | ||
target_address += work_area->params.flash_word_size; | ||
rp_cache += work_area->params.flash_word_size; | ||
|
||
/* wait for the busy flag */ | ||
while (*flash_sr & FLASH_BSY) | ||
; | ||
|
||
if (*flash_sr & FLASH_ERROR) { | ||
work_area->fifo.rp = 0; /* set rp to zero 0 on error */ | ||
goto write_end; | ||
} | ||
|
||
/* wrap if reach the fifo_end, and update rp in memory */ | ||
if (rp_cache >= fifo_end) | ||
rp_cache = fifo_start; | ||
|
||
/* flush the rp cache value, | ||
* so target_run_flash_async_algorithm can fill the circular fifo */ | ||
work_area->fifo.rp = rp_cache; | ||
|
||
/* update fifo_size and count */ | ||
fifo_size -= work_area->params.flash_word_size; | ||
count--; | ||
} | ||
} | ||
|
||
write_end: | ||
/* disable flash programming */ | ||
*flash_cr = 0; | ||
|
||
/* soft break the loader */ | ||
__asm("bkpt 0"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* Autogenerated with ../../../../src/helper/bin2char.sh */ | ||
0x2d,0xe9,0xf0,0x43,0x02,0x24,0xd0,0xf8,0x00,0x80,0xd0,0xf8,0x04,0xe0,0xd0,0xf8, | ||
0x74,0x90,0xce,0xf8,0x00,0x40,0x4c,0x46,0xe3,0xb1,0x05,0x6f,0xd5,0xb1,0x2d,0x1b, | ||
0x00,0xd5,0x0d,0x1b,0x86,0x68,0xae,0x42,0xf6,0xd8,0x86,0x68,0x4f,0xea,0x96,0x0c, | ||
0x00,0x26,0xb4,0x45,0x14,0xdc,0x86,0x68,0x32,0x44,0x86,0x68,0x34,0x44,0xd8,0xf8, | ||
0x00,0x60,0x16,0xf0,0x01,0x06,0xfa,0xd1,0xd8,0xf8,0x00,0x70,0x17,0xf4,0x7e,0x0f, | ||
0x0c,0xd0,0x46,0x67,0x00,0x23,0xce,0xf8,0x00,0x30,0x00,0xbe,0xbd,0xe8,0xf0,0x83, | ||
0x54,0xf8,0x26,0x70,0x42,0xf8,0x26,0x70,0x01,0x36,0xe2,0xe7,0xa1,0x42,0x98,0xbf, | ||
0x4c,0x46,0x44,0x67,0x86,0x68,0x01,0x3b,0xad,0x1b,0xd3,0xe7, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.