Skip to content

Follow ESP-IDF 5.0 #27

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

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build/
sdkconfig.old
main/example_mrb.h
components/mruby_component/esp32_build_config.rb.lock
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(mruby-esp32)
4 changes: 0 additions & 4 deletions Makefile

This file was deleted.

37 changes: 4 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ the [esp-idf](https://github.com/espressif/esp-idf/tree/master/docs) project
for your specific operating system.

I have only tested this on macOS and using a certain version of
[esp-idf](https://github.com/espressif/esp-idf/tree/abecab7525e7edb1fde16ab5d8cf7b368b1d332c).
[esp-idf](https://github.com/espressif/esp-idf/tree/release/v5.0).
You should try to use [more recent version](https://github.com/espressif/esp-idf#setting-up-esp-idf) if you have failed.

You will need to recursively clone this project with the recursive flag
Expand All @@ -26,9 +26,8 @@ are at least somewhat familiar with the building steps. With that in mind you
can do something like the following and see the example running:

```
make menuconfig
make MRUBY_EXAMPLE=simplest_mrb.rb
make MRUBY_EXAMPLE=simplest_mrb.rb flash monitor
idf.py build -D MRUBY_EXAMPLE=simplest_mrb.rb
idf.py -p $(YOUR_SERIAL_PORT) flash monitor
```

The flag `MRUBY_EXAMPLE` can be replaced with one of the following:
Expand All @@ -38,38 +37,10 @@ The flag `MRUBY_EXAMPLE` can be replaced with one of the following:
modify this file to include your SSID and password
* _system_mrb.rb_ - Examples of most of the system APIs

## wifi\_example\_mrb.rb stack overflow

If you experience a stack overflow during execution of the WiFi example, please
adjust the stack size on file `main/mruby_main.c` from 8192 to 32768.

```
void app_main()
{
nvs_flash_init();
xTaskCreate(&mruby_task, "mruby_task", 32768, NULL, 5, NULL);
}

```

Also adjust the configured stack size using `make menuconfig` from the default
one (which may be either 2048 or 4096) to 32768.

```
make menuconfig
Component config ---> ESP32-specific ---> Event loop task stack size
```

References: Issue [#11](https://github.com/mruby-esp32/mruby-esp32/issues/11)
and
[mruby-esp32\/mruby-socket](https://github.com/mruby-esp32/mruby-socket)

---

The clean command will clean both the ESP32 build and the mruby build:

```
make clean
idf.py fullclean
```

There are multiple GEMS that can be turned on and off via the mruby
Expand Down
24 changes: 24 additions & 0 deletions components/mruby_component/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(MRUBY_DIR "${COMPONENT_DIR}/mruby")
set(LIBMRUBY_FILE "${COMPONENT_DIR}/mruby/build/esp32/lib/libmruby.a")
set(MRUBY_CONFIG ${COMPONENT_DIR}/esp32_build_config.rb)

idf_component_register(
INCLUDE_DIRS mruby/include
REQUIRES esp_wifi esp_hw_support esp_rom
)

add_custom_command(
OUTPUT ${LIBMRUBY_FILE}
COMMAND ${CMAKE_COMMAND} -E env "MRUBY_CONFIG=${MRUBY_CONFIG}" "CC=${CMAKE_C_COMPILER}" "LD=${CMAKE_LINKER}" "AR=${CMAKE_AR}" "COMPONENT_INCLUDES=$<TARGET_PROPERTY:${COMPONENT_TARGET},INTERFACE_INCLUDE_DIRECTORIES>" rake
WORKING_DIRECTORY ${MRUBY_DIR}
VERBATIM
)

add_prebuilt_library(
libmruby ${LIBMRUBY_FILE}
PRIV_REQUIRES esp_wifi esp_hw_support esp_rom
)
target_link_libraries(${COMPONENT_LIB} INTERFACE libmruby)

add_custom_target(mruby DEPENDS ${LIBMRUBY_FILE})
add_dependencies(${COMPONENT_LIB} mruby)
16 changes: 0 additions & 16 deletions components/mruby_component/component.mk

This file was deleted.

4 changes: 3 additions & 1 deletion components/mruby_component/esp32_build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
toolchain :gcc

conf.cc do |cc|
cc.include_paths << ENV["COMPONENT_INCLUDES"].split(' ')
cc.include_paths << ENV["COMPONENT_INCLUDES"].split(';')

cc.flags << '-Wno-maybe-uninitialized'
cc.flags << '-mlongcalls'
cc.flags << '-std=gnu17'
cc.flags = cc.flags.flatten.collect { |x| x.gsub('-MP', '') }

cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
Expand Down
18 changes: 18 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(MRBC_COMMAND "${COMPONENT_DIR}/../components/mruby_component/mruby/bin/mrbc")

idf_component_register(
SRCS mruby_main.c
INCLUDE_DIRS .
REQUIRES mruby_component
PRIV_REQUIRES nvs_flash
)

add_custom_command(
OUTPUT example_mrb.h
COMMAND ${MRBC_COMMAND} -B example_mrb -o example_mrb.h ${COMPONENT_DIR}/examples/${MRUBY_EXAMPLE}
WORKING_DIRECTORY ${COMPONENT_DIR}
VERBATIM
)

add_custom_target(main DEPENDS example_mrb.h)
add_dependencies(${COMPONENT_LIB} main)
10 changes: 0 additions & 10 deletions main/component.mk

This file was deleted.

2 changes: 1 addition & 1 deletion main/mruby_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ void mruby_task(void *pvParameter)
void app_main()
{
nvs_flash_init();
xTaskCreate(&mruby_task, "mruby_task", 8192, NULL, 5, NULL);
xTaskCreate(&mruby_task, "mruby_task", 16384, NULL, 5, NULL);
}
Loading