Skip to content

Commit f493526

Browse files
authored
Merge pull request #460 from danielinux/stm32u5_spi
[QSPI] Fixed registers and pin config on STM32U5
2 parents d11accc + 7b5012b commit f493526

File tree

4 files changed

+96
-12
lines changed

4 files changed

+96
-12
lines changed

config/examples/stm32u5.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ NO_ASM?=0
1111
NO_MPU=1
1212
EXT_FLASH?=0
1313
SPI_FLASH?=0
14+
QSPI_FLASH?=0
15+
OCTOSPI_FLASH?=0
1416
ALLOW_DOWNGRADE?=0
1517
NVM_FLASH_WRITEONCE?=1
1618
WOLFBOOT_VERSION?=1

docs/Targets.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ ST-LINK_gdbserver -d -cp /opt/st/stm32cubeide_1.3.0/plugins/com.st.stm32cube.ide
358358
Max OS/X:
359359

360360
```sh
361-
sudo ln -s /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.macos64_1.6.0.202101291314/tools/bin/native/mac_x64/libSTLinkUSBDriver.dylib /usr/local/lib/libSTLinkUSBDriver.dylib
362-
363-
/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.macos64_1.6.0.202101291314/tools/bin/ST-LINK_gdbserver -d -cp ./Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.macos64_1.6.0.202101291314/tools/bin -e -r 1 -p 3333
361+
/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.macos64_2.1.300.202403291623/tools/bin/ST-LINK_gdbserver -d -cp /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.macos64_2.1.201.202404072231/tools/bin -e -r 1 -p 3333
364362
```
365363

366364
Win:
@@ -375,6 +373,7 @@ wolfBoot has a .gdbinit to configure
375373
add-symbol-file test-app/image.elf
376374
```
377375

376+
378377
## STM32L0
379378

380379
Example 192KB partitioning on STM32-L073

hal/spi/spi_drv_stm32.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,13 @@ static void stm_pins_release(void)
185185
static void RAMFUNCTION spi_reset(void)
186186
{
187187
#if defined(QSPI_FLASH) || defined(OCTOSPI_FLASH)
188-
AHB3_CLOCK_RST |= RCC_AHB3ENR_QSPIEN;
189-
AHB3_CLOCK_RST &= ~RCC_AHB3ENR_QSPIEN;
188+
#ifndef TARGET_stm32u5
189+
AHB3_CLOCK_RST |= RCC_AHB3ENR_QSPIEN;
190+
AHB3_CLOCK_RST &= ~RCC_AHB3ENR_QSPIEN;
191+
#else
192+
AHB2_CLOCK_RST |= RCC_AHB2ENR_QSPIEN;
193+
AHB2_CLOCK_RST &= ~RCC_AHB2ENR_QSPIEN;
194+
#endif
190195
#endif
191196
#if defined(SPI_FLASH) || defined(WOLFBOOT_TPM)
192197
APB2_CLOCK_RST |= SPI1_APB2_CLOCK_ER_VAL;
@@ -390,13 +395,21 @@ void RAMFUNCTION spi_init(int polarity, int phase)
390395
if (!initialized) {
391396
initialized++;
392397

393-
/* Setup clocks */
398+
/* Setup clocks */
394399
#if defined(QSPI_FLASH) || defined(OCTOSPI_FLASH)
400+
401+
#ifdef PLATFORM_stm32u5
402+
/* Clock configuration for QSPI defaults to SYSCLK
403+
* (RM0456 section 11.8.47)
404+
*/
405+
#else
395406
/* Select QUADSPI clock source */
396407
RCC_D1CCIPR &= ~RCC_D1CCIPR_QSPISEL_MASK;
397408
RCC_D1CCIPR |= RCC_D1CCIPR_QSPISEL(QSPI_CLOCK_SEL);
398409
AHB3_CLOCK_EN |= RCC_AHB3ENR_QSPIEN;
410+
#endif
399411
#endif
412+
400413
#if defined(SPI_FLASH) || defined(WOLFBOOT_TPM)
401414
APB2_CLOCK_ER |= SPI1_APB2_CLOCK_ER_VAL;
402415
#endif

hal/spi/spi_drv_stm32.h

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,37 @@
4040
#define SPI_MOSI_PIN 5 /* SPI_MOSI PB5 */
4141
#endif /* PLATFORM_stm32f4 */
4242

43-
4443
#ifdef PLATFORM_stm32u5
44+
4545
#ifdef TZEN
4646
#define PERIPH_BASE (0x50000000UL)
4747
#else
4848
#define PERIPH_BASE (0x40000000UL)
4949
#endif
5050

51-
#define APB2PERIPH_BASE (PERIPH_BASE + 0x00010000UL)
52-
#define AHB2PERIPH_BASE (PERIPH_BASE + 0x02020000UL)
51+
#define OCTOSPI1_BASE (PERIPH_BASE + 0x020D1400UL)
52+
#define OCTOSPI2_BASE (PERIPH_BASE + 0x020D2400UL)
5353

54-
#define SPI1_BASE (APB2PERIPH_BASE + 0x3000UL)
54+
#ifndef OCTOSPI_BASE
55+
#define OCTOSPI_BASE OCTOSPI2_BASE
56+
#endif
5557

56-
#define RCC_BASE (APB2PERIPH_BASE + 0x0C00UL)
58+
/* Registers mapping */
59+
#define APB2PERIPH_BASE (PERIPH_BASE + 0x00012C00UL)
60+
#define RCC_BASE (PERIPH_BASE + 0x06020C00UL)
61+
#define GPIO_BASE (PERIPH_BASE + 0x02020000UL)
62+
#define AHB2PERIPH_BASE (PERIPH_BASE + 0x02020000UL)
63+
#define SPI1_BASE (APB2PERIPH_BASE + 0x3000UL)
5764
#define APB2_CLOCK_ER (*(volatile uint32_t *)(RCC_BASE + 0xA4))
5865
#define APB2_CLOCK_RST (*(volatile uint32_t *)(RCC_BASE + 0x7C))
66+
#define AHB2_CLOCK_ER (*(volatile uint32_t *)(RCC_BASE + 0x90))
67+
#define AHB2_CLOCK_RST (*(volatile uint32_t *)(RCC_BASE + 0x68))
68+
5969
#define RCC_GPIO_CLOCK_ER (*(volatile uint32_t *)(RCC_BASE + 0x8C))
6070

61-
#define GPIO_BASE (APB2PERIPH_BASE + 0x02020000UL)
71+
72+
#define RCC_AHB2ENR_QSPIEN (1 << 8) /* OCTOSPI2 = bit 8, OCTOSPI1 = bit 4 */
73+
6274
#define GPIOA_BASE (GPIO_BASE + 0x00000UL)
6375
#define GPIOB_BASE (GPIO_BASE + 0x00400UL)
6476
#define GPIOC_BASE (GPIO_BASE + 0x00800UL)
@@ -69,6 +81,64 @@
6981
#define GPIOH_BASE (GPIO_BASE + 0x01C00UL)
7082
#define GPIOI_BASE (GPIO_BASE + 0x02000UL)
7183

84+
/** QSPI **/
85+
/* Default Base (H) and AF (alternate function=5) for QSPI */
86+
#define QSPI_GPIO GPIOH_BASE
87+
#define QSPI_PIN_AF 5
88+
89+
#ifndef QSPI_CLOCK_BASE
90+
#define QSPI_CLOCK_BASE 160000000
91+
#endif
92+
93+
#ifndef QSPI_CLOCK_MHZ
94+
#define QSPI_CLOCK_MHZ 10000000
95+
#endif
96+
97+
/* Default to flash bank 1 */
98+
#ifndef QSPI_FLASH_BANK
99+
#define QSPI_FLASH_BANK 1
100+
#endif
101+
102+
/* Default flash size to 16MB */
103+
#ifndef QSPI_FLASH_SIZE
104+
#define QSPI_FLASH_SIZE 23 /* 2^24 = 16 MB */
105+
#endif
106+
107+
/* QSPI CLK PB2 (alt OCTOSPIM_P1_CLK)*/
108+
#define QSPI_CLOCK_PIO_BASE GPIOH_BASE
109+
#define QSPI_CLOCK_PIN 6
110+
#define QSPI_CLOCK_PIN_AF 5
111+
112+
/* nQSPI_CS PG6 (alt PB6 -> OCTOSPIM_P1_NCS) */
113+
#ifndef QSPI_ALT_CONFIGURATION
114+
#define QSPI_CS_PIO_BASE GPIOH_BASE
115+
#define QSPI_CS_FLASH_PIN 5
116+
#else
117+
#define QSPI_CS_PIO_BASE GPIOH_BASE
118+
#define QSPI_CS_FLASH_PIN 6
119+
#endif
120+
121+
/* QSPI_IO0 */
122+
#define QSPI_IO0_PIO_BASE GPIOH_BASE
123+
#define QSPI_IO0_PIN 9
124+
#define QSPI_IO0_PIN_AF 5
125+
126+
/* QSPI_IO1 */
127+
#define QSPI_IO1_PIO_BASE GPIOH_BASE
128+
#define QSPI_IO1_PIN 10
129+
#define QSPI_IO1_PIN_AF 5
130+
131+
/* QSPI_IO2 */
132+
#define QSPI_IO2_PIO_BASE GPIOH_BASE
133+
#define QSPI_IO2_PIN 11
134+
#define QSPI_IO2_PIN_AF 5
135+
136+
/* QSPI_IO3 */
137+
#define QSPI_IO3_PIO_BASE GPIOH_BASE
138+
#define QSPI_IO3_PIN 12
139+
#define QSPI_IO3_PIN_AF 5
140+
141+
72142
/* STMOD+ Port */
73143
#define SPI_GPIO GPIOE_BASE
74144
#define SPI_CS_GPIO GPIOE_BASE

0 commit comments

Comments
 (0)