|
29 | 29 | #define GPIOC_BASE (0x40020800) |
30 | 30 | #define GPIOD_BASE (0x40020C00) |
31 | 31 | #define GPIOE_BASE (0x40021000) |
32 | | -#define GPIO_BASE GPIOA_BASE |
33 | 32 | #define SPI_GPIO GPIOB_BASE |
34 | 33 | #define SPI_CS_GPIO GPIOE_BASE |
35 | 34 | #define SPI_CS_FLASH 1 /* Flash CS connected to GPIOE1 */ |
|
40 | 39 | #define SPI_MOSI_PIN 5 /* SPI_MOSI PB5 */ |
41 | 40 | #endif /* TARGET_stm32f4 */ |
42 | 41 |
|
| 42 | + |
| 43 | +#ifdef TARGET_stm32h5 |
| 44 | +#include "hal/stm32h5.h" |
| 45 | + |
| 46 | +#define APB2_CLOCK_RST RCC_APB2_CLOCK_RSTR |
| 47 | +#define APB2_CLOCK_ER RCC_APB2_CLOCK_ER |
| 48 | +#define RCC_GPIO_CLOCK_ER RCC_AHB2ENR_CLOCK_ER |
| 49 | + |
| 50 | +/* Nucleo STM32H573ZI SPI_A Port (SPI1) */ |
| 51 | +#define SPI_CLOCK_PIO_BASE GPIOA_BASE |
| 52 | +#define SPI_MISO_PIO_BASE GPIOG_BASE |
| 53 | +#define SPI_MOSI_PIO_BASE GPIOB_BASE |
| 54 | +#define SPI_CS_TPM_PIO_BASE GPIOD_BASE |
| 55 | + |
| 56 | +#define SPI_PIN_AF 5 /* Alternate function for SPI pins */ |
| 57 | +#define SPI_CLOCK_PIN 5 /* SPI_SCK: PA5 */ |
| 58 | +#define SPI_MISO_PIN 9 /* SPI_MISO PG9 */ |
| 59 | +#define SPI_MOSI_PIN 5 /* SPI_MOSI PB5 */ |
| 60 | +#define SPI_CS_TPM 14 /* TPM CS connected to PD14 */ |
| 61 | +#endif /* TARGET_stm32h5 */ |
| 62 | + |
| 63 | + |
43 | 64 | #ifdef TARGET_stm32u5 |
44 | 65 |
|
45 | 66 | #ifdef TZEN |
|
405 | 426 |
|
406 | 427 | #define SPI1_APB2_CLOCK_ER_VAL (1 << 12) |
407 | 428 |
|
| 429 | +#if defined(TARGET_stm32h5) |
| 430 | +/* newer SPI/I2S peripheral */ |
| 431 | +#define SPI1_CR1 (*(volatile uint32_t *)(SPI1_BASE)) |
| 432 | +#define SPI1_CR2 (*(volatile uint32_t *)(SPI1_BASE + 0x04)) |
| 433 | +#define SPI1_CFG1 (*(volatile uint32_t *)(SPI1_BASE + 0x08)) |
| 434 | +#define SPI1_CFG2 (*(volatile uint32_t *)(SPI1_BASE + 0x0C)) |
| 435 | +#define SPI1_SR (*(volatile uint32_t *)(SPI1_BASE + 0x14)) |
| 436 | +#define SPI1_IFCR (*(volatile uint32_t *)(SPI1_BASE + 0x18)) |
| 437 | +#define SPI1_TXDR (*(volatile uint8_t *)(SPI1_BASE + 0x20)) |
| 438 | +#define SPI1_RXDR (*(volatile uint8_t *)(SPI1_BASE + 0x30)) |
| 439 | + |
| 440 | +#define SPI_CR1_SPI_EN (1 << 0) |
| 441 | +#define SPI_CR1_MASRX (1 << 8) /* master automatic suspension in Receive mode */ |
| 442 | +#define SPI_CR1_CSTART (1 << 9) /* Continous start */ |
| 443 | +#define SPI_CR1_SSI (1 << 12) /* Internal slave select signal input level */ |
| 444 | +#define SPI_CFG1_DSIZE_MASK (0x1F) |
| 445 | +#define SPI_CFG1_DSIZE_SHIFT (0) |
| 446 | +#define SPI_CFG1_FTHLV_MASK (0x1F) |
| 447 | +#define SPI_CFG1_FTHLV_SHIFT (5) |
| 448 | +#define SPI_CFG1_CRCSIZE_MASK (0x1F) |
| 449 | +#define SPI_CFG1_CRCSIZE_SHIFT (16) |
| 450 | +#define SPI_CFG1_BAUDRATE_MASK (0x07) |
| 451 | +#define SPI_CFG1_BAUDRATE_SHIFT (28) |
| 452 | + |
| 453 | +#define SPI_CFG2_MASTER (1 << 22) |
| 454 | +#define SPI_CFG2_LSBFIRST (1 << 23) |
| 455 | +#define SPI_CFG2_CLOCK_PHASE_SHIFT (24) |
| 456 | +#define SPI_CFG2_CLOCK_POL_SHIFT (25) |
| 457 | +#define SPI_CFG2_SSM (1 << 26) |
| 458 | +#define SPI_CFG2_SSOE (1 << 29) |
| 459 | +#define SPI_CFG2_SSOM (1 << 30) |
| 460 | +#define SPI_CFG2_AFCNTR (1 << 31) /* alternate function GPIOs control */ |
| 461 | +#define SPI_CFG2_COMM_MASK (0x3) /* 0=full duplex, 1=simplex tx, 2=simplex rx, 3=half duplex */ |
| 462 | +#define SPI_CFG2_COMM_SHIFT (17) |
| 463 | + |
| 464 | +#define SPI_IFCR_SUSPC (1 << 11) |
| 465 | +#define SPI_IFCR_MODFC (1 << 9) |
| 466 | +#define SPI_IFCR_TIFREC (1 << 8) |
| 467 | +#define SPI_IFCR_CRCEC (1 << 7) |
| 468 | +#define SPI_IFCR_OVRC (1 << 6) |
| 469 | +#define SPI_IFCR_UDRC (1 << 5) |
| 470 | +#define SPI_IFCR_TXTFC (1 << 4) |
| 471 | +#define SPI_IFCR_EOTC (1 << 3) |
| 472 | + |
| 473 | +#define SPI_SR_RX_NOTEMPTY (1 << 0) |
| 474 | +#define SPI_SR_TX_EMPTY (1 << 1) |
| 475 | + |
| 476 | +#else |
| 477 | + |
| 478 | +/* older SPI peripheral */ |
408 | 479 | #define SPI1_CR1 (*(volatile uint32_t *)(SPI1_BASE)) |
409 | 480 | #define SPI1_CR2 (*(volatile uint32_t *)(SPI1_BASE + 0x04)) |
410 | 481 | #define SPI1_SR (*(volatile uint32_t *)(SPI1_BASE + 0x08)) |
411 | | -#define SPI1_DR (*(volatile uint32_t *)(SPI1_BASE + 0x0c)) |
| 482 | +#define SPI1_TXDR (*(volatile uint8_t *)(SPI1_BASE + 0x0c)) |
| 483 | +#define SPI1_RXDR (*(volatile uint8_t *)(SPI1_BASE + 0x0c)) |
412 | 484 |
|
413 | | -#define SPI_CR1_CLOCK_PHASE (1 << 0) |
414 | | -#define SPI_CR1_CLOCK_POLARITY (1 << 1) |
| 485 | +#define SPI_CR1_CLOCK_PHASE_SHIFT (0) |
| 486 | +#define SPI_CR1_CLOCK_POL_SHIFT (1) |
415 | 487 | #define SPI_CR1_MASTER (1 << 2) |
416 | | -#define SPI_CR1_BAUDRATE (0x07 << 3) |
| 488 | +#define SPI_CR1_BAUDRATE_MASK (0x07) |
| 489 | +#define SPI_CR1_BAUDRATE_SHIFT (3) |
417 | 490 | #define SPI_CR1_SPI_EN (1 << 6) |
418 | 491 | #define SPI_CR1_LSBFIRST (1 << 7) |
419 | 492 | #define SPI_CR1_SSI (1 << 8) |
|
428 | 501 | #define SPI_SR_TX_EMPTY (1 << 1) |
429 | 502 | #define SPI_SR_BUSY (1 << 7) |
430 | 503 |
|
| 504 | +#endif |
431 | 505 |
|
432 | 506 | /* GPIO */ |
433 | 507 | #define GPIO_MODE(base) (*(volatile uint32_t *)(base + 0x00)) /* GPIOx_MODER */ |
|
438 | 512 | #define GPIO_BSRR(base) (*(volatile uint32_t *)(base + 0x18)) /* GPIOx_BSRR */ |
439 | 513 | #define GPIO_AFL(base) (*(volatile uint32_t *)(base + 0x20)) /* GPIOx_AFRL */ |
440 | 514 | #define GPIO_AFH(base) (*(volatile uint32_t *)(base + 0x24)) /* GPIOx_AFRH */ |
| 515 | +#ifndef GPIO_SECCFGR |
| 516 | +#define GPIO_SECCFGR(base) (*(volatile uint32_t *)(base + 0x30)) /* GPIOx_SECCFGR */ |
| 517 | +#endif |
441 | 518 |
|
442 | 519 | #define GPIO_MODE_INPUT (0) |
443 | 520 | #define GPIO_MODE_OUTPUT (1) |
|
0 commit comments