|
40 | 40 | #define SPI_MOSI_PIN 5 /* SPI_MOSI PB5 */ |
41 | 41 | #endif /* TARGET_stm32f4 */ |
42 | 42 |
|
| 43 | + |
| 44 | +#ifdef TARGET_stm32h5 |
| 45 | +#include "hal/stm32h5.h" |
| 46 | + |
| 47 | +#define RCC_GPIO_CLOCK_ER RCC_AHB2ENR_CLOCK_ER |
| 48 | +#define APB2_CLOCK_RST RCC_APB2_CLOCK_RSTR |
| 49 | +#define APB2_CLOCK_ER RCC_APB2_CLOCK_ER |
| 50 | + |
| 51 | +/* Nucleo STM32H573ZI SPI_A Port (SPI1) */ |
| 52 | +#define SPI_CLOCK_PIO_BASE GPIOA_BASE |
| 53 | +#define SPI_MISO_PIO_BASE GPIOG_BASE |
| 54 | +#define SPI_MOSI_PIO_BASE GPIOB_BASE |
| 55 | +#define SPI_CS_TPM_PIO_BASE GPIOD_BASE |
| 56 | + |
| 57 | +#define SPI_PIN_AF 5 /* Alternate function for SPI pins */ |
| 58 | +#define SPI_CLOCK_PIN 5 /* SPI_SCK: PA5 */ |
| 59 | +#define SPI_MISO_PIN 9 /* SPI_MISO PG9 */ |
| 60 | +#define SPI_MOSI_PIN 5 /* SPI_MOSI PB5 */ |
| 61 | +#define SPI_CS_TPM 14 /* TPM CS connected to PD14 */ |
| 62 | +#endif /* TARGET_stm32h5 */ |
| 63 | + |
| 64 | + |
43 | 65 | #ifdef TARGET_stm32u5 |
44 | 66 |
|
45 | 67 | #ifdef TZEN |
|
405 | 427 |
|
406 | 428 | #define SPI1_APB2_CLOCK_ER_VAL (1 << 12) |
407 | 429 |
|
| 430 | +#if defined(TARGET_stm32h5) |
| 431 | +/* newer SPI/I2S peripheral */ |
| 432 | +#define SPI1_CR1 (*(volatile uint32_t *)(SPI1_BASE)) |
| 433 | +#define SPI1_CR2 (*(volatile uint32_t *)(SPI1_BASE + 0x04)) |
| 434 | +#define SPI1_CFG1 (*(volatile uint32_t *)(SPI1_BASE + 0x08)) |
| 435 | +#define SPI1_CFG2 (*(volatile uint32_t *)(SPI1_BASE + 0x0C)) |
| 436 | +#define SPI1_SR (*(volatile uint32_t *)(SPI1_BASE + 0x14)) |
| 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 << 6) |
| 441 | +#define SPI_CR1_CSTART (1 << 9) /* Continous start */ |
| 442 | +#define SPI_CFG1_DSIZE_MASK (0x1F) |
| 443 | +#define SPI_CFG1_DSIZE_SHIFT (0) |
| 444 | + |
| 445 | +#define SPI_CFG1_FTHLV_MASK (0x1F) |
| 446 | +#define SPI_CFG1_FTHLV_SHIFT (5) |
| 447 | + |
| 448 | +#define SPI_CFG1_BAUDRATE_MASK (0x07) |
| 449 | +#define SPI_CFG1_BAUDRATE_SHIFT (28) |
| 450 | + |
| 451 | +#define SPI_CRF2_MASTER (1 << 22) |
| 452 | +#define SPI_CFG2_LSBFIRST (1 << 23) |
| 453 | +#define SPI_CFG2_CLOCK_PHASE_SHIFT (24) |
| 454 | +#define SPI_CFG2_CLOCK_POL_SHIFT (25) |
| 455 | +#define SPI_CFG2_SSM (1 << 26) |
| 456 | +#define SPI_CFG2_SSOE (1 << 29) |
| 457 | +#define SPI_CFG2_HW_CRC_EN (1 << 29) |
| 458 | +#define SPI_CFG2_COMM_MASK (0x3) /* 0=full duplex, 1=simplex tx, 2=simplex rx, 3=half duplex */ |
| 459 | +#define SPI_CFG2_COMM_SHIFT (17) |
| 460 | + |
| 461 | +#define SPI_SR_RX_NOTEMPTY (1 << 0) |
| 462 | +#define SPI_SR_TX_EMPTY (1 << 1) |
| 463 | + |
| 464 | +#else |
| 465 | + |
| 466 | +/* older SPI peripheral */ |
408 | 467 | #define SPI1_CR1 (*(volatile uint32_t *)(SPI1_BASE)) |
409 | 468 | #define SPI1_CR2 (*(volatile uint32_t *)(SPI1_BASE + 0x04)) |
410 | 469 | #define SPI1_SR (*(volatile uint32_t *)(SPI1_BASE + 0x08)) |
411 | | -#define SPI1_DR (*(volatile uint32_t *)(SPI1_BASE + 0x0c)) |
| 470 | +#define SPI1_DR (*(volatile uint8_t *)(SPI1_BASE + 0x0c)) |
412 | 471 |
|
413 | | -#define SPI_CR1_CLOCK_PHASE (1 << 0) |
414 | | -#define SPI_CR1_CLOCK_POLARITY (1 << 1) |
| 472 | +#define SPI_CR1_CLOCK_PHASE_SHIFT (0) |
| 473 | +#define SPI_CR1_CLOCK_POL_SHIFT (1) |
415 | 474 | #define SPI_CR1_MASTER (1 << 2) |
416 | | -#define SPI_CR1_BAUDRATE (0x07 << 3) |
| 475 | +#define SPI_CR1_BAUDRATE_MASK (0x07) |
| 476 | +#define SPI_CR1_BAUDRATE_SHIFT (3) |
417 | 477 | #define SPI_CR1_SPI_EN (1 << 6) |
418 | 478 | #define SPI_CR1_LSBFIRST (1 << 7) |
419 | 479 | #define SPI_CR1_SSI (1 << 8) |
|
428 | 488 | #define SPI_SR_TX_EMPTY (1 << 1) |
429 | 489 | #define SPI_SR_BUSY (1 << 7) |
430 | 490 |
|
| 491 | +#endif |
431 | 492 |
|
432 | 493 | /* GPIO */ |
433 | 494 | #define GPIO_MODE(base) (*(volatile uint32_t *)(base + 0x00)) /* GPIOx_MODER */ |
|
0 commit comments