Skip to content

Commit

Permalink
Added support for STM32H7 devices (from git://git.ac6.fr/openocd)
Browse files Browse the repository at this point in the history
OpenOCD can now locate the scripts directory when launched from arbitrary location
  • Loading branch information
sysprogs committed Aug 21, 2017
1 parent 317fe81 commit 1e2be7e
Show file tree
Hide file tree
Showing 12 changed files with 2,672 additions and 475 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ find_path(HIDAPI_INCLUDE_DIR hidapi.h
HINTS ${CMAKE_SYSTEM_INCLUDE_PATH} c:/mingw/include
PATH_SUFFIXES hidapi)

add_definitions(-DHAVE_CONFIG_H -DPKGDATADIR="." -DBINDIR="../../bin")
add_definitions(-DHAVE_CONFIG_H -DPKGDATADIR="../../share/openocd" -DBINDIR="../../bin")
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUSB1_INCLUDE_DIR} ${HIDAPI_INCLUDE_DIR})
set(CMAKE_C_FLAGS "-std=gnu99")

Expand Down
108 changes: 108 additions & 0 deletions contrib/loaders/flash/stm32h7x.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/***************************************************************************
* Copyright (C) 2010 by Spencer Oliver *
* spen@spen-soft.co.uk *
* *
* Copyright (C) 2011 Øyvind Harboe *
* oyvind.harboe@zylin.com *
* *
* Copyright (C) 2015 Uwe Bonnes *
* bon@elektron.ikp.physik.tu-darmstadt.de *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc. *
***************************************************************************/

.text
.syntax unified
.cpu cortex-m4
.thumb
.thumb_func

/* To assemble:
* arm-none-eabi-gcc -c stm32h7x.S
*
* To disassemble:
* arm-none-eabi-objdump -o stm32h7x.o
*
* To generate binary file:
* arm-none-eabi-objcopy -O binary stm32h7x.o stm32h7_flash_write_code.bin
*
* To generate include file:
* xxd -i stm32h7_flash_write_code.bin
*/

/*
* Params :
* r0 = workarea start, status (out)
* r1 = workarea end
* r2 = target address
* r3 = count (256 bit words)
* r4 = flash reg base
*
* Clobbered:
* r5 - index for loop
* r6 - temp
* r7 - rp
* r8 - wp, tmp
*/

#define STM32_FLASH_CR_OFFSET 0x0C /* offset of CR register in FLASH struct */
#define STM32_FLASH_SR_OFFSET 0x10 /* offset of SR register in FLASH struct */
#define STM32_PROG 0x32 /* Flash CR = PSIZE64 | PG */

wait_fifo:
ldr r8, [r0, #0] /* read wp */
cmp r8, #0 /* abort if wp == 0 */
beq exit
ldr r7, [r0, #4] /* read rp */
subs r6, r8, r7 /* number of bytes available for read in r6 */
itt mi /* if wrapped around*/
addmi r6, r1 /* add size of buffer */
submi r6, r0
cmp r6, #32 /* wait until 32 bytes are available */
bcc wait_fifo

mov r6, #STM32_PROG
str r6, [r4, #STM32_FLASH_CR_OFFSET]

mov r5, #8 /* program by 8 words = 32 bytes */
write_flash:
ldr r6, [r7], #0x04 /* read one word from src, increment ptr */
str r6, [r2], #0x04 /* write one word to dst, increment ptr */
dsb
subs r5, r5, #1 /* decrement index */
bne write_flash /* loop if not done */

busy:
ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
tst r6, #0x1 /* BSY (bit1) == 1 => operation in progress */
bne busy /* wait more... */
tst r6, #0x01ee0000 /* SNECCERR | RDSERR | RDPERR | OPERR | INCERR | STRBERR | PGSERR | WRPERR */
bne error /* fail... */
tst r6, #0x02000000 /* DBECCERR */
bne error /* fail... */

cmp r7, r1 /* wrap rp at end of buffer */
it cs
addcs r7, r0, #8 /* skip loader args */
str r7, [r0, #4] /* store rp */
subs r3, r3, #1 /* decrement count */
cbz r3, exit /* loop if not done */
b wait_fifo
error:
movs r1, #0
str r1, [r0, #4] /* set rp = 0 on error */
exit:
mov r0, r6 /* return status in r0 */
bkpt #0x00
76 changes: 43 additions & 33 deletions contrib/loaders/flash/stm32l4x.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

.text
.syntax unified
.cpu cortex-m4
.cpu cortex-m0
.thumb
.thumb_func

Expand All @@ -52,49 +52,59 @@
*
* Clobbered:
* r5 - rp
* r6/7 - temp (64-bit)
* r8 - wp, tmp
* r6 - temp
* r7 - wp
*/

#define STM32_FLASH_CR_OFFSET 0x14 /* offset of CR register in FLASH struct */
#define STM32_FLASH_SR_OFFSET 0x10 /* offset of SR register in FLASH struct */

wait_fifo:
ldr r8, [r0, #0] /* read wp */
cmp r8, #0 /* abort if wp == 0 */
beq exit
ldr r5, [r0, #4] /* read rp */
subs r6, r8, r5 /* number of bytes available for read in r6*/
itt mi /* if wrapped around*/
addmi r6, r1 /* add size of buffer */
submi r6, r0
cmp r6, #8 /* wait until 8 bytes are available */
bcc wait_fifo
ldr r7, [r0, #0] /* read wp */
cmp r7, #0 /* abort if wp == 0 */
beq exit
ldr r5, [r0, #4] /* read rp */
subs r6, r7, r5 /* number of bytes available for read in r6 */
bmi negative /* if wrapped around, add size of buffer */
positive:
cmp r6, #8 /* wait until 8 bytes are available */
bcc wait_fifo

ldr r6, STM32_PROG
str r6, [r4, #STM32_FLASH_CR_OFFSET]
ldrd r6, [r5], #0x08 /* read one word from src, increment ptr */
strd r6, [r2], #0x08 /* write one word to dst, increment ptr */
movs r6, #1 /* FLASH_CR = 1 (Set PROG bit) */
str r6, [r4, #STM32_FLASH_CR_OFFSET]
ldmia r5!, {r6} /* read 1st word from src, increment ptr */
stmia r2!, {r6} /* write 1st word to dest, increment ptr */
dsb
ldmia r5!, {r6} /* read 2nd word from src, increment ptr */
stmia r2!, {r6} /* write 2nd word to dest, increment ptr */
dsb
busy:
ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
tst r6, #0x10000 /* BSY (bit16) == 1 => operation in progress */
bne busy /* wait more... */
tst r6, #0xfa /* PGSERR | PGPERR | PGAERR | WRPERR | PROGERR*/
bne error /* fail... */
ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
lsrs r6, #17 /* BSY (bit16) == 1 => operation in progress */
bcs busy /* wait more... */
ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
uxtb r6, r6 /* isolate error flags byte */
cmp r6, #0 /* PGSERR | SIZERR | PGAERR | WRPERR | PROGERR | OPERR */
bne error /* fail... */

cmp r5, r1 /* wrap rp at end of buffer */
it cs
addcs r5, r0, #8 /* skip loader args */
str r5, [r0, #4] /* store rp */
subs r3, r3, #1 /* decrement dword count */
cbz r3, exit /* loop if not done */
b wait_fifo
cmp r5, r1 /* wrap rp at end of buffer */
bcs superior
inferior:
str r5, [r0, #4] /* store rp */
subs r3, r3, #1 /* decrement dword count */
beq exit /* loop if not done */
b wait_fifo
negative:
add r6, r6, r1 /* add size of buffer */
subs r6, r0
b positive
superior:
mov r5, r0 /* wrap rp (rp = r0 +8) */
adds r5, r5, #8 /* +8 to skip loader args */
b inferior
error:
movs r1, #0
str r1, [r0, #4] /* set rp = 0 on error */
str r1, [r0, #4] /* set rp = 0 on error */
exit:
mov r0, r6 /* return status in r0 */
mov r0, r6 /* return status in r0 */
bkpt #0x00

STM32_PROG: .word 0x1 /* PG */
35 changes: 20 additions & 15 deletions contrib/loaders/flash/stm32lx.S
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* Copyright (C) 2011 Clement Burin des Roziers *
* clement.burin-des-roziers@hikob.com *
* *
* Copyright (C) 2017 Armin van der Togt *
* armin@otheruse.nl *
* Copyright (C) 2016 Cezary Gapiński *
* cezary.gapinski@gmail.com *
* *
* 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 *
Expand Down Expand Up @@ -39,24 +39,29 @@
/*
r0 - destination address
r1 - source address
r2 - count
r2 - count to write
r3 - count written
r4 - temp
*/

// r2 = source + count * 4
lsls r2, r2, #2
adds r2, r1, r2
// Set 0 to r3
movs r3, #0
// Go to compare
b test_done
b test_done

write_word:
// load word from address in r1 and increase r1 by 4
ldmia r1!, {r3}
// store word to address in r0 and increase r0 by 4
stmia r0!, {r3}
// Load one word from address in r1 to r4, increment r1
ldmia r1!, {r4}
// Store the word to address in r0 from r4, increment r0
stmia r0!, {r4}
// Increment r3
adds r3, #1

test_done:
// compare r1 and r2
cmp r1, r2
// loop if not equal
bne write_word
// Compare r3 and r2
cmp r3, r2
// Loop if not zero
bcc write_word

// Set breakpoint to exit
bkpt #0x00
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/helper ${CMAKE_CURRENT_SOURCE_DIR}/../jimtcl ${CMAKE_CURRENT_BINARY_DIR}/../jimtcl-cmake ${CMAKE_CURRENT_BINARY_DIR})

add_library(helper helper/binarybuffer.c helper/options.c helper/time_support_common.c helper/configuration.c helper/log.c helper/command.c helper/time_support.c helper/replacements.c helper/fileio.c helper/util.c helper/jim-nvp.c helper/ioutil_stubs.c helper/jep106.c )
add_library(helper helper/binarybuffer.c helper/options.c helper/time_support_common.c helper/configuration.c helper/log.c helper/command.c helper/time_support.c helper/replacements.c helper/fileio.c helper/util.c helper/jim-nvp.c helper/ioutil_stubs.c helper/jep106.c helper/unicode.c)

add_library(transport transport/transport.c)
add_library(svf svf/svf.c)
Expand Down
1 change: 1 addition & 0 deletions src/flash/nor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_library(ocdflashnor
msp432p4.c
stm32f1x.c
stm32f2x.c
stm32h7x.c
stm32l4x.c
stm32lx.c
stmsmi.c
Expand Down
2 changes: 2 additions & 0 deletions src/flash/nor/drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern struct flash_driver stm32f1x_flash;
extern struct flash_driver stm32f2x_flash;
extern struct flash_driver stm32lx_flash;
extern struct flash_driver stm32l4x_flash;
extern struct flash_driver stm32h7x_flash;
extern struct flash_driver stmsmi_flash;
extern struct flash_driver str7x_flash;
extern struct flash_driver str9x_flash;
Expand Down Expand Up @@ -115,6 +116,7 @@ static struct flash_driver *flash_drivers[] = {
&stm32f2x_flash,
&stm32lx_flash,
&stm32l4x_flash,
&stm32h7x_flash,
&stmsmi_flash,
&str7x_flash,
&str9x_flash,
Expand Down
Loading

0 comments on commit 1e2be7e

Please sign in to comment.