Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/esp32: add platform code for RISC-V based ESP32x SoCs #18260

Merged
merged 4 commits into from
Jul 18, 2022

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Jun 25, 2022

Contribution description

This PR is a splitt-off from PR #17841 and replaces partially PR #18247.

To allow the compilation for RISC-V based ESP32x SoCs, platform independent implementation of tread_arch.c, irq_arch.c and exception.c are required that are provided by a platform-specific module esp_riscv.

Additionally, some DEBUG message formatting are fixed with this PR to become platform independent.

This PR includes PR #18259 at the moment to be compilable. The first commit of this PR is d05dacd. Once PR #18529 is merged, it will be rebased.

Background:

  • The file thread_arch.c in module esp_xtensa is not really independent of the used ESP SoC. Although ESP8266 and ESP32 share most of the code, they require some SoC specific code, especially in thread_yield_* functions. These functions are something very special to ESP SoCs and not common for Xtensa cores.
  • We have to use vectors.S for for RISC-V interrupt handling and portasm.S for RISC-V context switching from ESP-IDF, because they are needed by other ESP-IDF functions, e.g. by the startup function, which we also use directly from ESP-IDF. Unfortunately, they are not compatible with the RISC-V implementation in cpu/riscv_common. They use a different context frame structure, a different interrupt context structure, a different interrupt/exception handling and a different startup function. Even if we could reuse some parts of riscv_common, including a common folder in the compilation always means all or nothing. Therefore we can't use cpu/riscv_common at all.
  • Another problem is that the implementation of irq_disable/irq_restore in riscv_common only reset/set the MIE bit in mstatus register while the implementation for RISC-V based ESPs requires to change the value of the SoC specific interrupt level register INTERRUPT_CORE0_CPU_INT_THRESH_REG.

Thus, neither is the Xtensa code general enough to justify a cpu/xtensa_common folder, nor are the thread or interrupt handling for RISC-V based ESP compatible with the implementation in riscv_common. Therefore thread_arch.c, irq_arch.c and exception.c for Xtensa-based and RISC-V-based ESP SoCs are provided by the modules esp_xtensa and esp_riscv respectively.

Testing procedure

  1. Green CI
  2. Compile and check any simple test app, for example:
    BOARD=esp32-wroom-32 make -j8 -C tests/shell flash term
    

Issues/PRs references

Splitt-off from PR #17841 and PR #18247
Replaces PR #18247 partially
Depends on PR #18259

@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Jun 25, 2022
@gschorcht gschorcht requested a review from benpicco June 25, 2022 11:55
@gschorcht gschorcht added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 25, 2022
@gschorcht gschorcht force-pushed the cpu/esp32/add_riscv_platform_code branch from bce156a to b1a86a9 Compare June 25, 2022 21:52
@github-actions github-actions bot added the Area: Kconfig Area: Kconfig integration label Jun 25, 2022
@gschorcht gschorcht force-pushed the cpu/esp32/add_riscv_platform_code branch 2 times, most recently from 16fc40a to 57d12c3 Compare June 26, 2022 13:22
@gschorcht
Copy link
Contributor Author

Rebased after merge of PR #18259.

@benpicco benpicco requested a review from bergzand June 26, 2022 13:36
cpu/esp_common/esp-riscv/exceptions.c Outdated Show resolved Hide resolved
cpu/esp_common/esp-riscv/exceptions.c Outdated Show resolved Hide resolved
cpu/esp_common/esp-riscv/thread_arch.c Show resolved Hide resolved
@gschorcht gschorcht force-pushed the cpu/esp32/add_riscv_platform_code branch from 539711f to 24cb130 Compare June 27, 2022 06:30
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash

@gschorcht gschorcht force-pushed the cpu/esp32/add_riscv_platform_code branch from a0abbb0 to 778ff10 Compare July 18, 2022 11:52
@gschorcht
Copy link
Contributor Author

@benpicco I had to rebase this PR due to a conflict with the changes in in Kconfig in PR #18314.

@benpicco benpicco enabled auto-merge July 18, 2022 12:04
@benpicco benpicco merged commit e1bc176 into RIOT-OS:master Jul 18, 2022
@gschorcht
Copy link
Contributor Author

@benpicco Thanks for reviewing and merging.

@gschorcht gschorcht deleted the cpu/esp32/add_riscv_platform_code branch July 19, 2022 12:27
@maribu maribu added this to the Release 2022.10 milestone Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Area: Kconfig Area: Kconfig integration CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants