2019-01-08 05:29:25 -05:00
|
|
|
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// 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.
|
2020-11-26 00:06:21 -05:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#ifndef CONFIG_SPI_FLASH_NEW_ROM_API
|
|
|
|
|
|
|
|
// HAL for
|
|
|
|
// - MEMSPI
|
|
|
|
// - SPI1~3 on ESP32
|
|
|
|
// The common part is in spi_flash_hal_common.inc
|
|
|
|
|
|
|
|
// HAL for
|
|
|
|
// - MEMSPI
|
|
|
|
// - SPI1~3 on ESP32
|
|
|
|
// The common part is in spi_flash_hal_common.inc
|
2019-01-08 05:29:25 -05:00
|
|
|
|
2020-07-26 15:13:07 -04:00
|
|
|
// HAL for
|
|
|
|
// - MEMSPI
|
|
|
|
// - SPI1~3 on ESP32
|
|
|
|
// The common part is in spi_flash_hal_common.inc
|
|
|
|
|
2019-11-27 20:20:00 -05:00
|
|
|
#include "spi_flash_hal_common.inc"
|
2019-01-08 05:29:25 -05:00
|
|
|
|
2020-05-07 02:46:41 -04:00
|
|
|
void spi_flash_hal_erase_chip(spi_flash_host_inst_t *host)
|
2019-01-08 05:29:25 -05:00
|
|
|
{
|
2019-09-05 01:17:11 -04:00
|
|
|
spi_dev_t *dev = get_spi_dev(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
spi_flash_ll_erase_chip(dev);
|
2020-05-07 02:46:41 -04:00
|
|
|
host->driver->poll_cmd_done(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
}
|
|
|
|
|
2020-07-26 15:13:07 -04:00
|
|
|
// Only support 24bit address
|
2020-05-07 02:46:41 -04:00
|
|
|
void spi_flash_hal_erase_sector(spi_flash_host_inst_t *host, uint32_t start_address)
|
2019-01-08 05:29:25 -05:00
|
|
|
{
|
2019-09-05 01:17:11 -04:00
|
|
|
spi_dev_t *dev = get_spi_dev(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
spi_flash_ll_set_addr_bitlen(dev, 24);
|
|
|
|
spi_flash_ll_set_address(dev, start_address & ADDRESS_MASK_24BIT);
|
|
|
|
spi_flash_ll_erase_sector(dev);
|
2020-05-07 02:46:41 -04:00
|
|
|
host->driver->poll_cmd_done(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
}
|
|
|
|
|
2020-07-26 15:13:07 -04:00
|
|
|
// Only support 24bit address
|
2020-05-07 02:46:41 -04:00
|
|
|
void spi_flash_hal_erase_block(spi_flash_host_inst_t *host, uint32_t start_address)
|
2019-01-08 05:29:25 -05:00
|
|
|
{
|
2019-09-05 01:17:11 -04:00
|
|
|
spi_dev_t *dev = get_spi_dev(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
spi_flash_ll_set_addr_bitlen(dev, 24);
|
|
|
|
spi_flash_ll_set_address(dev, start_address & ADDRESS_MASK_24BIT);
|
|
|
|
spi_flash_ll_erase_block(dev);
|
2020-05-07 02:46:41 -04:00
|
|
|
host->driver->poll_cmd_done(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
}
|
|
|
|
|
2020-07-26 15:13:07 -04:00
|
|
|
// Only support 24bit address
|
2020-05-07 02:46:41 -04:00
|
|
|
void spi_flash_hal_program_page(spi_flash_host_inst_t *host, const void *buffer, uint32_t address, uint32_t length)
|
2019-01-08 05:29:25 -05:00
|
|
|
{
|
2019-09-05 01:17:11 -04:00
|
|
|
spi_dev_t *dev = get_spi_dev(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
spi_flash_ll_set_addr_bitlen(dev, 24);
|
|
|
|
spi_flash_ll_set_address(dev, (address & ADDRESS_MASK_24BIT) | (length << 24));
|
|
|
|
spi_flash_ll_program_page(dev, buffer, length);
|
2020-05-07 02:46:41 -04:00
|
|
|
host->driver->poll_cmd_done(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:46:41 -04:00
|
|
|
esp_err_t spi_flash_hal_set_write_protect(spi_flash_host_inst_t *host, bool wp)
|
2019-01-08 05:29:25 -05:00
|
|
|
{
|
2019-09-05 01:17:11 -04:00
|
|
|
spi_dev_t *dev = get_spi_dev(host);
|
2019-11-27 20:20:00 -05:00
|
|
|
spi_flash_ll_set_write_protect(dev, wp);
|
2020-05-07 02:46:41 -04:00
|
|
|
host->driver->poll_cmd_done(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:46:41 -04:00
|
|
|
bool spi_flash_hal_host_idle(spi_flash_host_inst_t *host)
|
2019-01-08 05:29:25 -05:00
|
|
|
{
|
2020-05-07 02:46:41 -04:00
|
|
|
spi_dev_t *dev = get_spi_dev(host);
|
2019-01-08 05:29:25 -05:00
|
|
|
bool idle = spi_flash_ll_host_idle(dev);
|
|
|
|
|
|
|
|
// Not clear if this is necessary, or only necessary if
|
|
|
|
// chip->spi == SPI1. But probably doesn't hurt...
|
2019-11-27 20:20:00 -05:00
|
|
|
if ((void*) dev == spi_flash_ll_get_hw(SPI_HOST)) {
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2019-01-08 05:29:25 -05:00
|
|
|
idle &= spi_flash_ll_host_idle(&SPI0);
|
2020-11-26 00:06:21 -05:00
|
|
|
#else
|
2020-08-18 05:11:46 -04:00
|
|
|
idle &= spi_flash_ll_host_idle(&SPIMEM0);
|
2019-11-27 20:20:00 -05:00
|
|
|
#endif
|
2019-01-08 05:29:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return idle;
|
2020-11-10 02:40:01 -05:00
|
|
|
}
|
2020-11-26 00:06:21 -05:00
|
|
|
|
|
|
|
#endif // !CONFIG_SPI_FLASH_NEW_ROM_API
|