Skip to content

Commit

Permalink
flash: Refactor and add flash support for ESP32-C3
Browse files Browse the repository at this point in the history
Closes #158
  • Loading branch information
gerekon committed Jun 3, 2021
1 parent d3d4888 commit e950ede
Show file tree
Hide file tree
Showing 47 changed files with 3,743 additions and 1,875 deletions.
9 changes: 5 additions & 4 deletions contrib/loaders/flash/esp/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ STUB_CHIP := ESP32
SRCS := $(IDF_PATH)/components/esp_hw_support/port/esp32/rtc_clk.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32/rtc_clk_init.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32/rtc_time.c \
$(IDF_PATH)/components/spi_flash/esp32/spi_flash_rom_patch.c
$(IDF_PATH)/components/spi_flash/esp32/spi_flash_rom_patch.c \
$(IDF_PATH)/components/xtensa/eri.c

CFLAGS :=
CFLAGS := -mlongcalls -mtext-section-literals

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

DEFINES :=

LDFLAGS := -L$(IDF_PATH)/components/esp32/ld -T$(IDF_PATH)/components/esp_rom/esp32/ld/esp32.rom.ld \
Expand Down
4 changes: 4 additions & 0 deletions contrib/loaders/flash/esp/esp32/stub_flasher_chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ struct stub_flash_state {
void stub_flash_state_prepare(struct stub_flash_state *state);
void stub_flash_state_restore(struct stub_flash_state *state);

uint32_t stub_esp_clk_cpu_freq(void);

#include "stub_xtensa_chips.h"

#endif /*ESP32_FLASHER_STUB_H */
10 changes: 6 additions & 4 deletions contrib/loaders/flash/esp/esp32_s2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ STUB_CHIP := ESP32_S2
SRCS := $(IDF_PATH)/components/esp_hw_support/port/esp32s2/rtc_clk.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32s2/rtc_clk_init.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32s2/rtc_time.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32s2/regi2c_ctrl.c
$(IDF_PATH)/components/esp_hw_support/port/esp32s2/regi2c_ctrl.c \
$(IDF_PATH)/components/xtensa/eri.c

CFLAGS :=
CFLAGS := -mlongcalls -mtext-section-literals

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

-I$(IDF_PATH)/components/esp_hw_support/port/esp32s2 \
-I$(IDF_PATH)/components/xtensa/include -I$(IDF_PATH)/components/freertos/port/xtensa/include

DEFINES :=

LDFLAGS := -L$(IDF_PATH)/components/esp32s2/ld -T$(IDF_PATH)/components/esp_rom/esp32s2/ld/esp32s2.rom.ld \
Expand Down
1 change: 1 addition & 0 deletions contrib/loaders/flash/esp/esp32_s2/stub_flasher_chip.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "stub_rom_chip.h"
#include "stub_flasher_int.h"
#include "stub_flasher_chip.h"
#include "stub_xtensa_chips.h"

uint32_t g_stub_cpu_freq_hz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MHZ;

Expand Down
4 changes: 4 additions & 0 deletions contrib/loaders/flash/esp/esp32_s2/stub_flasher_chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ struct stub_flash_state {
void stub_flash_state_prepare(struct stub_flash_state *state);
void stub_flash_state_restore(struct stub_flash_state *state);

uint32_t stub_esp_clk_cpu_freq(void);

#include "stub_xtensa_chips.h"

#endif /*ESP32_S2_FLASHER_STUB_H */
56 changes: 56 additions & 0 deletions contrib/loaders/flash/esp/esp32c3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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) 2017 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-S2 cross compilers (can include a directory path)
CROSS ?= riscv32-esp-elf-

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

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

SRCS := $(IDF_PATH)/components/esp_hw_support/port/esp32c3/rtc_clk_init.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32c3/rtc_clk.c \
$(IDF_PATH)/components/esp_hw_support/port/esp32c3/rtc_time.c \
$(IDF_PATH)/components/esp_hw_support/regi2c_ctrl.c \
$(IDF_PATH)/components/app_trace/port/riscv/port.c

CFLAGS :=

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

DEFINES :=

LDFLAGS += -T$(IDF_PATH)/components/esp_rom/esp32c3/ld/esp32c3.rom.ld -T$(IDF_PATH)/components/esp_rom/esp32c3/ld/esp32c3.rom.newlib.ld \
-T$(IDF_PATH)/components/esp_rom/esp32c3/ld/esp32c3.rom.api.ld

include ../stub_common.mk
33 changes: 33 additions & 0 deletions contrib/loaders/flash/esp/esp32c3/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_RISCV 1
#define CONFIG_IDF_TARGET_ESP32C3 1
#define CONFIG_FREERTOS_UNICORE 1
/* 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 16384
#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_ESP32C3_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/esp32c3/stub.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/***************************************************************************
* LD script for ESP32-S2 flassher stub *
* Copyright (C) 2019 Espressif Systems Ltd. *
* Author: Alexey Gerenkov <[email protected]> *
* *
* 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 = 0x40380000, len = 0x4000
dram : org = 0x3FC84000, len = 0xC000
}

INCLUDE stub_common.ld
Loading

0 comments on commit e950ede

Please sign in to comment.