From 04111f06c66f6f935651903e85bda36d6f05d349 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 25 Apr 2024 12:47:39 +0200 Subject: improve build/flash instructions --- main/makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 main/makefile (limited to 'main/makefile') diff --git a/main/makefile b/main/makefile new file mode 100644 index 0000000..833fd02 --- /dev/null +++ b/main/makefile @@ -0,0 +1,22 @@ +# this file is for lazy people (loek) + +.PHONY: FORCE + +all: FORCE build/main.uf2 + +build/build.ninja: CMakeLists.txt + mkdir -p build + cmake -B build -G Ninja + +build/main.uf2: build/build.ninja FORCE + ninja -C build +# ninja automatically builds in parallel, so is preferred + +flash: build/main.uf2 FORCE + picotool load -fx $< +# -f forces a reboot of the pico before flashing +# -x resets the pico after flashing + +clean: FORCE + $(RM) -r build + -- cgit v1.2.3 From 0ef1ae11846bfcbbd63e22d1dfecf579f4069c80 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 25 Apr 2024 14:28:45 +0200 Subject: WIP FreeRTOS --- .gitmodules | 5 ++++ main/CMakeLists.txt | 19 ++++++++----- main/FreeRTOSConfig.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ main/lib/FreeRTOS-Kernel | 1 + main/main.cpp | 29 +++++++++++++------- main/makefile | 2 +- 6 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 main/FreeRTOSConfig.h create mode 160000 main/lib/FreeRTOS-Kernel (limited to 'main/makefile') diff --git a/.gitmodules b/.gitmodules index c951407..58b768d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,8 @@ url = https://github.com/google/googletest branch = v1.14.0 shallow = true +[submodule "main/lib/FreeRTOS-Kernel"] + path = main/lib/FreeRTOS-Kernel + url = https://github.com/FreeRTOS/FreeRTOS-Kernel + branch = V11.1.0 + shallow = true diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e24d9a5..590d516 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,22 +1,29 @@ cmake_minimum_required(VERSION 3.29) -include(lib/pico-sdk/pico_sdk_init.cmake) - -project(puzzlebox_main C CXX ASM) - set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(PICO_BOARD pico_w) +include(lib/pico-sdk/pico_sdk_init.cmake) +include(lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) + +project(puzzlebox_main C CXX ASM) + pico_sdk_init() add_executable(main main.cpp -) + ) pico_enable_stdio_usb(main 1) # pico_enable_stdio_uart(main 1) pico_add_extra_outputs(main) + target_include_directories(main PRIVATE ${CMAKE_CURRENT_LIST_DIR}) -target_link_libraries(main pico_cyw43_arch_lwip_threadsafe_background pico_stdlib) +target_link_libraries(main + pico_cyw43_arch_lwip_threadsafe_background + pico_stdlib + FreeRTOS-Kernel + ) + diff --git a/main/FreeRTOSConfig.h b/main/FreeRTOSConfig.h new file mode 100644 index 0000000..305bcb4 --- /dev/null +++ b/main/FreeRTOSConfig.h @@ -0,0 +1,69 @@ +#pragma once +// values from pico-examples/pico_w/wifi/freertos + +#define configUSE_PREEMPTION 1 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configTICK_RATE_HZ ((TickType_t) 1000) +#define configMAX_PRIORITIES 32 +#define configMINIMAL_STACK_SIZE ((configSTACK_DEPTH_TYPE) 256) +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_QUEUE_SETS 1 +#define configUSE_TIME_SLICING 1 +#define configUSE_NEWLIB_REENTRANT 0 +#define configENABLE_BACKWARD_COMPATIBILITY 1 +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 +#define configSTACK_DEPTH_TYPE uint32_t +#define configMESSAGE_BUFFER_LENGTH_TYPE size_t +#define configSUPPORT_STATIC_ALLOCATION 0 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 +#define configTOTAL_HEAP_SIZE (128 * 1024) +#define configAPPLICATION_ALLOCATED_HEAP 0 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 +#define configGENERATE_RUN_TIME_STATS 0 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 0 +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES 1 +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH 1024 + +// #define configNUM_CORES 2 +// #define configTICK_CORE 0 +// #define configRUN_MULTIPLE_PRIORITIES 1 +// #define configUSE_CORE_AFFINITY 1 + +#define configSUPPORT_PICO_SYNC_INTEROP 1 +#define configSUPPORT_PICO_TIME_INTEROP 1 + +#include +#define configASSERT(x) assert(x) + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_xTaskResumeFromISR 1 +#define INCLUDE_xQueueGetMutexHolder 1 + diff --git a/main/lib/FreeRTOS-Kernel b/main/lib/FreeRTOS-Kernel new file mode 160000 index 0000000..dbf7055 --- /dev/null +++ b/main/lib/FreeRTOS-Kernel @@ -0,0 +1 @@ +Subproject commit dbf70559b27d39c1fdb68dfb9a32140b6a6777a0 diff --git a/main/main.cpp b/main/main.cpp index 9fd3123..d118de2 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,12 +1,23 @@ -#include - #include "config.h" -#include "pico/stdlib.h" -#include "pico/cyw43_arch.h" +#include +#include + +#include +#include +#include const unsigned int LED_PIN = CYW43_WL_GPIO_LED_PIN; +void blink_task() { + while (true) { + cyw43_arch_gpio_put(LED_PIN, 0); + sleep_ms(250); + cyw43_arch_gpio_put(LED_PIN, 1); + sleep_ms(250); + } +} + int main() { stdio_init_all(); sleep_ms(2000); @@ -16,6 +27,8 @@ int main() { return 1; } cyw43_arch_gpio_put(LED_PIN, 1); + + printf("initialised\n"); cyw43_arch_enable_sta_mode(); @@ -26,11 +39,7 @@ int main() { } printf("connected\n"); - while (true) { - cyw43_arch_gpio_put(LED_PIN, 0); - sleep_ms(250); - cyw43_arch_gpio_put(LED_PIN, 1); - sleep_ms(250); - } + xTaskCreate((TaskFunction_t) blink_task, "blink", 128, NULL, 1, NULL); + vTaskStartScheduler(); } diff --git a/main/makefile b/main/makefile index 833fd02..1986cd3 100644 --- a/main/makefile +++ b/main/makefile @@ -6,7 +6,7 @@ all: FORCE build/main.uf2 build/build.ninja: CMakeLists.txt mkdir -p build - cmake -B build -G Ninja + cmake -B build -G Ninja --fresh --log-level WARNING build/main.uf2: build/build.ninja FORCE ninja -C build -- cgit v1.2.3 From 573643a1d3220830de47c810cb1a6be629ce7abd Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 10 May 2024 14:49:36 +0200 Subject: WIP protobuf hello world --- .gitignore | 3 ++- .gitmodules | 12 ++++++------ client/.gitignore | 1 + client/CMakeLists.txt | 14 ++++++++++++++ client/compile_commands.json | 1 + client/main.cpp | 25 +++++++++++++++++++++++++ client/makefile | 2 ++ lazy.mk | 20 ++++++++++++++++++++ lib/FreeRTOS-Kernel | 1 + lib/googletest | 1 + lib/pico-sdk | 1 + main/.gitignore | 2 -- main/lib | 1 + main/lib/FreeRTOS-Kernel | 1 - main/lib/pico-sdk | 1 - main/makefile | 19 +++---------------- proto/.gitignore | 1 + proto/include.cmake | 1 + proto/makefile | 7 +++++++ proto/puzbusv1.proto | 12 ++++++++++++ test/CMakeLists.txt | 2 +- test/lib | 1 + test/lib/googletest | 1 - 23 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 client/.gitignore create mode 100644 client/CMakeLists.txt create mode 120000 client/compile_commands.json create mode 100644 client/main.cpp create mode 100644 client/makefile create mode 100644 lazy.mk create mode 160000 lib/FreeRTOS-Kernel create mode 160000 lib/googletest create mode 160000 lib/pico-sdk create mode 120000 main/lib delete mode 160000 main/lib/FreeRTOS-Kernel delete mode 160000 main/lib/pico-sdk create mode 100644 proto/.gitignore create mode 100644 proto/include.cmake create mode 100644 proto/makefile create mode 100644 proto/puzbusv1.proto create mode 120000 test/lib delete mode 160000 test/lib/googletest (limited to 'main/makefile') diff --git a/.gitignore b/.gitignore index 0902ca8..19dc4f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build -.vscode/** \ No newline at end of file +.vscode/** +.cache diff --git a/.gitmodules b/.gitmodules index 58b768d..fc98963 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,15 +1,15 @@ -[submodule "main/lib/pico-sdk"] - path = main/lib/pico-sdk +[submodule "pico-sdk"] + path = lib/pico-sdk url = https://github.com/raspberrypi/pico-sdk branch = 1.5.1 shallow = true -[submodule "test/lib/googletest"] - path = test/lib/googletest +[submodule "googletest"] + path = lib/googletest url = https://github.com/google/googletest branch = v1.14.0 shallow = true -[submodule "main/lib/FreeRTOS-Kernel"] - path = main/lib/FreeRTOS-Kernel +[submodule "FreeRTOS-Kernel"] + path = lib/FreeRTOS-Kernel url = https://github.com/FreeRTOS/FreeRTOS-Kernel branch = V11.1.0 shallow = true diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..ba2906d --- /dev/null +++ b/client/.gitignore @@ -0,0 +1 @@ +main diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 0000000..9e433b1 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.29) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +include(../proto/include.cmake) + +project(puzzlebox_client C CXX) + +add_executable(main + main.cpp + ) + diff --git a/client/compile_commands.json b/client/compile_commands.json new file mode 120000 index 0000000..25eb4b2 --- /dev/null +++ b/client/compile_commands.json @@ -0,0 +1 @@ +build/compile_commands.json \ No newline at end of file diff --git a/client/main.cpp b/client/main.cpp new file mode 100644 index 0000000..7a05049 --- /dev/null +++ b/client/main.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "puzbusv1.pb.h" + +int main() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + puzbus::I2CMsg test_msg; + + test_msg.set_address(0x39); + test_msg.set_data("Test message data!"); + + std::string output; + test_msg.SerializeToString(&output); + + printf("output[%lu]:\n", output.size()); + for (size_t i = 0; i < output.size(); i++) { + printf("%02x ", output[i]); + } + printf("\n"); + + return 0; +} + diff --git a/client/makefile b/client/makefile new file mode 100644 index 0000000..8352615 --- /dev/null +++ b/client/makefile @@ -0,0 +1,2 @@ +include ../lazy.mk + diff --git a/lazy.mk b/lazy.mk new file mode 100644 index 0000000..2620961 --- /dev/null +++ b/lazy.mk @@ -0,0 +1,20 @@ +# this file is for lazy people (loek) + +BUILD_DIR ?= build +TARGET ?= $(BUILD_DIR)/main + +.PHONY: FORCE + +all: FORCE $(TARGET) + +$(BUILD_DIR)/build.ninja: CMakeLists.txt + mkdir -p $(BUILD_DIR) + cmake -B $(BUILD_DIR) -G Ninja --fresh --log-level WARNING + +$(TARGET): $(BUILD_DIR)/build.ninja FORCE + ninja -C $(BUILD_DIR) +# ninja automatically builds in parallel, so is preferred + +clean: FORCE + $(RM) -r $(BUILD_DIR) + diff --git a/lib/FreeRTOS-Kernel b/lib/FreeRTOS-Kernel new file mode 160000 index 0000000..dbf7055 --- /dev/null +++ b/lib/FreeRTOS-Kernel @@ -0,0 +1 @@ +Subproject commit dbf70559b27d39c1fdb68dfb9a32140b6a6777a0 diff --git a/lib/googletest b/lib/googletest new file mode 160000 index 0000000..5197b1a --- /dev/null +++ b/lib/googletest @@ -0,0 +1 @@ +Subproject commit 5197b1a8e6a1ef9f214f4aa537b0be17cbf91946 diff --git a/lib/pico-sdk b/lib/pico-sdk new file mode 160000 index 0000000..6a7db34 --- /dev/null +++ b/lib/pico-sdk @@ -0,0 +1 @@ +Subproject commit 6a7db34ff63345a7badec79ebea3aaef1712f374 diff --git a/main/.gitignore b/main/.gitignore index 7c3ba25..0e56cf2 100644 --- a/main/.gitignore +++ b/main/.gitignore @@ -1,3 +1 @@ config.h -build -.cache diff --git a/main/lib b/main/lib new file mode 120000 index 0000000..dc598c5 --- /dev/null +++ b/main/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file diff --git a/main/lib/FreeRTOS-Kernel b/main/lib/FreeRTOS-Kernel deleted file mode 160000 index dbf7055..0000000 --- a/main/lib/FreeRTOS-Kernel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dbf70559b27d39c1fdb68dfb9a32140b6a6777a0 diff --git a/main/lib/pico-sdk b/main/lib/pico-sdk deleted file mode 160000 index 6a7db34..0000000 --- a/main/lib/pico-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6a7db34ff63345a7badec79ebea3aaef1712f374 diff --git a/main/makefile b/main/makefile index 1986cd3..9df4f09 100644 --- a/main/makefile +++ b/main/makefile @@ -1,22 +1,9 @@ -# this file is for lazy people (loek) +TARGET = $(BUILD_DIR)/main.uf2 -.PHONY: FORCE +include ../lazy.mk -all: FORCE build/main.uf2 - -build/build.ninja: CMakeLists.txt - mkdir -p build - cmake -B build -G Ninja --fresh --log-level WARNING - -build/main.uf2: build/build.ninja FORCE - ninja -C build -# ninja automatically builds in parallel, so is preferred - -flash: build/main.uf2 FORCE +flash: $(TARGET) FORCE picotool load -fx $< # -f forces a reboot of the pico before flashing # -x resets the pico after flashing -clean: FORCE - $(RM) -r build - diff --git a/proto/.gitignore b/proto/.gitignore new file mode 100644 index 0000000..75feca5 --- /dev/null +++ b/proto/.gitignore @@ -0,0 +1 @@ +*.pb.* diff --git a/proto/include.cmake b/proto/include.cmake new file mode 100644 index 0000000..d5beaef --- /dev/null +++ b/proto/include.cmake @@ -0,0 +1 @@ +include_directories(${CMAKE_CURRENT_LIST_DIR}) diff --git a/proto/makefile b/proto/makefile new file mode 100644 index 0000000..3bc4ca4 --- /dev/null +++ b/proto/makefile @@ -0,0 +1,7 @@ +PROTOCARGS += --cpp_out . + +all: puzbusv1.pb.cc puzbusv1.pb.h + +%.pb.cc %.pb.h &: %.proto + protoc $(PROTOCARGS) $< + diff --git a/proto/puzbusv1.proto b/proto/puzbusv1.proto new file mode 100644 index 0000000..6b4fa52 --- /dev/null +++ b/proto/puzbusv1.proto @@ -0,0 +1,12 @@ +syntax = "proto2"; + +package puzbus; + +message I2CMsg { + // 32-bit is the smallest integer format supported by protobuf, even though + // we only need 7-10 bits for the I2C address. + required uint32 address = 1; + + optional bytes data = 2; +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a0bd099..a280a86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,4 +20,4 @@ target_link_libraries(tests PRIVATE gtest_main) add_test( NAME tests COMMAND tests -) \ No newline at end of file +) diff --git a/test/lib b/test/lib new file mode 120000 index 0000000..dc598c5 --- /dev/null +++ b/test/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file diff --git a/test/lib/googletest b/test/lib/googletest deleted file mode 160000 index 5197b1a..0000000 --- a/test/lib/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5197b1a8e6a1ef9f214f4aa537b0be17cbf91946 -- cgit v1.2.3