mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-11-03 22:08:28 +00:00 
			
		
		
		
	spi_flash: add support for th 1M flash
This commit is contained in:
		@@ -88,6 +88,7 @@ const static qio_info_t chip_data[] = {
 | 
				
			|||||||
    { "WinBond",     0xEF,   0x4000, 0xFF00,    read_status_16b_rdsr_rdsr2, write_status_16b_wrsr,      9 },
 | 
					    { "WinBond",     0xEF,   0x4000, 0xFF00,    read_status_16b_rdsr_rdsr2, write_status_16b_wrsr,      9 },
 | 
				
			||||||
    { "GD",          0xC8,   0x6000, 0xFF00,    read_status_16b_rdsr_rdsr2, write_status_16b_wrsr,      9 },
 | 
					    { "GD",          0xC8,   0x6000, 0xFF00,    read_status_16b_rdsr_rdsr2, write_status_16b_wrsr,      9 },
 | 
				
			||||||
    { "XM25QU64A",   0x20,   0x3817, 0xFFFF,    read_status_8b_xmc25qu64a,  write_status_8b_xmc25qu64a, 6 },
 | 
					    { "XM25QU64A",   0x20,   0x3817, 0xFFFF,    read_status_8b_xmc25qu64a,  write_status_8b_xmc25qu64a, 6 },
 | 
				
			||||||
 | 
					    { "TH",          0xcd,   0x6000, 0xFF00,    read_status_16b_rdsr_rdsr2, write_status_16b_wrsr,      9 },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Final entry is default entry, if no other IDs have matched.
 | 
					    /* Final entry is default entry, if no other IDs have matched.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,6 +86,7 @@ else()
 | 
				
			|||||||
            "spi_flash_chip_gd.c"
 | 
					            "spi_flash_chip_gd.c"
 | 
				
			||||||
            "spi_flash_chip_winbond.c"
 | 
					            "spi_flash_chip_winbond.c"
 | 
				
			||||||
            "spi_flash_chip_boya.c"
 | 
					            "spi_flash_chip_boya.c"
 | 
				
			||||||
 | 
					            "spi_flash_chip_th.c"
 | 
				
			||||||
            "memspi_host_driver.c")
 | 
					            "memspi_host_driver.c")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        list(APPEND cache_srcs
 | 
					        list(APPEND cache_srcs
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -228,13 +228,24 @@ menu "SPI Flash driver"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        config SPI_FLASH_SUPPORT_BOYA_CHIP
 | 
					        config SPI_FLASH_SUPPORT_BOYA_CHIP
 | 
				
			||||||
            bool "BOYA"
 | 
					            bool "BOYA"
 | 
				
			||||||
            depends on !IDF_TARGET_ESP32
 | 
					            # ESP32 doens't usually use this chip, default n to save iram.
 | 
				
			||||||
 | 
					            default n if IDF_TARGET_ESP32
 | 
				
			||||||
            default y
 | 
					            default y
 | 
				
			||||||
            help
 | 
					            help
 | 
				
			||||||
                Enable this to support auto detection of BOYA chips if chip vendor not directly
 | 
					                Enable this to support auto detection of BOYA chips if chip vendor not directly
 | 
				
			||||||
                given by ``chip_drv`` member of the chip struct. This adds support for variant
 | 
					                given by ``chip_drv`` member of the chip struct. This adds support for variant
 | 
				
			||||||
                chips, however will extend detecting time.
 | 
					                chips, however will extend detecting time.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        config SPI_FLASH_SUPPORT_TH_CHIP
 | 
				
			||||||
 | 
					            bool "TH"
 | 
				
			||||||
 | 
					            # ESP32 doens't usually use this chip, default n to save iram.
 | 
				
			||||||
 | 
					            default n if IDF_TARGET_ESP32
 | 
				
			||||||
 | 
					            default y
 | 
				
			||||||
 | 
					            help
 | 
				
			||||||
 | 
					                Enable this to support auto detection of TH chips if chip vendor not directly
 | 
				
			||||||
 | 
					                given by ``chip_drv`` member of the chip struct. This adds support for variant
 | 
				
			||||||
 | 
					                chips, however will extend detecting time.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    endmenu #auto detect flash chips
 | 
					    endmenu #auto detect flash chips
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    config SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE
 | 
					    config SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								components/spi_flash/include/spi_flash_chip_th.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								components/spi_flash/include/spi_flash_chip_th.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					#include "esp_flash.h"
 | 
				
			||||||
 | 
					#include "spi_flash_chip_driver.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern const spi_flash_chip_t esp_flash_chip_th;
 | 
				
			||||||
@@ -7,7 +7,6 @@ entries:
 | 
				
			|||||||
    spi_flash_chip_mxic (noflash)
 | 
					    spi_flash_chip_mxic (noflash)
 | 
				
			||||||
    spi_flash_chip_gd (noflash)
 | 
					    spi_flash_chip_gd (noflash)
 | 
				
			||||||
    spi_flash_chip_winbond (noflash)
 | 
					    spi_flash_chip_winbond (noflash)
 | 
				
			||||||
    memspi_host_driver (noflash)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if IDF_TARGET_ESP32 = n:
 | 
					 | 
				
			||||||
    spi_flash_chip_boya (noflash)
 | 
					    spi_flash_chip_boya (noflash)
 | 
				
			||||||
 | 
					    spi_flash_chip_th (noflash)
 | 
				
			||||||
 | 
					    memspi_host_driver (noflash)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,16 +1,8 @@
 | 
				
			|||||||
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
 | 
					/*
 | 
				
			||||||
//
 | 
					 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
 | 
				
			||||||
// Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 *
 | 
				
			||||||
// you may not use this file except in compliance with the License.
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
// You may obtain a copy of the License at
 | 
					 */
 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//     http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
// distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
// See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
// limitations under the License.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include "spi_flash_chip_driver.h"
 | 
					#include "spi_flash_chip_driver.h"
 | 
				
			||||||
@@ -20,6 +12,7 @@
 | 
				
			|||||||
#include "spi_flash_chip_gd.h"
 | 
					#include "spi_flash_chip_gd.h"
 | 
				
			||||||
#include "spi_flash_chip_winbond.h"
 | 
					#include "spi_flash_chip_winbond.h"
 | 
				
			||||||
#include "spi_flash_chip_boya.h"
 | 
					#include "spi_flash_chip_boya.h"
 | 
				
			||||||
 | 
					#include "spi_flash_chip_th.h"
 | 
				
			||||||
#include "sdkconfig.h"
 | 
					#include "sdkconfig.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -46,6 +39,9 @@ static const spi_flash_chip_t *default_registered_chips[] = {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP
 | 
					#ifdef CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP
 | 
				
			||||||
    &esp_flash_chip_boya,
 | 
					    &esp_flash_chip_boya,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef CONFIG_SPI_FLASH_SUPPORT_TH_CHIP
 | 
				
			||||||
 | 
					    &esp_flash_chip_th,
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    // Default chip drivers that will accept all chip ID.
 | 
					    // Default chip drivers that will accept all chip ID.
 | 
				
			||||||
    // FM, Winbond and XMC chips are supposed to be supported by this chip driver.
 | 
					    // FM, Winbond and XMC chips are supposed to be supported by this chip driver.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										74
									
								
								components/spi_flash/spi_flash_chip_th.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								components/spi_flash/spi_flash_chip_th.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include "spi_flash_chip_generic.h"
 | 
				
			||||||
 | 
					#include "spi_flash_defs.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					esp_err_t spi_flash_chip_th_probe(esp_flash_t *chip, uint32_t flash_id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /* Check manufacturer and product IDs match our desired masks */
 | 
				
			||||||
 | 
					    const uint8_t MFG_ID = 0xcd;
 | 
				
			||||||
 | 
					    if (flash_id >> 16 != MFG_ID) {
 | 
				
			||||||
 | 
					        return ESP_ERR_NOT_FOUND;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const uint16_t FLASH_ID_MASK = 0xFF00;
 | 
				
			||||||
 | 
					    const uint16_t FLASH_ID_VALUE = 0x6000;
 | 
				
			||||||
 | 
					    if ((flash_id & FLASH_ID_MASK) != FLASH_ID_VALUE) {
 | 
				
			||||||
 | 
					        return ESP_ERR_NOT_FOUND;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ESP_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					spi_flash_caps_t spi_flash_chip_th_get_caps(esp_flash_t *chip)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    spi_flash_caps_t caps_flags = 0;
 | 
				
			||||||
 | 
					    // 32-bit-address flash is not supported
 | 
				
			||||||
 | 
					    // flash-suspend is not supported
 | 
				
			||||||
 | 
					    return caps_flags;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char chip_name[] = "th";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The th chip can use the functions for generic chips except from set read mode and probe,
 | 
				
			||||||
 | 
					// So we only replace these two functions.
 | 
				
			||||||
 | 
					const spi_flash_chip_t esp_flash_chip_th = {
 | 
				
			||||||
 | 
					    .name = chip_name,
 | 
				
			||||||
 | 
					    .timeout = &spi_flash_chip_generic_timeout,
 | 
				
			||||||
 | 
					    .probe = spi_flash_chip_th_probe,
 | 
				
			||||||
 | 
					    .reset = spi_flash_chip_generic_reset,
 | 
				
			||||||
 | 
					    .detect_size = spi_flash_chip_generic_detect_size,
 | 
				
			||||||
 | 
					    .erase_chip = spi_flash_chip_generic_erase_chip,
 | 
				
			||||||
 | 
					    .erase_sector = spi_flash_chip_generic_erase_sector,
 | 
				
			||||||
 | 
					    .erase_block = spi_flash_chip_generic_erase_block,
 | 
				
			||||||
 | 
					    .sector_size = 4 * 1024,
 | 
				
			||||||
 | 
					    .block_erase_size = 64 * 1024,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .get_chip_write_protect = spi_flash_chip_generic_get_write_protect,
 | 
				
			||||||
 | 
					    .set_chip_write_protect = spi_flash_chip_generic_set_write_protect,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .num_protectable_regions = 0,
 | 
				
			||||||
 | 
					    .protectable_regions = NULL,
 | 
				
			||||||
 | 
					    .get_protected_regions = NULL,
 | 
				
			||||||
 | 
					    .set_protected_regions = NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .read = spi_flash_chip_generic_read,
 | 
				
			||||||
 | 
					    .write = spi_flash_chip_generic_write,
 | 
				
			||||||
 | 
					    .program_page = spi_flash_chip_generic_page_program,
 | 
				
			||||||
 | 
					    .page_size = 256,
 | 
				
			||||||
 | 
					    .write_encrypted = spi_flash_chip_generic_write_encrypted,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .wait_idle = spi_flash_chip_generic_wait_idle,
 | 
				
			||||||
 | 
					    .set_io_mode = spi_flash_chip_generic_set_io_mode,
 | 
				
			||||||
 | 
					    .get_io_mode = spi_flash_chip_generic_get_io_mode,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .read_reg = spi_flash_chip_generic_read_reg,
 | 
				
			||||||
 | 
					    .yield = spi_flash_chip_generic_yield,
 | 
				
			||||||
 | 
					    .sus_setup = spi_flash_chip_generic_suspend_cmd_conf,
 | 
				
			||||||
 | 
					    .get_chip_caps = spi_flash_chip_th_get_caps,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -38,6 +38,7 @@ components/spi_flash/include/spi_flash_chip_mxic.h
 | 
				
			|||||||
components/spi_flash/include/spi_flash_chip_gd.h
 | 
					components/spi_flash/include/spi_flash_chip_gd.h
 | 
				
			||||||
components/spi_flash/include/spi_flash_chip_winbond.h
 | 
					components/spi_flash/include/spi_flash_chip_winbond.h
 | 
				
			||||||
components/spi_flash/include/spi_flash_chip_boya.h
 | 
					components/spi_flash/include/spi_flash_chip_boya.h
 | 
				
			||||||
 | 
					components/spi_flash/include/spi_flash_chip_th.h
 | 
				
			||||||
components/spi_flash/include/memspi_host_driver.h
 | 
					components/spi_flash/include/memspi_host_driver.h
 | 
				
			||||||
components/spi_flash/include/spi_flash_chip_driver.h
 | 
					components/spi_flash/include/spi_flash_chip_driver.h
 | 
				
			||||||
components/spi_flash/include/spi_flash_chip_generic.h
 | 
					components/spi_flash/include/spi_flash_chip_generic.h
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user