Skip to content

Conversation

@1c3t3a
Copy link
Contributor

@1c3t3a 1c3t3a commented Dec 14, 2021

This PR introduces an implementation of the WAMR platform API for ESP-IDF and enables support for Espressif microcontrollers.

This PR is related to the following issues at WAMR: closes #883, #628, #449 and #668 as well as #4735 at the esp-idf repo.
This PR implements most functions required by platform_api_vmcore.h only the following functions are left empty:

  • os_thread_get_stack_boundary
  • os_mprotect
  • os_dcache_flush (although optional)

Furthermore, a lot of functions from platform_api_extension.h are implemented. Only the following functions are missing:

  • os_recursive_mutex_init
  • os_thread_env_init
  • os_thread_env_destroy

It would be nice to get feedback from someone more familiar with ESP-IDF on how to implement those functions. I am working with ESP-IDF mostly through it's Rust API and I currently don't feel safe implementing these methods without a mentor or someone that looks over my work.

The code in this PR runs on my Esp32c3 and Esp32 in Interpreter mode, the AoT mode currently errors on both platforms with a Guru Meditation Error I think that is because os_mprotect isn't implemented.
I also added some documentation around how to build WAMR for ESP-IDF.

@sfranzyshen
Copy link

👍

@wenyongh
Copy link
Contributor

@1c3t3a Thanks a lot for enabling the platform esp-idf!

os_thread_get_stack_boundary(void)
{
BH_FREE(addr);
return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, so let's merge the patch firstly, and fix it in the future.

}

printf("run main() of the application\n");
void *ret = app_instance_main(wasm_module_inst);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Had better define the variable at the beginning of the function.

@wenyongh wenyongh merged commit a9f1c2b into bytecodealliance:main Dec 20, 2021
@wenyongh
Copy link
Contributor

@1c3t3a I did several minor changes according to @xujuntwt95329's comments and merged the patch. And more discussion for the commit:

  • For os_thread_env_init/os_thread_env_destroy, it should be unnecessary to implement them as the implementation of os_thread APIs is based on pthread.
  • For AOT mode running error, it seems that it is due to that the AOT code isn't executable: os_mmap() just calls malloc.
  • For os_thread_get_stack_boundary, had better implement it in the future if we can.

@wallento wallento mentioned this pull request Dec 30, 2021
wenyongh pushed a commit that referenced this pull request Jan 5, 2022
Various fixes and beautifications coordinated with @1c3t3a,
fixes 2 of the 3 all remaining issues from #892:
- enable to os_mmap executable memory
- fix os_malloc/os_realloc/os_free issues
- implement os_thread_get_stack_boundary
- add build scripts to include with esp-idf to use wamr as
  an ESP-IDF component
- update sample and document
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
This PR introduces an implementation of the WAMR platform APIs for ESP-IDF and enables support for Espressif microcontrollers, and adds the documentation around how to build WAMR for ESP-IDF.

This PR is related to the following issues at WAMR: closes bytecodealliance#883, bytecodealliance#628, bytecodealliance#449 and bytecodealliance#668 as well as [#4735](espressif/esp-idf#4735) at the esp-idf repo. It implements most functions required by [platform_api_vmcore.h](https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/shared/platform/include/platform_api_vmcore.h).

The PR works in interpreter mode on Esp32c3 and Esp32. For the AOT mode, currently errors occur on both platforms with `Guru Meditation Error`. It seems that the AOT code isn't run with shared memory as os_mmap() allocates memory with malloc() API, it is to be fixed in the future.
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Various fixes and beautifications coordinated with @1c3t3a,
fixes 2 of the 3 all remaining issues from bytecodealliance#892:
- enable to os_mmap executable memory
- fix os_malloc/os_realloc/os_free issues
- implement os_thread_get_stack_boundary
- add build scripts to include with esp-idf to use wamr as
  an ESP-IDF component
- update sample and document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build for esp32 fails

4 participants