1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # This is a stm32h7b3i-dk with a single STM32H7B3LIH6Q chip.
4 # https://www.st.com/en/evaluation-tools/stm32h7b3i-dk.html
7 # This is for using the onboard STLINK
8 source [find interface/stlink.cfg]
10 transport select hla_swd
12 set CHIPNAME stm32h7b3lih6q
15 if {![info exists OCTOSPI1]} {
20 source [find target/stm32h7x_dual_bank.cfg]
22 reset_config srst_only
24 # OCTOSPI initialization
26 proc octospi_init { octo } {
28 mmw 0x58024540 0x000007FF 0 ;# RCC_AHB4ENR |= GPIOAEN-GPIOKEN (enable clocks)
29 mmw 0x58024534 0x00284000 0 ;# RCC_AHB3ENR |= IOMNGREN, OSPI2EN, OSPI1EN (enable clocks)
30 sleep 1 ;# Wait for clock startup
32 mww 0x5200B404 0x03010111 ;# OCTOSPIM_P1CR: assign Port 1 to OCTOSPI1
33 mww 0x5200B408 0x00000000 ;# OCTOSPIM_P2CR: disable Port 2
35 # PG06: OCSPI1_NCS, PB02: OCSPI1_CLK, PC05: OCSPI1_DQS, PD07: OCSPI1_IO7, PG09: OCSPI1_IO6, PH03: OCSPI1_IO5,
36 # PC01: OCSPI1_IO4, PF06: OCSPI1_IO3, PF07: OCSPI1_IO2, PF09: OCSPI1_IO1, PD11: OCSPI1_IO0
38 # PB02:AF09:V, PC05:AF10:V, PC01:AF10:V, PD11:AF09:V, PD07:AF10:V, PF09:AF10:V
39 # PF07:AF10:V, PF06:AF10:V, PG09:AF09:V, PG06:AF10:V, PH03:AF09:V
41 mmw 0x58020400 0x00000020 0x00000010 ;# MODER
42 mmw 0x58020408 0x00000030 0x00000000 ;# OSPEEDR
43 mmw 0x5802040C 0x00000000 0x00000030 ;# PUPDR
44 mmw 0x58020420 0x00000900 0x00000600 ;# AFRL
45 # Port C: PC05:AF10:V, PC01:AF10:V
46 mmw 0x58020800 0x00000808 0x00000404 ;# MODER
47 mmw 0x58020808 0x00000C0C 0x00000000 ;# OSPEEDR
48 mmw 0x5802080C 0x00000000 0x00000C0C ;# PUPDR
49 mmw 0x58020820 0x00A000A0 0x00500050 ;# AFRL
50 # Port D: PD11:AF09:V, PD07:AF10:V
51 mmw 0x58020C00 0x00808000 0x00404000 ;# MODER
52 mmw 0x58020C08 0x00C0C000 0x00000000 ;# OSPEEDR
53 mmw 0x58020C0C 0x00000000 0x00C0C000 ;# PUPDR
54 mmw 0x58020C20 0xA0000000 0x50000000 ;# AFRL
55 mmw 0x58020C24 0x00009000 0x00006000 ;# AFRH
56 # Port F: PF09:AF10:V, PF07:AF10:V, PF06:AF10:V
57 mmw 0x58021400 0x0008A000 0x00045000 ;# MODER
58 mmw 0x58021408 0x000CF000 0x00000000 ;# OSPEEDR
59 mmw 0x5802140C 0x00000000 0x000CF000 ;# PUPDR
60 mmw 0x58021420 0xAA000000 0x55000000 ;# AFRL
61 mmw 0x58021424 0x000000A0 0x00000050 ;# AFRH
62 # Port G: PG09:AF09:V, PG06:AF10:V
63 mmw 0x58021800 0x00082000 0x00041000 ;# MODER
64 mmw 0x58021808 0x000C3000 0x00000000 ;# OSPEEDR
65 mmw 0x5802180C 0x00000000 0x000C3000 ;# PUPDR
66 mmw 0x58021820 0x0A000000 0x05000000 ;# AFRL
67 mmw 0x58021824 0x00000090 0x00000060 ;# AFRH
69 mmw 0x58021C00 0x00000080 0x00000040 ;# MODER
70 mmw 0x58021C08 0x000000C0 0x00000000 ;# OSPEEDR
71 mmw 0x58021C0C 0x00000000 0x000000C0 ;# PUPDR
72 mmw 0x58021C20 0x00009000 0x00006000 ;# AFRL
74 # OCTOSPI1: memory-mapped 1-line read mode with 4-byte addresses
75 mww 0x52005130 0x00001000 ;# OCTOSPI_LPTR: deactivate CS after 4096 clocks when FIFO is full
76 mww 0x52005000 0x3040000B ;# OCTOSPI_CR: FMODE=0x1, APMS=1, FTHRES=0, FSEL=0, DQM=0, TCEN=0
77 mww 0x52005008 0x01190100 ;# OCTOSPI_DCR1: MTYP=0x1, FSIZE=0x19, CSHT=0x01, CKMODE=0, DLYBYP=0
78 mww 0x5200500C 0x00000005 ;# OCTOSPI_DCR2: PRESCALER=5
80 mww 0x52005108 0x00000000 ;# OCTOSPI_TCR: SSHIFT=0, DHQC=0, DCYC=0x0
81 mww 0x52005100 0x01003101 ;# OCTOSPI_CCR: DMODE=0x1, ABMODE=0x0, ADSIZE=0x3, ADMODE=0x1, ISIZE=0x0, IMODE=0x1
82 mww 0x52005110 0x00000013 ;# OCTOSPI_IR: INSTR=READ4B
84 flash probe $a ;# load configuration from CR, TCR, CCR, IR register values
87 stmqspi cmd $a 1 0x71 0x00 0x00 0x00 0x00 ;# Read Conf. Reg. 2, addr 0x00000000: DOPI, SOPI bits
88 stmqspi cmd $a 0 0x06 ;# Write Enable
89 stmqspi cmd $a 1 0x05 ;# Read Status Register
90 stmqspi cmd $a 0 0x72 0x00 0x00 0x00 0x00 0x02 ;# Write Conf. Reg. 2, addr 0x00000000: DTR OPI enable
92 # OCTOSPI1: memory-mapped 8-line read mode with 4-byte addresses
93 mww 0x52005000 0x3040000B ;# OCTOSPI_CR: FMODE=0x3, APMS=1, FTHRES=0, FSEL=0, DQM=0, TCEN=1, EN=1
94 mww 0x52005108 0x10000006 ;# OCTOSPI_TCR: SSHIFT=0, DHQC=1, DCYC=0x6
95 mww 0x52005100 0x2C003C1C ;# OCTOSPI_CCR: DTR, DMODE=0x4, ABMODE=0x0, ADSIZE=0x3, ADMODE=0x4, ISIZE=0x1, IMODE=0x4
96 mww 0x52005110 0x0000EE11 ;# OCTOSPI_IR: INSTR=OCTA DTR Read
98 flash probe $a ;# reload configuration from CR, TCR, CCR, IR register values
100 stmqspi cmd $a 0 0x06 ;# Write Enable
101 stmqspi cmd $a 1 0x05 0x00 0x00 0x00 0x00 ;# Read Status Register (note dummy address in 8-line mode)
102 stmqspi cmd $a 0 0x04 ;# Write Disable
103 stmqspi cmd $a 1 0x05 0x00 0x00 0x00 0x00 ;# Read Status Register (note dummy address in 8-line mode)
104 stmqspi cmd $a 1 0x71 0x00 0x00 0x00 0x00 ;# Read Conf. Reg. 2, addr 0x00000000: DOPI, SOPI bits
108 $_CHIPNAME.cpu0 configure -event reset-init {
112 mmw 0x52002000 0x00000004 0x0000000B ;# FLASH_ACR: 4 WS for 192 MHZ HCLK
114 mmw 0x58024400 0x00000001 0x00000018 ;# RCC_CR: HSIDIV=1, HSI on
115 mmw 0x58024410 0x10000000 0xEE000007 ;# RCC_CFGR: MCO2=system, MCO2PRE=8, HSI as system clock
116 mww 0x58024418 0x00000040 ;# RCC_D1CFGR: D1CPRE=1, D1PPRE=2, HPRE=1
117 mww 0x5802441C 0x00000440 ;# RCC_D2CFGR: D2PPRE2=2, D2PPRE1=2
118 mww 0x58024420 0x00000040 ;# RCC_D3CFGR: D3PPRE=2
119 mww 0x58024428 0x00000040 ;# RCC_PPLCKSELR: DIVM3=0, DIVM2=0, DIVM1=4, PLLSRC=HSI
120 mmw 0x5802442C 0x0001000C 0x00000002 ;# RCC_PLLCFGR: PLL1RGE=8MHz to 16MHz, PLL1VCOSEL=wide
121 mww 0x58024430 0x01070217 ;# RCC_PLL1DIVR: 192 MHz: DIVR1=2, DIVQ=8, DIVP1=2, DIVN1=24
122 mmw 0x58024400 0x01000000 0 ;# RCC_CR: PLL1ON=1
124 mmw 0x58024410 0x00000003 0 ;# RCC_CFGR: PLL1 as system clock