diff --git a/.gitignore b/.gitignore index dcda214..ad53937 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ build_pico/ -build_pico_wifi/ -build_pico_ble/ +build_pico_w/ build_pico2/ .rake_tasks~ tags diff --git a/CMakeLists.txt b/CMakeLists.txt index e81e5a2..bde9d1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,18 +27,11 @@ else() message(FATAL_ERROR "PICORUBY_MSC_xxxx is not defined.") endif() -if((DEFINED ENV{PICO_WIFI}) AND DEFINED ENV{PICO_BLE}) - message(FATAL_ERROR "Both BLE and WiFi cannot be enabled for Pico W") -elseif(DEFINED ENV{PICO_WIFI}) +if(DEFINED ENV{PICO_W}) set(PICO_BOARD pico_w) - set(R2P2_NAME R2P2_WIFI) - set(BUILD_CONFIG r2p2_wifi-cortex-m0plus) - set(BUILD_DIR build_pico_wifi) -elseif(DEFINED ENV{PICO_BLE}) - set(PICO_BOARD pico_w) - set(R2P2_NAME R2P2_BLE) - set(BUILD_CONFIG r2p2_ble-cortex-m0plus) - set(BUILD_DIR build_pico_ble) + set(R2P2_NAME R2P2_W) + set(BUILD_CONFIG r2p2_w-cortex-m0plus) + set(BUILD_DIR build_pico_w) elseif(DEFINED ENV{PICO2}) set(PICO_BOARD pico2) set(R2P2_NAME R2P2_PICO2) @@ -82,6 +75,7 @@ add_definitions( -DMRBC_USE_MATH -DMRBC_TICK_UNIT=1 -DMRBC_TIMESLICE_TICK_COUNT=10 + -DPICORB_VM_MRUBYC ) if(DEFINED ENV{PICORUBY_DEBUG}) @@ -94,7 +88,7 @@ else() ) endif() -if(DEFINED ENV{PICO_WIFI}) +if(DEFINED ENV{PICO_W}) add_definitions( -DUSE_WIFI ) @@ -118,23 +112,18 @@ set(SOURCE_FILES ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-rng/ports/rp2040/rng.c ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-env/ports/rp2040/env.c ) -# only used in BLE build -if(DEFINED ENV{PICO_BLE}) - list(APPEND SOURCE_FILES - ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-cyw43/ports/rp2040/cyw43.c - ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble.c - ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble_peripheral.c - ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble_central.c - ) -endif() -# only used in WiFi build -if(DEFINED ENV{PICO_WIFI}) +# only used in W build +if(DEFINED ENV{PICO_W}) list(APPEND SOURCE_FILES ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-cyw43/ports/rp2040/cyw43.c ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/common.c ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/dns.c ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/tcp.c ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/udp.c + ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-mqtt/ports/rp2040/mqtt.c + ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble.c + ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble_peripheral.c + ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble_central.c ) endif() add_executable(${PROJECT_NAME} @@ -163,6 +152,8 @@ endforeach(rb) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb ${CMAKE_CURRENT_LIST_DIR}/include + ${CMAKE_SOURCE_DIR}/lib/picoruby/include + ${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/${BUILD_CONFIG}/mruby-compiler2/lib/prism/include ) target_link_directories(${PROJECT_NAME} PRIVATE @@ -193,26 +184,18 @@ if(NOT DEFINED ENV{PICO2}) ) endif() -# btstack is used in BLE build -if(DEFINED ENV{PICO_BLE}) - target_link_libraries(${PROJECT_NAME} PRIVATE - pico_btstack_ble - pico_btstack_cyw43 - ) - target_include_directories(${PROJECT_NAME} PRIVATE - ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/include - ) -endif() - -if(DEFINED ENV{PICO_WIFI}) +if(DEFINED ENV{PICO_W}) # these are used only in WiFi build target_link_libraries(${PROJECT_NAME} PRIVATE pico_cyw43_arch_lwip_threadsafe_background pico_lwip_mbedtls pico_mbedtls + pico_btstack_ble + pico_btstack_cyw43 ) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include-net + ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/include ) #else() # # Even the BLE build needs a pico_cyw43_arch, only in a different flavor @@ -230,6 +213,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/lib/ff14b/source ${CMAKE_SOURCE_DIR}/lib/picoruby/build/${BUILD_CONFIG}/mrbgems ${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/${BUILD_CONFIG}/mruby-compiler2/include + ${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-mbedtls/include ) pico_add_extra_outputs(${PROJECT_NAME}) diff --git a/README.md b/README.md index fdd5cca..b099875 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # R2P2 -R2P2 (Ruby on Raspberry Pi Pico) is a shell system written in [picoruby/picoruby](https://github.com/picoruby/picoruby). +R2P2 (Ruby Rapid Portable Platform) is a shell system runs on Raspberry Pi Pico written in [picoruby/picoruby](https://github.com/picoruby/picoruby). ## Usage diff --git a/Rakefile b/Rakefile index 01195d3..f05ce3e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,16 +1,18 @@ require "fileutils" -PICO_SDK_TAG = "2.1.0" -PICO_EXTRAS_TAG = "sdk-#{PICO_SDK_TAG}" +PICO_SDK_TAG = "2.1.1" +if PICO_SDK_TAG = "2.1.1" + PICO_EXTRAS_TAG = "sdk-2.1.0" # workaround. 2.1.1 and 2.1.0 are the same +else + PICO_EXTRAS_TAG = "sdk-#{PICO_SDK_TAG}" +end def mruby_config case ENV['BOARD']&.downcase when 'pico2' 'r2p2-cortex-m33' - when 'pico_wifi' - 'r2p2_wifi-cortex-m0plus' - when 'pico_ble' - 'r2p2_ble-cortex-m0plus' + when 'pico_w' + 'r2p2_w-cortex-m0plus' else 'r2p2-cortex-m0plus' end @@ -20,10 +22,8 @@ def cmake_flags flags = [] flags << (ENV['MSC']&.downcase == 'sd' ? "PICORUBY_MSC_SD=yes" : "PICORUBY_MSC_FLASH=yes") case ENV['BOARD']&.downcase - when 'pico_wifi' - flags << "PICO_WIFI=yes" - when 'pico_ble' - flags << "PICO_BLE=yes" + when 'pico_w' + flags << "PICO_W=yes" when 'pico2' flags << "PICO2=yes" end @@ -34,7 +34,7 @@ def def_board case ENV['BOARD']&.downcase when 'pico2' '-DPICO_PLATFORM=rp2350 -DPICO_BOARD=pico2' - when 'pico_wifi', 'pico_ble' + when 'pico_w' '-DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico_w' else '-DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico' @@ -45,10 +45,8 @@ def build_dir case ENV['BOARD']&.downcase when 'pico2' 'build_pico2' - when 'pico_wifi' - 'build_pico_wifi' - when 'pico_ble' - 'build_pico_ble' + when 'pico_w' + 'build_pico_w' else 'build_pico' end @@ -57,8 +55,7 @@ end task :default do puts "Specify a task:" puts " rake pico # build for RP2040" - puts " rake pico_wifi # build for RP2040 with CYW43 WiFi" - puts " rake pico_ble # build for RP2040 with CYW43 BLE" + puts " rake pico_w # build for RP2040 with CYW43" puts " rake pico2 # build for RP2350" end @@ -75,28 +72,15 @@ task :pico_debug do sh "rake debug" end -desc "build for RP2040 with CYW43 WiFi" -task :pico_wifi do - ENV['BOARD'] = 'pico_wifi' - sh "rake all" -end - -desc "build for RP2040 with CYW43 WiFi with debug flags" -task :pico_wifi_debug do - ENV['BOARD'] = 'pico_wifi' - ENV['PICORUBY_DEBUG'] = '1' - sh "rake debug" -end - -desc "build for RP2040 with CYW43 BLE" -task :pico_ble do - ENV['BOARD'] = 'pico_ble' +desc "build for RP2040 with CYW43" +task :pico_w do + ENV['BOARD'] = 'pico_w' sh "rake all" end -desc "build for RP2040 with CYW43 BLE with debug flags" -task :pico_ble_debug do - ENV['BOARD'] = 'pico_ble' +desc "build for RP2040 with CYW43 with debug flags" +task :pico_w_debug do + ENV['BOARD'] = 'pico_w' ENV['PICORUBY_DEBUG'] = '1' sh "rake debug" end @@ -115,7 +99,7 @@ task :pico2_debug do end desc "clean built for RP2xxx" -task clean_all: [:clean_pico, :clean_pico_wifi, :clean_pico_ble, :clean_pico2] +task clean_all: [:clean_pico, :clean_pico_w, :clean_pico2] desc "clean built for RP2040" task :clean_pico do @@ -124,19 +108,13 @@ task :clean_pico do sh "cmake --build build_pico --target clean" end -desc "clean built for RP2040 with CYW43 WiFi" -task :clean_pico_wifi do - ENV['BOARD'] = 'pico_wifi' +desc "clean built for RP2040 with CYW43" +task :clean_pico_w do + ENV['BOARD'] = 'pico_w' sh "rake clean" - sh "cmake --build build_pico_wifi --target clean" + sh "cmake --build build_pico_w --target clean" end -desc "clean built for RP2040 with CYW43 BLE" -task :clean_pico_ble do - ENV['BOARD'] = 'pico_ble' - sh "rake clean" - sh "cmake --build build_pico_ble --target clean" -end desc "clean built for RP2350" task :clean_pico2 do ENV['BOARD'] = 'pico2' @@ -163,7 +141,7 @@ end task :libmruby => "lib/picoruby" do FileUtils.cd "lib/picoruby" do - sh "rake test" +# sh "rake test" sh "MRUBY_CONFIG=#{mruby_config} rake" end end @@ -216,7 +194,7 @@ task :build => :check_pico_sdk do sh "cmake --build #{build_dir}" end -BUILD_DIRS = %w(build_pico build_pico_wifi build_pico_ble build_pico2) +BUILD_DIRS = %w(build_pico build_pico_w build_pico2) desc "deep clean built" task :deep_clean do diff --git a/include-net/mbedtls_config.h b/include-net/mbedtls_config.h deleted file mode 100644 index b6a5c15..0000000 --- a/include-net/mbedtls_config.h +++ /dev/null @@ -1,49 +0,0 @@ -#define MBEDTLS_NO_PLATFORM_ENTROPY -#define MBEDTLS_ENTROPY_HARDWARE_ALT -#define MBEDTLS_HAVE_TIME - -#define MBEDTLS_ERROR_C - -#define MBEDTLS_ENTROPY_C -#define MBEDTLS_CTR_DRBG_C - -#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED -#define MBEDTLS_RSA_C - -#define MBEDTLS_PKCS1_V15 -#define MBEDTLS_BIGNUM_C -#define MBEDTLS_PK_C -#define MBEDTLS_PK_PARSE_C - -#define MBEDTLS_AES_C -#define MBEDTLS_CCM_C -#define MBEDTLS_CIPHER_MODE_CBC -#define MBEDTLS_AES_FEWER_TABLES - -#define MBEDTLS_X509_CRT_PARSE_C -#define MBEDTLS_X509_USE_C -#define MBEDTLS_OID_C -#define MBEDTLS_ASN1_PARSE_C -#define MBEDTLS_ASN1_WRITE_C - -#define MBEDTLS_SHA1_C -#define MBEDTLS_SHA224_C -#define MBEDTLS_SHA256_C -#define MBEDTLS_SHA512_C - -#define MBEDTLS_CIPHER_C -#define MBEDTLS_SSL_TLS_C -#define MBEDTLS_MD_C - -#define MBEDTLS_SSL_CLI_C -#define MBEDTLS_SSL_SERVER_NAME_INDICATION - -#define MBEDTLS_SSL_PROTO_TLS1_2 - -#define MBEDTLS_CIPHER_PADDING_PKCS7 -#define MBEDTLS_CIPHER_MODE_GCM -#define MBEDTLS_GCM_C - -#define PICORUBY_MBEDTLS_USE_R2P2_CONFIG - -#include "mbedtls/check_config.h" diff --git a/lib/picoruby b/lib/picoruby index 2c1cd69..b9c9202 160000 --- a/lib/picoruby +++ b/lib/picoruby @@ -1 +1 @@ -Subproject commit 2c1cd69903d8c2b5dbbc293a99bb72efb34b15ce +Subproject commit b9c9202d24b27369a5c3f8b0102f56d402d24b53 diff --git a/mrblib/main_task.rb b/mrblib/main_task.rb index ffabf67..fb817a1 100644 --- a/mrblib/main_task.rb +++ b/mrblib/main_task.rb @@ -2,34 +2,26 @@ require "watchdog" Watchdog.disable require "shell" - STDOUT = IO STDIN = IO # Setup flash disk begin STDIN.echo = false - $shell = Shell.new(clean: true) puts "Initializing FLASH disk as the root volume... " - $shell.setup_root_volume(:flash, label: "R2P2") - $shell.setup_system_files - puts "Available" -rescue => e - puts "Not available" - puts "#{e.message} (#{e.class})" -end + Shell.setup_root_volume(:flash, label: "R2P2") + Shell.setup_system_files -# Putting this before the shell setup causes the shell to hang -begin - require "cyw43" - ENV['WIFI_MODULE'] = "cwy43" -rescue LoadError - # No WiFi module -end + begin + require "cyw43" + ENV['WIFI_MODULE'] = "cwy43" + rescue LoadError + # No WiFi module + end -begin - $shell.bootstrap("/etc/init.d/r2p2") + Shell.bootstrap("/etc/init.d/r2p2") + $shell = Shell.new(clean: true) puts "Starting shell...\n\n" $shell.show_logo @@ -37,6 +29,5 @@ rescue => e puts "#{e.message} (#{e.class})" - Watchdog.reboot 1000 end diff --git a/src/main.c b/src/main.c index 9688924..a146f12 100644 --- a/src/main.c +++ b/src/main.c @@ -6,15 +6,13 @@ #include /* PicoRuby */ -#include -#include - +#include "picoruby.h" #include "main_task.c" #if !defined(HEAP_SIZE) #if defined(PICO_RP2040) #if defined(USE_WIFI) - #define HEAP_SIZE (1024 * 110) + #define HEAP_SIZE (1024 * 150) #else #define HEAP_SIZE (1024 * 194) #endif