Skip to content

Commit

Permalink
flash/esp: Adds ESP32-S3 flash support
Browse files Browse the repository at this point in the history
  • Loading branch information
gerekon committed Oct 22, 2021
1 parent 64b5a0a commit dbede94
Show file tree
Hide file tree
Showing 24 changed files with 1,906 additions and 48 deletions.
10 changes: 0 additions & 10 deletions contrib/loaders/flash/esp/esp32/stub_flasher_chip.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,6 @@ static bool esp32_flash_cache_enabled(uint32_t cpuid)
return result;
}

static inline uint32_t stub_get_coreid()
{
int id;
__asm__ volatile (
"rsr.prid %0\n"
" extui %0,%0,13,1"
: "=r" (id));
return id;
}

static uint32_t esp32_flash_exec_usr_cmd(uint32_t cmd)
{
uint32_t status_value = ESP_ROM_SPIFLASH_BUSY_FLAG;
Expand Down
59 changes: 59 additions & 0 deletions contrib/loaders/flash/esp/esp32s3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Makefile to compile the flasher stub program
#
# Note that YOU DO NOT NEED TO COMPILE THIS IN ORDER TO JUST USE

# See the comments in the top of the Makefile for parameters that
# you probably want to override.
#
# Copyright (c) 2021 Espressif Systems
# All rights reserved
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Prefix for ESP32-S3 cross compilers (can include a directory path)
CROSS ?= xtensa-esp32s3-elf-

# Path to the esp-idf root dir
IDF_PATH ?= ../..

STUB_CHIP_PATH := $(shell pwd)
STUB_COMMON_PATH := $(STUB_CHIP_PATH)/..
STUB_CHIP_ARCH_PATH := $(STUB_COMMON_PATH)/xtensa
STUB_OBJ_DEPS := sdkconfig.h
STUB_LD_SCRIPT := stub.ld
STUB_CHIP := ESP32S3

SRCS := $(IDF_PATH)/components/app_trace/port/xtensa/port.c \
$(IDF_PATH)/components/xtensa/eri.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32s3/rtc_clk.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32s3/rtc_clk_init.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32s3/rtc_time.c

CFLAGS := -mlongcalls -mtext-section-literals

INCLUDES := -I$(IDF_PATH)/components/esp32s3/include -I$(IDF_PATH)/components/soc/esp32s3/include \
-I$(IDF_PATH)/components/esp_rom/include/esp32s3 -I$(IDF_PATH)/components/xtensa/esp32s3/include \
-I$(IDF_PATH)/components/hal/esp32s3/include \
-I$(IDF_PATH)/components/esp_hw_support/port/esp32s3/private_include \
-I$(IDF_PATH)/components/esp_hw_support/port/esp32s3 \
-I$(IDF_PATH)/components/xtensa/include \
-I$(IDF_PATH)/components/freertos/include \
-I$(IDF_PATH)/components/freertos/port/xtensa/include

DEFINES :=

LDFLAGS := -L$(IDF_PATH)/components/esp32s3/ld -T$(IDF_PATH)/components/esp_rom/esp32s3/ld/esp32s3.rom.ld \
-T$(IDF_PATH)/components/esp_rom/esp32s3/ld/esp32s3.rom.api.ld

include ../stub_common.mk
33 changes: 33 additions & 0 deletions contrib/loaders/flash/esp/esp32s3/sdkconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _STUB_SDKCONFIG_H_
#define _STUB_SDKCONFIG_H_

#define CONFIG_IDF_TARGET_ARCH_XTENSA 1
#define CONFIG_IDF_TARGET_ESP32S3 1
#define CONFIG_FREERTOS_UNICORE 0
/* Use ROM flash driver patch
* #define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
* Disable application module multi-threading lock */
#define CONFIG_APPTRACE_LOCK_ENABLE 0
/* Enable apptarce module for flash data transfers */
#define CONFIG_APPTRACE_DEST_JTAG 1
#define CONFIG_APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE 1
#define CONFIG_APPTRACE_ENABLE 1
#define CONFIG_APPTRACE_BUF_SIZE 0
#define CONFIG_APPTRACE_PENDING_DATA_SIZE_MAX 0
/* Debug UART number */
#define CONFIG_CONSOLE_UART_NUM 0
/* Debug UART baudrate */
#define CONFIG_CONSOLE_UART_BAUDRATE 115200
/* alloc apptrace data buffers on stack */
#define CONFIG_STUB_STACK_DATA_POOL_SIZE (2*CONFIG_APPTRACE_BUF_SIZE)

/* needed due to apptrace sources usage */
#define CONFIG_LOG_MAXIMUM_LEVEL 0
/* needed due to various checks in IDF headers */
#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16
/* TODO: use current clk, get it from PLL settings */
#define CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ 160
/* Unused by stub, just for compilation of IDF */
#define CONFIG_PARTITION_TABLE_OFFSET 0x8000

#endif /*_STUB_SDKCONFIG_H_ */
29 changes: 29 additions & 0 deletions contrib/loaders/flash/esp/esp32s3/stub.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/***************************************************************************
* LD script for ESP32-S3 flasher stub *
* Copyright (C) 2021 Espressif Systems Ltd. *
* Author: Alexey Gerenkov <alexey@espressif.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/

MEMORY {
/* place stub at the beginning of the OpenOCD working area,
remaining space will be used for other chunks */
iram : org = 0x403B0000, len = 0x4000
dram : org = 0x3FCE0000, len = 0xC000
}

INCLUDE stub_common.ld
Loading

0 comments on commit dbede94

Please sign in to comment.