Skip to content

Commit 3068e1b

Browse files
author
sidart
committed
Summary: Add Initial support to pico2 (Arm Cortex M)
Test Plan: TBD Reviewers: Subscribers: Tasks: Tags:
1 parent 56392aa commit 3068e1b

File tree

8 files changed

+285
-0
lines changed

8 files changed

+285
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ install(FILES tools/cmake/executorch-config.cmake
479479

480480
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
481481
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
482+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/raspberry_pi)
482483
endif()
483484

484485
if(EXECUTORCH_BUILD_CADENCE)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(pico)
3+
4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../)
6+
7+
8+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/arm-cortex-m0plus-toolchain.cmake)
9+
10+
# Only include here, NOT in arm-cortex-m0plus-toolchain.cmake
11+
include(${CMAKE_SOURCE_DIR}/tools/cmake/Codegen.cmake)
12+
13+
target_sources(executorch_core PRIVATE ${CMAKE_CURRENT_LIST_DIR}/syscall_stubs.c)
14+
gen_selected_ops(LIB_NAME "portable_ops_lib" ROOT_OPS "aten::add.out")

backends/raspberry_pi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# cortex-m0plus cmake
2+
3+
if(NOT DEFINED EXECUTORCH_BUILD_ARM_BAREMETAL)
4+
# If not defined, assume we're building standalone
5+
set(EXECUTORCH_BUILD_ARM_BAREMETAL ON)
6+
endif()
7+
set(CMAKE_SYSTEM_NAME Generic)
8+
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
9+
10+
if(NOT DEFINED CMAKE_C_COMPILER)
11+
set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE STRING "C compiler")
12+
endif()
13+
14+
if(NOT DEFINED CMAKE_CXX_COMPILER)
15+
set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE STRING "C++ compiler")
16+
endif()
17+
18+
set(CPU_FLAGS "-mcpu=cortex-m0plus -mthumb -mfloat-abi=soft")
19+
# C flags (no RTTI or exceptions here, since RTTI is C++-only)
20+
set(CMAKE_C_FLAGS "${CPU_FLAGS} -O2 -ffunction-sections -fdata-sections -fno-exceptions -fno-unwind-tables")
21+
22+
# C++ flags (RTTI-related flags go here)
23+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-use-cxa-atexit -ffunction-sections -fdata-sections")
24+
25+
# Linker flags
26+
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -nostartfiles -flto")
27+
28+
# Linker flags
29+
set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
3+
project(executorch_pico C CXX ASM)
4+
pico_sdk_init()
5+
6+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../)
7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8+
9+
add_executable(executorch_pico main.cpp simple_addmodule_pte.c)
10+
pico_enable_stdio_usb(executorch_pico 1)
11+
pico_enable_stdio_uart(executorch_pico 0)
12+
13+
# Set correct flags for Pico (Cortex-M0+)
14+
target_compile_options(executorch_pico PRIVATE
15+
-mcpu=cortex-m0plus
16+
-mfloat-abi=soft
17+
-mthumb
18+
)
19+
20+
# Link Executorch and Pico libraries
21+
target_link_libraries(executorch_pico
22+
PRIVATE
23+
${EXECUTORCH_ROOT}/executorch/build/libexecutorch.a
24+
${EXECUTORCH_ROOT}/executorch/build/libexecutorch_core.a
25+
-Wl,--whole-archive
26+
${EXECUTORCH_ROOT}/executorch/build/kernels/portable/libportable_ops_lib.a
27+
-Wl,--no-whole-archive
28+
${EXECUTORCH_ROOT}/executorch/build/kernels/portable/libportable_kernels.a
29+
pico_stdlib
30+
pico_stdio_usb
31+
)
32+
33+
# Include Executorch and third-party headers
34+
target_include_directories(executorch_pico PRIVATE
35+
${EXECUTORCH_ROOT}
36+
${EXECUTORCH_ROOT}/executorch/third-party/
37+
# Add other include paths as needed
38+
)
39+
40+
pico_add_extra_outputs(executorch_pico)
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#include "pico/stdio_usb.h"
2+
#include "pico/stdlib.h"
3+
4+
#include <executorch/extension/data_loader/buffer_data_loader.h>
5+
#include <executorch/runtime/core/portable_type/scalar_type.h>
6+
#include <executorch/runtime/executor/method.h>
7+
#include <executorch/runtime/executor/program.h>
8+
#include <executorch/runtime/platform/runtime.h>
9+
10+
// Declare your model data (from simple_addmodule_pte.c)
11+
extern const uint8_t model_pte[] __attribute__((aligned(8)));
12+
extern const unsigned int model_pte_len;
13+
14+
// Define GPIO pins for indicators
15+
const uint INDICATOR_PIN_1 = 25; // Onboard LED
16+
const uint INDICATOR_PIN_2 = 22; // External LED
17+
const uint INDICATOR_PIN_3 = 23; // Onboard LED
18+
19+
static uint8_t method_allocator_pool[1024];
20+
static uint8_t activation_pool[512];
21+
22+
void blink_indicator(uint pin, int times, int delay_ms = 100) {
23+
gpio_init(pin);
24+
gpio_set_dir(pin, GPIO_OUT);
25+
for (int i = 0; i < times; ++i) {
26+
gpio_put(pin, 1);
27+
sleep_ms(delay_ms);
28+
gpio_put(pin, 0);
29+
sleep_ms(delay_ms);
30+
}
31+
}
32+
33+
int main() {
34+
using namespace executorch::extension;
35+
using namespace executorch::runtime;
36+
using executorch::aten::Tensor;
37+
using executorch::aten::TensorImpl;
38+
using ScalarType = executorch::runtime::etensor::ScalarType;
39+
using executorch::runtime::runtime_init;
40+
41+
stdio_init_all();
42+
43+
// Give host time to enumerate USB serial
44+
sleep_ms(1000);
45+
46+
int retry_usb_count= 0;
47+
while (!stdio_usb_connected() && retry_usb_count++ < 10) {
48+
printf("Retry again! USB not connected \n");
49+
sleep_ms(100); // Check every 100 ms
50+
}
51+
runtime_init();
52+
53+
executorch::extension::BufferDataLoader loader(model_pte, model_pte_len);
54+
MemoryAllocator method_allocator(sizeof(method_allocator_pool), method_allocator_pool);
55+
method_allocator.enable_profiling("method allocator");
56+
57+
Span<uint8_t> memory_planned_buffers[1]{{activation_pool, sizeof(activation_pool)}};
58+
HierarchicalAllocator planned_memory({memory_planned_buffers, 1});
59+
60+
MemoryManager memory_manager(&method_allocator, &planned_memory);
61+
auto program_result = Program::load(&loader);
62+
if (!program_result.ok()) {
63+
printf("Failed to load model: %d\n", (int)program_result.error());
64+
blink_indicator(INDICATOR_PIN_1, 10);
65+
return 1;
66+
}
67+
Program program = std::move(*program_result);
68+
69+
const char* method_name = nullptr;
70+
// Get method name (usually "forward")
71+
auto method_name_result = program.get_method_name(0);
72+
if (!method_name_result.ok()) {
73+
printf("Failed to get method name: %d\n", (int)method_name_result.error());
74+
blink_indicator(INDICATOR_PIN_1, 10);
75+
return 1;
76+
}
77+
78+
method_name = *method_name_result;
79+
// Load method
80+
auto method_result = program.load_method(method_name, &memory_manager);
81+
if (!method_result.ok()) {
82+
printf("Failed to load method: %d\n", (int)method_result.error());
83+
blink_indicator(INDICATOR_PIN_1, 10);
84+
return 1;
85+
}
86+
printf("Method loaded [%s]\n", method_name);
87+
88+
auto method = std::move(*method_result);
89+
// Prepare input tensor
90+
float input_data_0[4] = {4.0, 109.0, 13.0, 123.0};
91+
float input_data_1[4] = {9.0, 27.0, 11.0, 8.0};
92+
TensorImpl::SizesType sizes[1] = {4};
93+
TensorImpl::DimOrderType dim_order[] = {0};
94+
TensorImpl impl0(ScalarType::Float, 1, sizes, input_data_0, dim_order);
95+
TensorImpl impl1(ScalarType::Float, 1, sizes, input_data_1, dim_order);
96+
Tensor input0(&impl0);
97+
Tensor input1(&impl1);
98+
99+
// Set input
100+
auto set_input_error0 = method.set_input(input0, 0);
101+
auto set_input_error1 = method.set_input(input1, 1);
102+
if (set_input_error0 != Error::Ok || set_input_error1 != Error::Ok) {
103+
printf("Failed to set input(s)\n");
104+
blink_indicator(INDICATOR_PIN_1, 10);
105+
return 1;
106+
}
107+
108+
// Run inference
109+
auto exec_error = method.execute();
110+
if (exec_error != Error::Ok) {
111+
printf("Failed to execute: %d\n", (int)exec_error);
112+
blink_indicator(INDICATOR_PIN_1, 10);
113+
return 1;
114+
}
115+
116+
// Get output
117+
const EValue& output = method.get_output(0);
118+
if (output.isTensor()) {
119+
const auto& out_tensor = output.toTensor();
120+
const float* out_data = out_tensor.const_data_ptr<float>();
121+
printf("Output: %f, %f, %f, %f\n", out_data[0], out_data[1], out_data[2], out_data[3]);
122+
} else {
123+
printf("Output is not a tensor!\n");
124+
blink_indicator(INDICATOR_PIN_1, 10);
125+
}
126+
127+
blink_indicator(INDICATOR_PIN_1, 100, 500); // Blink onboard LED 10 times (~10 secs) to indicate success
128+
return 0;
129+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
__attribute__((aligned(8))) const unsigned char model_pte[] = {
2+
0x1c, 0x00, 0x00, 0x00, 0x45, 0x54, 0x31, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x10, 0x00, 0x00, 0x00,
3+
0x44, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
4+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5+
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x28, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x1c, 0x00,
6+
0x20, 0x00, 0x24, 0x00, 0x16, 0x00, 0x00, 0x00, 0x9c, 0x03, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,
7+
0x24, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8+
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x38, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x75, 0x74, 0x00,
9+
0x09, 0x00, 0x00, 0x00, 0x61, 0x74, 0x65, 0x6e, 0x3a, 0x3a, 0x61, 0x64, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x04, 0x00,
10+
0x08, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x24, 0xff, 0xff, 0xff,
11+
0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12+
0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
13+
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
14+
0x44, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15+
0x00, 0x00, 0x00, 0x00, 0x68, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x05, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x16, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00,
16+
0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00,
17+
0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00,
18+
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
19+
0x8c, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0e, 0x00,
20+
0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x14, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00,
21+
0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xe4, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
22+
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00,
23+
0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x5b, 0x31, 0x2c, 0x20, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22,
24+
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a,
25+
0x20, 0x5b, 0x5d, 0x7d, 0x5d, 0x00, 0x00, 0x00, 0x34, 0x01, 0x00, 0x00, 0x5b, 0x31, 0x2c, 0x20, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69,
26+
0x6e, 0x73, 0x2e, 0x74, 0x75, 0x70, 0x6c, 0x65, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x6e, 0x75, 0x6c, 0x6c, 0x22, 0x2c, 0x20, 0x22, 0x63,
27+
0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69,
28+
0x6e, 0x73, 0x2e, 0x74, 0x75, 0x70, 0x6c, 0x65, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x6e, 0x75, 0x6c, 0x6c, 0x22, 0x2c, 0x20, 0x22, 0x63,
29+
0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22,
30+
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a,
31+
0x20, 0x5b, 0x5d, 0x7d, 0x2c, 0x20, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20,
32+
0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x5d, 0x7d, 0x5d, 0x7d, 0x2c, 0x20, 0x7b, 0x22,
33+
0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69, 0x6e, 0x73, 0x2e, 0x64, 0x69, 0x63, 0x74, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
34+
0x22, 0x3a, 0x20, 0x22, 0x5b, 0x5d, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x5d, 0x7d, 0x5d, 0x7d, 0x5d,
35+
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x00, };
36+
37+
38+
const unsigned int model_pte_len = sizeof(model_pte);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <sys/types.h>
2+
#include <sys/stat.h>
3+
#include <unistd.h>
4+
5+
/*
6+
* We are adding a custom syscall_stubs.c file to provide dummy implementations for syscalls that are not
7+
* available on the Pico platform. This is necessary because the Pico does not have an operating system,
8+
* and therefore does not support standard C library functions like _exit, _sbrk, _read, etc.
9+
* By adding these stubs, we can resolve linker errors that occur when building our project for the Pico.
10+
* The stubs will be compiled and linked into our final executable, allowing it to run on the target hardware.
11+
*/
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
void *__dso_handle = 0;
16+
int fnmatch(const char *pattern, const char *string, int flags) { return 1; }
17+
ssize_t pread(int fd, void *buf, size_t count, off_t offset) { return -1; }
18+
void _fini(void) {}
19+
void _exit(int status) { while (1) {} }
20+
void* _sbrk(ptrdiff_t incr) { return (void*)-1; }
21+
int _read(int file, char *ptr, int len) { return -1; }
22+
int _write(int file, char *ptr, int len) { return -1; }
23+
int _close(int file) { return -1; }
24+
int _fstat(int file, void *st) { return 0; }
25+
int _lseek(int file, int ptr, int dir) { return 0; }
26+
int _isatty(int file) { return 1; }
27+
int _kill(int pid, int sig) { return -1; }
28+
int _getpid(void) { return 1; }
29+
int _open(const char *name, int flags, int mode) { return -1; }
30+
int _gettimeofday(void *tv, void *tz) { return -1; }
31+
#ifdef __cplusplus
32+
}
33+
#endif

0 commit comments

Comments
 (0)