Skip to content

Commit

Permalink
Merge branch 'patch/more_patch_for_xmc' into 'master'
Browse files Browse the repository at this point in the history
patch(spi_flash): cleanup XMC flash chip usage according to new information

See merge request espressif/esp-idf!34048
  • Loading branch information
mythbuster5 committed Oct 18, 2024
2 parents fe51222 + 89b9c48 commit 121a272
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ void bootloader_spi_flash_reset(void)

#define XMC_SUPPORT CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT
#define XMC_VENDOR_ID_1 0x20
#define XMC_VENDOR_ID_2 0x46

#if BOOTLOADER_BUILD
#define BOOTLOADER_FLASH_LOG(level, ...) ESP_EARLY_LOG##level(TAG, ##__VA_ARGS__)
Expand All @@ -687,7 +686,7 @@ static IRAM_ATTR bool is_xmc_chip_strict(uint32_t rdid)
uint32_t mfid = BYTESHIFT(rdid, 1);
uint32_t cpid = BYTESHIFT(rdid, 0);

if (vendor_id != XMC_VENDOR_ID_1 && vendor_id != XMC_VENDOR_ID_2) {
if (vendor_id != XMC_VENDOR_ID_1) {
return false;
}

Expand Down Expand Up @@ -720,7 +719,7 @@ esp_err_t IRAM_ATTR bootloader_flash_xmc_startup(void)
// Check the Manufacturer ID in SFDP registers (JEDEC standard). If not XMC chip, no need to run the flow
const int sfdp_mfid_addr = 0x10;
uint8_t mf_id = (bootloader_flash_read_sfdp(sfdp_mfid_addr, 1) & 0xff);
if ((mf_id != XMC_VENDOR_ID_1) && (mf_id != XMC_VENDOR_ID_2)) {
if (mf_id != XMC_VENDOR_ID_1) {
BOOTLOADER_FLASH_LOG(D, "non-XMC chip detected by SFDP Read (%02X), skip.", mf_id);
return ESP_OK;
}
Expand Down Expand Up @@ -752,7 +751,7 @@ esp_err_t IRAM_ATTR bootloader_flash_xmc_startup(void)
static IRAM_ATTR bool is_xmc_chip(uint32_t rdid)
{
uint32_t vendor_id = (rdid >> 16) & 0xFF;
return ((vendor_id == XMC_VENDOR_ID_1) || (vendor_id == XMC_VENDOR_ID_2));
return (vendor_id == XMC_VENDOR_ID_1);
}

esp_err_t IRAM_ATTR bootloader_flash_xmc_startup(void)
Expand Down
11 changes: 11 additions & 0 deletions components/spi_flash/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ menu "Main Flash configuration"
This config is used for setting Tsus parameter. Tsus means CS# high to next command after
suspend. You can refer to the chapter of AC CHARACTERISTICS of flash datasheet.

config SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND
bool "Enable XMC-C series flash chip suspend feature anyway"
default n
help
XMC-C series is regarded as not qualified for the Suspend feature, since its specification
has a tRS >= 1ms restriction. We strongly do not suggest using it for the Suspend feature.
However, if your product in field has enabled this feature, you may still enable this
config option to keep the legacy behavior.

For new users, DO NOT enable this config.

endmenu
endmenu

Expand Down
2 changes: 1 addition & 1 deletion components/spi_flash/flash_brownout_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void spi_flash_needs_reset_check(void)
{
// Currently only XMC is suggested to reset when brownout
#if CONFIG_SPI_FLASH_BROWNOUT_RESET_XMC
if ((g_rom_flashchip.device_id >> 16) == 0x20 || (g_rom_flashchip.device_id >> 16) == 0x46) {
if ((g_rom_flashchip.device_id >> 16) == 0x20) {
flash_brownout_needs_reset = true;
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions components/spi_flash/include/spi_flash/spi_flash_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#define CMD_RST_EN 0x66
#define CMD_RST_DEV 0x99

#define CMD_RDSFDP 0x5A /* Read the SFDP of the flash */

#define SPI_FLASH_DIO_ADDR_BITLEN 24
#define SPI_FLASH_DIO_DUMMY_BITLEN 4
#define SPI_FLASH_QIO_ADDR_BITLEN 24
Expand Down
30 changes: 28 additions & 2 deletions components/spi_flash/spi_flash_chip_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,37 @@ spi_flash_caps_t spi_flash_chip_generic_get_caps(esp_flash_t *chip)
// 32M-bits address support

// flash suspend support
// XMC support suspend
if (chip->chip_id >> 16 == 0x20 || chip->chip_id >> 16 == 0x46) {
// XMC-D support suspend
if (chip->chip_id >> 16 == 0x46) {
caps_flags |= SPI_FLASH_CHIP_CAP_SUSPEND;
}

// XMC-D support suspend (some D series flash chip begin with 0x20, difference checked by SFDP)
if (chip->chip_id >> 16 == 0x20) {
uint8_t data = 0;
spi_flash_trans_t t = {
.command = CMD_RDSFDP,
.address_bitlen = 24,
.address = 0x32,
.mosi_len = 0,
.mosi_data = 0,
.miso_len = 1,
.miso_data = &data,
.dummy_bitlen = 8,
};
chip->host->driver->common_command(chip->host, &t);
if((data & 0x8) == 0x8) {
caps_flags |= SPI_FLASH_CHIP_CAP_SUSPEND;
}
}

#if CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND
// XMC-C suspend has big risk. But can enable this anyway.
if (chip->chip_id >> 16 == 0x20) {
caps_flags |= SPI_FLASH_CHIP_CAP_SUSPEND;
}
#endif

// FM support suspend
if (chip->chip_id >> 16 == 0xa1) {
caps_flags |= SPI_FLASH_CHIP_CAP_SUSPEND;
Expand Down
1 change: 1 addition & 0 deletions docs/en/migration-guides/release-5.x/5.4/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Migration from 5.3 to 5.4
gcc
system
bluetooth-classic
storage
7 changes: 7 additions & 0 deletions docs/en/migration-guides/release-5.x/5.4/storage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Storage
=======

SPI Flash Driver
^^^^^^^^^^^^^^^^

XMC-C series flash suspend support has been removed. According to feedback from the flash manufacturer, in some situations the XMC-C flash would require a 1ms interval between resume and next command. This is too long for a software request. Based on the above reason, in order to use suspend safely, we decide to remove flash suspend support from XMC-C series. But you can still force enable it via `CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND`. If you have any questions, please contact espressif business support.
1 change: 1 addition & 0 deletions docs/zh_CN/migration-guides/release-5.x/5.4/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
gcc
system
bluetooth-classic
storage
7 changes: 7 additions & 0 deletions docs/zh_CN/migration-guides/release-5.x/5.4/storage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
存储
=======

SPI flash 驱动
^^^^^^^^^^^^^^^^^^^^^^

XMC-C 系列闪存 suspend 功能的支持已被移除。根据闪存制造商的反馈,在某些情况下,XMC-C 闪存需要在 resume 和下一条命令之间间隔 1 毫秒。这对于软件请求来说时间太长。基于上述原因,为了安全使用 suspend 功能,我们决定取消 XMC-C 系列的闪存挂起支持。但是你依旧可以强行通过 `CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND` 的配置使能这个功能。如果您有任何疑问,请联系 espressif 业务支持。

0 comments on commit 121a272

Please sign in to comment.