Skip to content

Commit 4992d16

Browse files
committed
feat(spiflash): add initial structure for SPI Flash support: H2, C6, C2, C5, P4, C61
1 parent 73a2d80 commit 4992d16

File tree

19 files changed

+215
-42
lines changed

19 files changed

+215
-42
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdbool.h>
10+
#include <stdint.h>
11+
12+
#include <log.h>
13+
14+
/**
15+
* @brief SPI Flash init. CONFIG SPI is unsupported
16+
*
17+
* @param spiconfig: Deprecated compatibility API value, must be 0
18+
*
19+
* @param legacy: Deprecated compatibility API value, must be false
20+
*
21+
*/
22+
extern void esp_rom_spiflash_attach(uint32_t spiconfig, bool legacy);
23+
24+
inline static
25+
void flash_impl_init_no_spiconfig(void)
26+
{
27+
STUB_LOG_TRACE();
28+
esp_rom_spiflash_attach(0, false);
29+
}

src/esp32c2/include/soc/spi_mem_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#pragma once
77

8-
#include <private/soc_utils.h>
8+
#include <bit_utils.h>
99
#include "reg_base.h"
1010

1111
#define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <soc/spi_mem_reg.h>
10+
11+
#define PERIPHS_SPI_FLASH_CMD SPI_MEM_CMD_REG(1)
12+
#define PERIPHS_SPI_FLASH_C0 SPI_MEM_W0_REG(1)
13+
14+
#define PERIPHS_SPI_FLASH_BITS_RDID SPI_MEM_FLASH_RDID

src/esp32c2/src/flash.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
66

7+
#include <stdint.h>
8+
#include <log.h>
79
#include <target/flash.h>
10+
#include <target/impl/flash_init_no_spiconfig.h>
11+
#include <target/impl/flash_get_id_from_rom.h>
12+
#include <target/impl/flash_get_config_from_rom.h>
813

9-
void stub_target_flash_init(void *state)
14+
void stub_target_flash_init(void)
1015
{
11-
(void)state;
12-
// TODO: Implement
16+
STUB_LOG_TRACE();
17+
flash_impl_init_no_spiconfig();
1318
}
1419

15-
void stub_target_flash_deinit(const void *state)
20+
uint32_t stub_target_flash_get_flash_id(void)
1621
{
17-
(void)state;
18-
// TODO: Implement
22+
STUB_LOG_TRACE();
23+
return flash_impl_get_id_from_rom();
24+
}
25+
26+
const esp_rom_spiflash_chip_t * stub_target_flash_get_config(void)
27+
{
28+
return flash_impl_get_config_from_rom();
1929
}

src/esp32c5/include/soc/spi1_mem_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#pragma once
77

8-
#include <private/soc_utils.h>
8+
#include <bit_utils.h>
99
#include "reg_base.h"
1010

1111
#define REG_SPI_MEM_BASE(i) (DR_REG_SPIMEM0_BASE + (i) * 0x1000) // SPIMEM0 and SPIMEM1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <soc/spi1_mem_reg.h>
10+
11+
#define PERIPHS_SPI_FLASH_CMD SPI_MEM_CMD_REG(1)
12+
#define PERIPHS_SPI_FLASH_C0 SPI_MEM_W0_REG(1)
13+
14+
#define PERIPHS_SPI_FLASH_BITS_RDID SPI_MEM_FLASH_RDID

src/esp32c5/src/flash.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
66

7+
#include <stdint.h>
8+
#include <log.h>
79
#include <target/flash.h>
10+
#include <target/impl/flash_init_no_spiconfig.h>
11+
#include <target/impl/flash_get_id_from_rom.h>
12+
#include <target/impl/flash_get_config_from_rom.h>
813

9-
void stub_target_flash_init(void *state)
14+
void stub_target_flash_init(void)
1015
{
11-
(void)state;
12-
// TODO: Implement
16+
STUB_LOG_TRACE();
17+
flash_impl_init_no_spiconfig();
1318
}
1419

15-
void stub_target_flash_deinit(const void *state)
20+
uint32_t stub_target_flash_get_flash_id(void)
1621
{
17-
(void)state;
18-
// TODO: Implement
22+
STUB_LOG_TRACE();
23+
return flash_impl_get_id_from_rom();
24+
}
25+
26+
const esp_rom_spiflash_chip_t * stub_target_flash_get_config(void)
27+
{
28+
return flash_impl_get_config_from_rom();
1929
}

src/esp32c6/include/soc/spi_mem_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#pragma once
77

8-
#include <private/soc_utils.h>
8+
#include <bit_utils.h>
99
#include "reg_base.h"
1010

1111
#define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE + (i) * 0x1000) // SPIMEM0 and SPIMEM1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <soc/spi_mem_reg.h>
10+
11+
#define PERIPHS_SPI_FLASH_CMD SPI_MEM_CMD_REG(1)
12+
#define PERIPHS_SPI_FLASH_C0 SPI_MEM_W0_REG(1)
13+
14+
#define PERIPHS_SPI_FLASH_BITS_RDID SPI_MEM_FLASH_RDID

src/esp32c6/src/flash.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
66

7+
#include <stdint.h>
8+
#include <log.h>
79
#include <target/flash.h>
10+
#include <target/impl/flash_init_no_spiconfig.h>
11+
#include <target/impl/flash_get_id_from_rom.h>
12+
#include <target/impl/flash_get_config_from_rom.h>
813

9-
void stub_target_flash_init(void *state)
14+
void stub_target_flash_init(void)
1015
{
11-
(void)state;
12-
// TODO: Implement
16+
STUB_LOG_TRACE();
17+
flash_impl_init_no_spiconfig();
1318
}
1419

15-
void stub_target_flash_deinit(const void *state)
20+
uint32_t stub_target_flash_get_flash_id(void)
1621
{
17-
(void)state;
18-
// TODO: Implement
22+
STUB_LOG_TRACE();
23+
return flash_impl_get_id_from_rom();
24+
}
25+
26+
const esp_rom_spiflash_chip_t * stub_target_flash_get_config(void)
27+
{
28+
return flash_impl_get_config_from_rom();
1929
}

0 commit comments

Comments
 (0)