CXX: Make spi_flash related part works

This commit is contained in:
Cao Sen Miao 2022-06-27 15:16:50 +08:00
parent 435bbb444c
commit 64147c3794
6 changed files with 83 additions and 24 deletions

View File

@ -1,18 +1,10 @@
// Copyright 2015-2016 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.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include "esp_spi_flash.h"
#include "spi_flash_mmap.h"
#include "esp_partition.h"
#include "spi_flash_emulation.h"
#include <functional>

View File

@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
size_t strlcpy(char *dst, const char *src, size_t dsize);

View File

@ -0,0 +1,60 @@
/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */
/*-
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
/*
* Copy string src to buffer dst of size dsize. At most dsize-1
* chars will be copied. Always NUL terminates (unless dsize == 0).
* Returns strlen(src); if retval >= dsize, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t dsize)
{
const char *osrc = src;
size_t nleft = dsize;
/* Copy as many bytes as will fit. */
if (nleft != 0) {
while (--nleft != 0) {
if ((*dst++ = *src++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src. */
if (nleft == 0) {
if (dsize != 0)
*dst = '\0'; /* NUL-terminate dst */
while (*src++)
;
}
return(src - osrc - 1); /* count does not include NUL */
}

View File

@ -6,7 +6,8 @@
#include "esp_log.h"
#include "SPI_Flash.h"
#include "esp_spi_flash.h"
#include "spi_flash_mmap.h"
#include "esp_rom_spiflash.h"
static const char *TAG = "spi_flash";
SPI_Flash::SPI_Flash()
@ -15,12 +16,12 @@ SPI_Flash::SPI_Flash()
size_t SPI_Flash::chip_size()
{
return spi_flash_get_chip_size();
return g_rom_flashchip.chip_size;
}
esp_err_t SPI_Flash::erase_sector(size_t sector)
{
esp_err_t result = spi_flash_erase_sector(sector);
esp_err_t result = esp_rom_spiflash_erase_sector(sector);
if (result == ESP_OK) {
ESP_LOGV(TAG, "erase_sector - sector=0x%08x, result=0x%08x", sector, result);
} else {
@ -32,7 +33,7 @@ esp_err_t SPI_Flash::erase_range(size_t start_address, size_t size)
{
size = (size + SPI_FLASH_SEC_SIZE - 1) / SPI_FLASH_SEC_SIZE;
size = size * SPI_FLASH_SEC_SIZE;
esp_err_t result = spi_flash_erase_range(start_address, size);
esp_err_t result = esp_rom_spiflash_erase_area(start_address, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
} else {
@ -43,7 +44,7 @@ esp_err_t SPI_Flash::erase_range(size_t start_address, size_t size)
esp_err_t SPI_Flash::write(size_t dest_addr, const void *src, size_t size)
{
esp_err_t result = spi_flash_write(dest_addr, src, size);
esp_err_t result = esp_rom_spiflash_write(dest_addr, (uint32_t*)src, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "write - dest_addr=0x%08x, size=0x%08x, result=0x%08x", dest_addr, size, result);
} else {
@ -54,7 +55,7 @@ esp_err_t SPI_Flash::write(size_t dest_addr, const void *src, size_t size)
esp_err_t SPI_Flash::read(size_t src_addr, void *dest, size_t size)
{
esp_err_t result = spi_flash_read(src_addr, dest, size);
esp_err_t result = esp_rom_spiflash_read(src_addr, (uint32_t*)dest, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "read - src_addr=0x%08x, size=0x%08x, result=0x%08x", src_addr, size, result);
} else {

View File

@ -7,7 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include "esp_spi_flash.h"
#include "spi_flash_mmap.h"
#include "esp_partition.h"
#include "wear_levelling.h"
#include "WL_Flash.h"

View File

@ -648,7 +648,6 @@ components/esp_serial_slave_link/include/esp_serial_slave_link/essl_spi.h
components/esp_serial_slave_link/include/essl_spi/esp32c3_defs.h
components/esp_serial_slave_link/include/essl_spi/esp32s2_defs.h
components/esp_serial_slave_link/include/essl_spi/esp32s3_defs.h
components/esp_system/esp_err.c
components/esp_system/include/eh_frame_parser.h
components/esp_system/include/esp_expression_with_stack.h
components/esp_system/include/esp_freertos_hooks.h
@ -1002,7 +1001,6 @@ components/nvs_flash/test_nvs_host/esp_error_check_stub.cpp
components/nvs_flash/test_nvs_host/main.cpp
components/nvs_flash/test_nvs_host/sdkconfig.h
components/nvs_flash/test_nvs_host/spi_flash_emulation.cpp
components/nvs_flash/test_nvs_host/spi_flash_emulation.h
components/nvs_flash/test_nvs_host/test_fixtures.hpp
components/nvs_flash/test_nvs_host/test_intrusive_list.cpp
components/nvs_flash/test_nvs_host/test_nvs_cxx_api.cpp
@ -1010,7 +1008,6 @@ components/nvs_flash/test_nvs_host/test_nvs_handle.cpp
components/nvs_flash/test_nvs_host/test_nvs_initialization.cpp
components/nvs_flash/test_nvs_host/test_nvs_partition.cpp
components/nvs_flash/test_nvs_host/test_nvs_storage.cpp
components/nvs_flash/test_nvs_host/test_spi_flash_emulation.cpp
components/openthread/include/esp_openthread.h
components/openthread/include/esp_openthread_lock.h
components/openthread/include/esp_openthread_netif_glue.h
@ -1431,6 +1428,7 @@ components/spi_flash/sim/SpiFlash.cpp
components/spi_flash/sim/flash_mock.cpp
components/spi_flash/sim/flash_mock_util.c
components/spi_flash/sim/sdkconfig/sdkconfig.h
components/spi_flash/sim/stubs/bsd/strlcpy.c
components/spi_flash/spi_flash_chip_boya.c
components/spi_flash/spi_flash_chip_gd.c
components/spi_flash/spi_flash_chip_issi.c