Skip to content

Commit

Permalink
PRK Firmware for RP2350
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Nov 26, 2024
1 parent afed5e1 commit 652b7b6
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 50 deletions.
40 changes: 33 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,27 @@ if(DEFINED ENV{PICORUBY_SQLITE3})
add_definitions(-DPICORUBY_SQLITE3)
endif()

project("prk_firmware-${MSC_NAME}-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
if(DEFINED ENV{PICO2})
set(PICO_BOARD pico2)
set(R2P2_NAME R2P2_PICO2)
set(BUILD_CONFIG prk_firmware-cortex-m33)
set(BUILD_DIR build_pico2)
add_compile_options(
-mcpu=cortex-m33
#-march=armv8-m.main+fp+dsp
#-mabi=aapcs-linux
#-mfloat-abi=softfp
-fno-strict-aliasing
-fno-unroll-loops
-mslow-flash-data
)
else()
set(R2P2_NAME R2P2)
set(BUILD_CONFIG prk_firmware-cortex-m0plus)
set(BUILD_DIR build_pico)
endif()

project("prk_firmware-${PICO_BOARD}-${MSC_NAME}-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")

# Initializing the Raspberry Pi Pico SDK should happen after project created
pico_sdk_init()
Expand Down Expand Up @@ -99,7 +119,7 @@ if(DEFINED ENV{PICORUBY_NO_MSC})
endif()

add_custom_target(mrbdir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/mrb
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb
)

set(RUBY_TASK_FILES
Expand All @@ -108,7 +128,7 @@ set(RUBY_TASK_FILES
foreach(rb ${RUBY_TASK_FILES})
add_custom_target(${rb}
COMMAND ${PICORBC} -B${rb}
-o${CMAKE_SOURCE_DIR}/build/mrb/${rb}.c
-o${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb/${rb}.c
${CMAKE_SOURCE_DIR}/mrblib/${rb}.rb
)
endforeach(rb)
Expand All @@ -124,21 +144,21 @@ target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-mrubyc/lib/mrubyc/src
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/lib/ff14b/source
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/$ENV{MRUBY_CONFIG}/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/${BUILD_CONFIG}/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/${BUILD_CONFIG}/mruby-compiler2/include
${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb
)

target_link_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/lib/picoruby/build/$ENV{MRUBY_CONFIG}/lib
${CMAKE_SOURCE_DIR}/lib/picoruby/build/${BUILD_CONFIG}/lib
)

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
pico_stdlib
pico_bootsel_via_double_reset
tinyusb_device
tinyusb_board
hardware_pio
hardware_sleep
hardware_flash
hardware_adc
hardware_uart
Expand All @@ -150,6 +170,12 @@ target_link_libraries(${PROJECT_NAME}
hardware_pwm
mruby
)
# Workaround for Pico2
if(NOT DEFINED ENV{PICO2})
target_link_libraries(${PROJECT_NAME} PRIVATE
hardware_sleep
)
endif()

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(${PROJECT_NAME})
Expand Down
136 changes: 101 additions & 35 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
require "fileutils"

ENV['MRUBY_CONFIG'] = "prk_firmware-cortex-m0plus"
PICO_SDK_TAG = "2.0.0"
PICO_SDK_TAG = "2.1.0"

task :default => :production
def mruby_config
case ENV['BOARD']&.downcase
when 'pico2'
'prk_firmware-cortex-m33'
else
'prk_firmware-cortex-m0plus'
end
end

def cmake_flags
flags = []
case ENV['BOARD']&.downcase
when 'pico2'
flags << "PICO2=yes"
end
flags.join(" ")
end

def def_board
case ENV['BOARD']&.downcase
when 'pico2'
'-DPICO_PLATFORM=rp2350 -DPICO_BOARD=pico2'
else
'-DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico'
end
end

def build_dir
dir = case ENV['BOARD']&.downcase
when 'pico2'
"#{ENV['WITH_KEYMAP_DIR']}build_pico2"
else
"#{ENV['WITH_KEYMAP_DIR']}build_pico"
end
FileUtils.mkdir_p dir
dir
end

task :default do
puts "Specify a task:"
puts " rake pico # build for RP2040"
puts " rake pico2 # build for RP2350"
end

task :setup do
sh "bundle install"
Expand All @@ -15,36 +56,65 @@ end

task :all => [:libmruby, :cmake, :build]

desc "build debug (you may need to rake clean before this)"
task :debug do
desc "build debug for RP2040 (you may need to rake clean before this)"
task :pico_debug do
ENV['PICORUBY_DEBUG'] = '1'
ENV['BOARD'] = 'pico'
ENV['CMAKE_BUILD_TYPE'] = 'Debug'
Rake::Task[:all].invoke
end

desc "build production"
task :production do
desc "build production for RP2040"
task :pico do
ENV['BOARD'] = 'pico'
ENV['CMAKE_BUILD_TYPE'] = 'Release'
Rake::Task[:all].invoke
end

desc "build PRK Firmware inclusive of keymap.rb (without mass storage)"
task :build_with_keymap, ['keyboard_name'] do |_t, args|
desc "build debug for RP2350 (you may need to rake clean before this)"
task :pico2_debug do
ENV['PICORUBY_DEBUG'] = '1'
ENV['BOARD'] = 'pico2'
ENV['CMAKE_BUILD_TYPE'] = 'Debug'
Rake::Task[:all].invoke
end

desc "build production for RP2350"
task :pico2 do
ENV['BOARD'] = 'pico2'
ENV['CMAKE_BUILD_TYPE'] = 'Release'
Rake::Task[:all].invoke
end

def with_keymap(board)
ENV['BOARD'] = board
ENV['PICORUBY_NO_MSC'] = '1'
ENV['WITH_KEYMAP_DIR'] = "keyboards/#{args.keyboard_name}/"
Rake::Task[:all].invoke
end

desc "build PRK Firmware inclusive of keymap.rb (without mass storage) for RP2040"
task :build_with_keymap_pico, ['keyboard_name'] do |_t, args|
unless args.keyboard_name
raise "Argument `keyboard_name` missing.\nUsage: rake build_with_keymap[prk_meishi2]"
end
dir = "keyboards/#{args.keyboard_name}"
FileUtils.mkdir_p "#{dir}/build"
ENV['PICORUBY_NO_MSC'] = '1'
ENV['PRK_BUILD_DIR'] = "#{dir}/"
Rake::Task[:all].invoke
with_keymap('pico')
end

desc "build PRK Firmware inclusive of keymap.rb (without mass storage) for RP2350 (Pico2)"
task :build_with_keymap_pico2, ['keyboard_name'] do |_t, args|
unless args.keyboard_name
raise "Argument `keyboard_name` missing.\nUsage: rake build_with_keymap[prk_meishi2]"
end
with_keymap('pico2')
end

desc "build production with SQLite3 and SD card"
desc "build production with SQLite3 and SD card for RP2350 (Pico2)"
task :sqlite3 do
ENV['PICORUBY_SQLITE3'] = '1'
ENV['PICORUBY_SD_CARD'] = '1'
ENV['PICORUBY_MSC_SD'] = '1'
ENV['BOARD'] = 'pico2'
Rake::Task[:all].invoke
end

Expand All @@ -55,12 +125,12 @@ end
task :libmruby => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=default rake test"
sh "rake"
sh "MRUBY_CONFIG=#{mruby_config} rake"
end
end

task :cmake do
sh "cmake -DCMAKE_BUILD_TYPE=#{ENV['CMAKE_BUILD_TYPE']} -B #{ENV['PRK_BUILD_DIR']}build"
sh "#{cmake_flags} cmake #{def_board} -DCMAKE_BUILD_TYPE=#{ENV['CMAKE_BUILD_TYPE']} -B #{build_dir}"
end

task :check_pico_sdk => :check_pico_sdk_path do
Expand All @@ -85,29 +155,23 @@ end

desc "build without cmake preparation"
task :build => :check_pico_sdk do
sh "cmake --build #{ENV['PRK_BUILD_DIR']}build"
end

desc "clean built that includes keymap"
task :clean_with_keymap , ['keyboard_name'] do |_t, args|
unless args.keyboard_name
raise "Argument `keyboard_name` missing.\nUsage: rake clean_with_keymap[prk_meishi2]"
end
FileUtils.rm_r Dir.glob("keyboards/#{args.keyboard_name}/build/*")
sh "cmake --build #{build_dir}"
end

desc "clean built"
task :clean do
FileUtils.cd "lib/picoruby" do
sh "rake clean"
end
FileUtils.cd "build" do
FileUtils.rm_rf Dir.glob("prk_firmware-*.*")
end
begin
sh "cmake --build build --target clean"
rescue => e
puts "Ignoring an error: #{e.message}"
%(build_pico build_pico2).each do |dir|
FileUtils.cd dir do
FileUtils.rm_rf Dir.glob("prk_firmware-*.*")
end
begin
sh "cmake --build #{dir} --target clean"
rescue => e
puts "Ignoring an error: #{e.message}"
end
end
end

Expand All @@ -116,8 +180,10 @@ task :deep_clean do
FileUtils.cd "lib/picoruby" do
sh "rake deep_clean"
end
FileUtils.cd "build" do
FileUtils.rm_rf Dir.glob("*")
%(build_pico build_pico2).each do |dir|
FileUtils.cd dir do
FileUtils.rm_rf Dir.glob("*")
end
end
end

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions build_pico2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.keep
!.gitignore
Empty file added build_pico2/.keep
Empty file.
26 changes: 19 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@
#include "../include/sounder.h"

/* tasks */
#include "../build/mrb/usb_task.c"
#include "usb_task.c"

#ifdef PICORUBY_NO_MSC
#include <keymap.c>
#endif

#if defined(PICORUBY_SQLITE3)
#define MEMORY_SIZE (1024*184)
#else
#define MEMORY_SIZE (1024*194)

#if !defined(HEAP_SIZE)
#if defined(PICO_RP2040)
#if defined(PICORUBY_SQLITE3)
#error "Not enough memory for SQLite3 in RP2040"
#endif
#define HEAP_SIZE (1024 * 194)
#elif defined(PICO_RP2350)
#if defined(PICORUBY_SQLITE3)
#define HEAP_SIZE (1024 * (194 + 240))
#else
#define HEAP_SIZE (1024 * (194 + 260))
#endif
#else
#error "Unknown board"
#endif
#endif

static uint8_t memory_pool[MEMORY_SIZE];
static uint8_t memory_pool[HEAP_SIZE];

int autoreload_state; /* from keyboard.h */

Expand Down Expand Up @@ -83,7 +95,7 @@ main(void)
stdio_init_all();
board_init();
/* PicoRuby */
mrbc_init(memory_pool, MEMORY_SIZE);
mrbc_init(memory_pool, HEAP_SIZE);
prk_init_picoruby();
/* Tasks */
mrbc_create_task(usb_task, 0);
Expand Down

0 comments on commit 652b7b6

Please sign in to comment.