Commit ad12a06e authored by Sylvio Alves's avatar Sylvio Alves Committed by Carles Cufi
Browse files

soc: espressif: esp32c3: update to hal_espressif v5.1



Modify and reorganize SoC to meet updated hal.

Signed-off-by: default avatarSylvio Alves <sylvio.alves@espressif.com>
Signed-off-by: default avatarLucas Tamborrino <lucas.tamborrino@espressif.com>
parent 561f31bb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
#define ESP32_CLK_CPU_160M             160000000

/* Supported XTAL Frequencies */
#define ESP32_CLK_XTAL_32M             0U
#define ESP32_CLK_XTAL_40M             1U
#define ESP32_CLK_XTAL_32M             32
#define ESP32_CLK_XTAL_40M             40

/* Supported RTC fast clock frequencies */
#define ESP32_RTC_FAST_CLK_FREQ_8M     8500000U
+18 −48
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ zephyr_sources(
  soc_irq.S
  soc_irq.c
  soc.c
  loader.c
  ../common/loader.c
  )

zephyr_include_directories(.)
@@ -25,52 +25,22 @@ dt_reg_addr(boot_off PATH ${dts_partition_path})
math(EXPR esptoolpy_flashsize "${CONFIG_FLASH_SIZE} / 0x100000")

if(CONFIG_BOOTLOADER_ESP_IDF)
  include(ExternalProject)

  ## we use hello-world project, but I think any can be used.
  set(espidf_components_dir   ${ESP_IDF_PATH}/components)
  set(espidf_prefix    ${CMAKE_BINARY_DIR}/esp-idf)
  set(espidf_build_dir ${espidf_prefix}/build)

  ExternalProject_Add(
    EspIdfBootloader
    PREFIX ${espidf_prefix}
    SOURCE_DIR ${espidf_components_dir}/bootloader/subproject
    BINARY_DIR ${espidf_build_dir}/bootloader
    CONFIGURE_COMMAND
    ${CMAKE_COMMAND} -G${CMAKE_GENERATOR}
    -S ${espidf_components_dir}/bootloader/subproject
    -B ${espidf_build_dir}/bootloader -DSDKCONFIG=${espidf_build_dir}/sdkconfig
    -DIDF_PATH=${ESP_IDF_PATH} -DIDF_TARGET=${CONFIG_SOC_SERIES}
    -DPYTHON_DEPS_CHECKED=1
    -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
    -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
    -DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
    -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
    -DPYTHON=${PYTHON_EXECUTABLE}
    BUILD_COMMAND
    ${CMAKE_COMMAND} --build .
    INSTALL_COMMAND ""      # This particular build system has no install command
    )

  ExternalProject_Add(
    EspPartitionTable
    SOURCE_DIR ${espidf_components_dir}/partition_table
    BINARY_DIR ${espidf_build_dir}
    CONFIGURE_COMMAND ""
    BUILD_COMMAND
    ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
    --offset 0x8000 --flash-size ${esptoolpy_flashsize}MB ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
    INSTALL_COMMAND ""
    )
  set(bootloader_dir "${ZEPHYR_HAL_ESPRESSIF_MODULE_DIR}/zephyr/blobs/lib/${CONFIG_SOC_SERIES}")

  set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
  if(EXISTS "${bootloader_dir}/bootloader-${CONFIG_SOC_SERIES}.bin")
    file(COPY "${bootloader_dir}/bootloader-${CONFIG_SOC_SERIES}.bin" DESTINATION ${CMAKE_BINARY_DIR})
    file(RENAME "${CMAKE_BINARY_DIR}/bootloader-${CONFIG_SOC_SERIES}.bin" "${CMAKE_BINARY_DIR}/bootloader.bin")
  endif()

  add_dependencies(app EspIdfBootloader EspPartitionTable)
  if(EXISTS "${bootloader_dir}/partition-table-${CONFIG_SOC_SERIES}.bin")
    file(COPY "${bootloader_dir}/partition-table-${CONFIG_SOC_SERIES}.bin" DESTINATION ${CMAKE_BINARY_DIR})
    file(RENAME "${CMAKE_BINARY_DIR}/partition-table-${CONFIG_SOC_SERIES}.bin" "${CMAKE_BINARY_DIR}/partition-table.bin")
  endif()

  board_finalize_runner_args(esp32 "--esp-flash-bootloader=${espidf_build_dir}/bootloader/bootloader.bin")
  board_finalize_runner_args(esp32 "--esp-flash-bootloader=${CMAKE_BINARY_DIR}/bootloader.bin")

  board_finalize_runner_args(esp32 "--esp-flash-partition_table=${espidf_build_dir}/partitions_singleapp.bin")
  board_finalize_runner_args(esp32 "--esp-flash-partition_table=${CMAKE_BINARY_DIR}/partition-table.bin")

  board_finalize_runner_args(esp32 "--esp-partition-table-address=0x8000")

@@ -80,7 +50,7 @@ if(CONFIG_MCUBOOT OR CONFIG_BOOTLOADER_ESP_IDF)

  if(CONFIG_BUILD_OUTPUT_BIN)
    set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
      COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
      COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/tools/esptool_py/esptool.py
      ARGS --chip esp32c3 elf2image --flash_mode dio --flash_freq 40m --flash_size ${esptoolpy_flashsize}MB
      -o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
      ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
+0 −50
Original line number Diff line number Diff line
@@ -22,56 +22,6 @@ config IDF_TARGET_ESP32C3
	bool "ESP32C3 as target board"
	default y

config ESP_SYSTEM_RTC_EXT_XTAL
	bool

config ESP_SYSTEM_RTC_EXT_OSC
	bool

choice ESP32C3_RTC_CLK_SRC
	prompt "RTC clock source"
	default ESP32C3_RTC_CLK_SRC_INT_RC
	help
	  Choose which clock is used as RTC clock source.

config ESP32C3_RTC_CLK_SRC_INT_RC
	bool "Internal 150kHz RC oscillator"

config ESP32C3_RTC_CLK_SRC_EXT_CRYS
	bool "External 32kHz crystal"
	select ESP_SYSTEM_RTC_EXT_XTAL

config ESP32C3_RTC_CLK_SRC_EXT_OSC
	bool "External 32kHz oscillator at 32K_XP pin"
	select ESP_SYSTEM_RTC_EXT_OSC

config ESP32C3_RTC_CLK_SRC_INT_8MD256
	bool "Internal 8MHz oscillator, divided by 256 (~32kHz)"

endchoice # ESP32C3_RTC_CLK_SRC

config ESP32C3_RTC_CLK_CAL_CYCLES
	int "Number of cycles for RTC_SLOW_CLK calibration"
	default 3000 if ESP32C3_RTC_CLK_SRC_EXT_CRYS || ESP32C3_RTC_CLK_SRC_EXT_OSC || ESP32C3_RTC_CLK_SRC_INT_8MD256
	default 1024 if ESP32C3_RTC_CLK_SRC_INT_RC
	range 0 27000 if ESP32C3_RTC_CLK_SRC_EXT_CRYS || ESP32C3_RTC_CLK_SRC_EXT_OSC || ESP32C3_RTC_CLK_SRC_INT_8MD256
	range 0 32766 if ESP32C3_RTC_CLK_SRC_INT_RC
	help
	  When the startup code initializes RTC_SLOW_CLK, it can perform
	  calibration by comparing the RTC_SLOW_CLK frequency with main XTAL
	  frequency. This option sets the number of RTC_SLOW_CLK cycles measured
	  by the calibration routine. Higher numbers increase calibration
	  precision, which may be important for applications which spend a lot of
	  time in deep sleep. Lower numbers reduce startup time.

	  When this option is set to 0, clock calibration will not be performed at
	  startup, and approximate clock frequencies will be assumed:

	  - 150000 Hz if internal RC oscillator is used as clock source. For this use value 1024.
	  - 32768 Hz if the 32k crystal oscillator is used. For this use value 3000 or more.
	    In case more value will help improve the definition of the launch of the crystal.
	    If the crystal could not start, it will be switched to internal RC.

config ESP32_PHY_MAX_WIFI_TX_POWER
	int "Max WiFi TX power (dBm)"
	range 10 20
+0 −3
Original line number Diff line number Diff line
@@ -6,9 +6,6 @@ if SOC_SERIES_ESP32C3
config NUM_IRQS
	default 62

config ESPTOOLPY_FLASHFREQ_80M
	default y

config FLASH_SIZE
	default $(dt_node_reg_size_int,/soc/flash-controller@60002000/flash@0,0)

+48 −0
Original line number Diff line number Diff line
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

if SOC_SERIES_ESP32C3

choice ESP32C3_UNIVERSAL_MAC_ADDRESSES
	bool "Number of universally administered (by IEEE) MAC address"
	default ESP32C3_UNIVERSAL_MAC_ADDRESSES_FOUR
	help
	  Configure the number of universally administered (by IEEE) MAC addresses.
	  During initialization, MAC addresses for each network interface are generated or derived from a
	  single base MAC address.
	  If the number of universal MAC addresses is four, all four interfaces (WiFi station, WiFi softap,
	  Bluetooth and Ethernet) receive a universally administered MAC address. These are generated
	  sequentially by adding 0, 1, 2 and 3 (respectively) to the final octet of the base MAC address.
	  If the number of universal MAC addresses is two, only two interfaces (WiFi station and Bluetooth)
	  receive a universally administered MAC address. These are generated sequentially by adding 0
	  and 1 (respectively) to the base MAC address. The remaining two interfaces (WiFi softap and Ethernet)
	  receive local MAC addresses. These are derived from the universal WiFi station and Bluetooth MAC
	  addresses, respectively.
	  When using the default (Espressif-assigned) base MAC address, either setting can be used. When using
	  a custom universal MAC address range, the correct setting will depend on the allocation of MAC
	  addresses in this range (either 2 or 4 per device.)
	  Note that ESP32-C3 has no integrated Ethernet MAC. Although it's possible to use the esp_read_mac()
	  API to return a MAC for Ethernet, this can only be used with an external MAC peripheral.

config ESP32C3_UNIVERSAL_MAC_ADDRESSES_TWO
	bool "Two"
	select ESP_MAC_UNIVERSAL_MAC_ADDRESSES_TWO
	select ESP_MAC_ADDR_UNIVERSE_WIFI_STA
	select ESP_MAC_ADDR_UNIVERSE_BT

config ESP32C3_UNIVERSAL_MAC_ADDRESSES_FOUR
	bool "Four"
	select ESP_MAC_UNIVERSAL_MAC_ADDRESSES_FOUR
	select ESP_MAC_ADDR_UNIVERSE_WIFI_STA
	select ESP_MAC_ADDR_UNIVERSE_WIFI_AP
	select ESP_MAC_ADDR_UNIVERSE_BT
	select ESP_MAC_ADDR_UNIVERSE_ETH

endchoice # ESP32C3_UNIVERSAL_MAC_ADDRESSES

config ESP32C3_UNIVERSAL_MAC_ADDRESSES
	int
	default 2 if ESP32C3_UNIVERSAL_MAC_ADDRESSES_TWO
	default 4 if ESP32C3_UNIVERSAL_MAC_ADDRESSES_FOUR

endif # SOC_SERIES_ESP32C3
Loading