From 8d119ccf2eb0f39a019fc9b2fc02fe149f941647 Mon Sep 17 00:00:00 2001 From: lukstep Date: Sat, 17 Sep 2022 08:52:28 +0200 Subject: [PATCH] Add sample C project --- CMakeLists.txt | 18 ++++++++++++++++++ README.md | 16 +++++++++++++++- main.c | 27 +++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 main.c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..81b8e8e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.13) + +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) + +project(sample C CXX ASM) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +pico_sdk_init() + +add_executable(sample main.c) + +pico_enable_stdio_usb(sample 1) +pico_enable_stdio_uart(sample 1) +pico_add_extra_outputs(sample) + +target_link_libraries(sample pico_stdlib) diff --git a/README.md b/README.md index 47dc09e..769d408 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Raspberry Pi Pico Docker +# Raspberry Pi Pico Docker SDK ## Run Docker container @@ -9,3 +9,17 @@ docker run -d -it --name pico-sdk --mount type=bind,source=${PWD},target=/home/d docker exec -it pico-sdk /bin/sh ``` + +## Project build + +After attaching to SDK container run the following command to build the project: +``` +cd /home/dev + +mkdir build + +cd build + +cmake .. && make -j4 + +``` diff --git a/main.c b/main.c new file mode 100644 index 0000000..5113755 --- /dev/null +++ b/main.c @@ -0,0 +1,27 @@ +#include +#include "pico/stdlib.h" +#include "hardware/gpio.h" +#include "pico/binary_info.h" + +int LED_PIN = 25; + +int main () +{ + bi_decl(bi_program_description("Sample binary")); + bi_decl(bi_1pin_with_name(LED_PIN, "on-board PIN")); + + stdio_init_all(); + + gpio_init(); + gpio_set_dir(LED_PIN, GPIO_OUT); + + while(1) + { + gpio_put(LED_PIN, 0); + sleep_ms(250); + gpio_put(LED_PIN, 1); + puts("Hello Word\n"); + sleep_ms(1000); + } +} +