Skip to content

Commit

Permalink
stm32/octospi: Add support for dual-line SPI interface.
Browse files Browse the repository at this point in the history
And fix the case of 32-bit addresses in single-line mode.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Sep 13, 2023
1 parent ee5e594 commit 60e0ef6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ports/stm32/octospi.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,36 @@ STATIC int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *de
STATIC int octospi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
(void)self_in;

#if defined(MICROPY_HW_OSPIFLASH_IO1) && !defined(MICROPY_HW_OSPIFLASH_IO2) && !defined(MICROPY_HW_OSPIFLASH_IO4)

// Use 2-line address, 2-line data.

uint32_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2;
uint32_t dmode = 2; // data on 2-lines
uint32_t admode = 2; // address on 2-lines
uint32_t dcyc = 4; // 4 dummy cycles

if (cmd == 0xeb || cmd == 0xec) {
// Convert to 2-line command.
cmd = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 0xbc : 0xbb;
}

#else

// Fallback to use 1-line address, 1-line data.

uint32_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2;
uint32_t dmode = 1; // data on 1-line
uint32_t admode = 1; // address on 1-line
uint32_t dcyc = 0; // 0 dummy cycles

if (cmd == 0xeb) {
if (cmd == 0xeb || cmd == 0xec) {
// Convert to 1-line command.
cmd = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 0x13 : 0x03;
}

#endif

OCTOSPI1->FCR = OCTOSPI_FCR_CTCF; // clear TC flag

OCTOSPI1->DLR = len - 1; // number of bytes to read
Expand Down

0 comments on commit 60e0ef6

Please sign in to comment.