stub.cをラズピコで動かす
code:sh
test/%: test/%.s libmincaml.S stub.c
$(CC) $(CFLAGS) -m32 $^ -lm -o $@
事前準備
以下の CMakeLists.txt を用意
code:CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(pico-min-caml C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(min-caml
# min_caml_start.s
# libmincaml.S
stub.c
)
pico_enable_stdio_usb(min-caml 1)
# pico_enable_stdio_uart(min-caml 1)
pico_add_extra_outputs(min-caml)
target_link_libraries(min-caml pico_stdlib)
piko-sdk から pico_sdk_import.cmake をコピー
code:sh
cp ~/src/pico/pico-sdk/external/pico_sdk_import.cmake ~/src/min-caml-pico/
stub.cを書き換え
code:stub.c
const uint LED_PIN = 25;
extern void min_caml_start(char *, char *);
/* "stderr" is a macro and cannot be referred to in libmincaml.S, so
this "min_caml_stderr" is used (in place of "__iob+32") for better
portability (under SPARC emulators, for example). Thanks to Steven
Shaw for reporting the problem and proposing this solution. */
FILE *min_caml_stderr;
int main() {
bi_decl(bi_program_description("This is a test binary."));
bi_decl(bi_1pin_with_name(LED_PIN, "On-board LED"));
stdio_init_all();
// MinCaml の処理 (ここから)
char *hp, *sp;
sp = alloca(1000000); hp = malloc(4000000);
if (hp == NULL || sp == NULL) {
fprintf(stderr, "malloc or alloca failed\n");
return 1;
}
fprintf(stderr, "sp = %p, hp = %p\n", sp, hp);
// min_caml_start(sp, hp);
// MinCaml の処理 (ここまで)
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (1) {
gpio_put(LED_PIN, 0);
sleep_ms(250);
gpio_put(LED_PIN, 1);
puts("Hello World\n");
sleep_ms(1000);
}
return 0;
}
ビルド
code:sh
cd ~/src/min-caml-pico
mkdir build
cd build
cmake ..
make
アップロード
以下の手順でラズピコへアップロード & 実行する
(1) ラズピコ本体のBOOTSELボタンを押しながらラズピコをPCへ刺す
(2) cp min-caml.uf2 /Volumes/RPI-RP2/ で作成したバイナリをラズピコへアップロード
(3) ls /dev/cu.* して /dev/cu.usbmodem21101 が存在することを確認(環境によって違うかも)
(4) ./run.sh /dev/cu.usbmodem21101 を実行