Added rpi-pico-sdk

This commit is contained in:
AlexanderHD27
2024-09-10 15:36:38 +02:00
parent 8b97a1853d
commit 29af5335f5
25 changed files with 3354 additions and 2 deletions

BIN
motor-control/firmware/.gitignore (Stored with Git LFS) vendored

Binary file not shown.

View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/include/**",
"${workspaceFolder}/lib/pico-sdk/lib/tinyusb/src"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-arm",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}

31
motor-control/firmware/.vscode/launch.json vendored Executable file
View File

@@ -0,0 +1,31 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Pico: Debug External OpenOCD",
"cwd": "${workspaceRoot}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"preLaunchTask": "Pico: flash freeRTOS_test",
"type": "cortex-debug",
"servertype": "external",
"gdbPath" : "gdb-multiarch",
"gdbTarget": "localhost:3333",
"device": "RP2040",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/rp2040.cfg"
],
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
"runToEntryPoint": "main",
"postRestartCommands": [
"continue"
]
}
]
}

View File

@@ -0,0 +1,78 @@
{
"cSpell.words": [
"apcsw",
"apreg",
"apsel",
"arrayname",
"baseaddr",
"Bhaskra",
"bitwidth",
"BOOTSEL",
"cget",
"channellist",
"charmsg",
"clkdiv",
"cpnum",
"deassert",
"deasserted",
"deasserting",
"doxygen",
"dpreg",
"drawio",
"dreq",
"eabi",
"eventlist",
"gpio",
"helptext",
"jtag",
"lindex",
"memaccess",
"microcontroller",
"multiarch",
"multicore",
"Pico",
"picoprobe",
"pindirs",
"pinout",
"pregen",
"resexit",
"semihosting",
"srst",
"struct",
"targetname",
"TPIU",
"trst",
"UART",
"virt",
"waitstate",
"watchpoint",
"watchpoints",
"wready"
],
"cmake.sourceDirectory": "/home/alexander/Projects/gobot/motor-control/firmware",
"cmake.buildDirectory": "${workspaceFolder}/firmware/build",
"cmake.configureOnOpen": true,
"files.associations": {
"timer.h": "c",
"stdlib.h": "c",
"stdio.h": "c",
"string.h": "c",
"assert.h": "c",
"gen.h": "c",
"multicore.h": "c",
"pio.h": "c",
"freertos.h": "c",
"random": "c",
"queue.h": "c",
"string_view": "c",
"instructionformat.h": "c",
"includeglobals.h": "c",
"dacconfig.h": "c",
"freertosconfig.h": "c"
},
"cortex-debug.variableUseNaturalFormat": false,
"todo-tree.filtering.ignoreGitSubmodules": true,
"todo-tree.tree.showBadges": true,
"terminal.integrated.scrollback": 10000,
"C_Cpp.refactoring.includeHeader": "always",
}

View File

@@ -0,0 +1,171 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build main",
"command": "build",
"targets": [
"main"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"type": "shell",
"label": "Pico: flash main",
"command": [
"scripts/flash.exp",
"${workspaceRoot}/build/bin/main.elf"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "test",
"dependsOn": ["CMake: build main"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"type": "cmake",
"label": "CMake: build usb_test",
"command": "build",
"targets": [
"usb_test"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"type": "shell",
"label": "Pico: flash usb_test",
"command": [
"scripts/flash.exp",
"${workspaceRoot}/build/bin/usb_test.elf"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "test",
"dependsOn": ["CMake: build usb_test"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"type": "cmake",
"label": "CMake: build freeRTOS_test",
"command": "build",
"targets": [
"freeRTOS_test"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"type": "shell",
"label": "Pico: flash freeRTOS_test",
"command": [
"scripts/flash.exp",
"${workspaceRoot}/build/bin/freeRTOS_test.elf"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "test",
"dependsOn": ["CMake: build freeRTOS_test"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"type": "shell",
"label": "Pico: launch openocd",
"command": [
"scripts/launch_openocd.sh"
],
"options": {
"cwd": "${workspaceRoot}"
},
"isBackground": true
},
{
"type": "cmake",
"label": "CMake: Clean",
"command": "clean"
},
{
"type": "cmake",
"label": "CMake: Clean Rebuild",
"command": "cleanRebuild"
},
{
"type": "cmake",
"label": "CMake: Configure",
"command": "configure"
},
{
"type": "shell",
"label": "Doxygen: Generate Docs",
"command": [
"doxygen ./docs/Doxyfile",
],
"options": {
"cwd": "${workspaceRoot}"
}
}
]
}

View File

@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.12)
# Including the SDK (must be before project)
if (NOT "$ENV{PICO_SDK_PATH_OVERRIDE}" STREQUAL "")
SET(PICO_SDK_PATH "$ENV{PICO_SDK_PATH_OVERRIDE}")
else()
SET(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/lib/pico-sdk")
endif()
SET(PICO_TOOLCHAIN_PATH $PICO_SDK_PATH/cmake/preload/toolchains/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>")
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
#include(pico_extras_import_optional.cmake)
project(pico_examples C CXX ASM)
set(CMAKE_C_STANDARD 23)
set(CMAKE_CXX_STANDARD 23)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})
# Initialize the SDK
pico_sdk_init()
include(example_auto_set_url.cmake)
add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-maybe-uninitialized)
endif()
# adding sources files & includes
add_executable(main
src/main.cpp
)
target_include_directories(main PUBLIC
include/
)
# Add FreeRTOS
include(freeRTOS.cmake)
target_include_directories(FreeRTOS PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Adding PIO
#pico_generate_pio_header(main ${CMAKE_CURRENT_LIST_DIR}/src/dac/dac.pio)
# pull in common dependencies
target_link_libraries(main
pico_stdlib
pico_multicore
hardware_pio
hardware_dma
hardware_timer
FreeRTOS
EEPROMDriver
)
# create map/bin/hex file etc.
pico_add_extra_outputs(main)
# add url via pico_set_program_url
example_auto_set_url(main)

View File

@@ -0,0 +1,100 @@
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ 133000000
#define configSYSTICK_CLOCK_HZ 1000000
#define configTICK_RATE_HZ 1000
#define configMAX_PRIORITIES 4
#define configMINIMAL_STACK_SIZE 256
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
#define configUSE_MUTEXES 0
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 1
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define configSTACK_DEPTH_TYPE uint16_t
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 50000
#define configAPPLICATION_ALLOCATED_HEAP 0
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1
/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
/* Interrupt nesting behaviour configuration. */
#define configKERNEL_INTERRUPT_PRIORITY [dependent of processor]
#define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application]
#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application]
/* Define to trap errors during development. */
//#define configASSERT( ( x ) ) assert()
/* FreeRTOS MPU specific definitions. */
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0
#define configTOTAL_MPU_REGIONS 8 /* Default value. */
#define configTEX_S_C_B_FLASH 0x07UL /* Default value. */
#define configTEX_S_C_B_SRAM 0x07UL /* Default value. */
#define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY 1
/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 0
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 1
#define vPortSVCHandler isr_svcall
#define xPortPendSVHandler isr_pendsv
#define xPortSysTickHandler isr_systick
/* A header file that defines trace macro can be included here. */
#endif /* FREERTOS_CONFIG_H */

106
motor-control/firmware/Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,106 @@
pipeline {
agent none
stages {
stage('git checkout') {
agent {
label 'docker'
}
steps {
git branch: 'firmware-dev',
credentialsId: 'osci-rendering_github',
url: 'git@github.com:AlexanderHD27/oscilloscope-drawing.git'
sh 'git submodule update --init --recursive'
sh "ls -laF"
stash includes: "firmware/lib/doxygen-awesome-css/**", name: 'libs-doxygen'
}
}
stage('build build-container') {
agent {
label 'docker'
}
steps {
sh 'docker build -t rpi_pico_build_container firmware/docker/'
}
}
stage('build') {
parallel {
stage('build firmware') {
agent {
docker {
image 'rpi_pico_build_container'
label 'docker'
reuseNode true
}
}
steps {
script {
env.PICO_SDK_PATH_OVERRIDE = sh(script: 'echo $PWD/firmware/lib/pico-sdk', returnStdout: true).trim()
}
dir('firmware/build') {
sh 'echo building in $PWD'
sh 'rm -rf *'
sh 'echo PicoSDK path: $PICO_SDK_PATH_OVERRIDE'
sh 'cmake ..'
sh 'cmake --build . --config Debug'
sh 'make -j4 all'
}
stash includes: "firmware/build/bin/*", name: 'binary'
}
}
stage('build docs') {
agent {
docker {
image 'rpi_pico_build_container'
label 'docker'
reuseNode true
}
}
steps {
unstash 'libs-doxygen'
sh "doxygen firmware/docs/Doxyfile"
stash includes: "firmware/docs/html/*", name: 'html-docs'
}
}
}
}
stage('publish') {
parallel {
stage('publish docs') {
agent {
label 'cdc-deploy'
}
steps {
sh 'rm -rf /www/projects/osci-rendering/docs/*'
unstash 'html-docs'
sh 'cp -r firmware/docs/html/* /www/projects/osci-rendering/docs'
}
}
stage('publish binary') {
agent {
label 'cdc-deploy'
}
steps {
sh 'rm -rf /www/projects/osci-rendering/bin/*'
unstash 'binary'
sh 'cp -r bin/* /www/projects/osci-rendering/bin'
}
}
}
}
}
}

BIN
motor-control/firmware/README.md (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,8 @@
FROM ubuntu:22.04
RUN apt -y update
RUN apt -y install build-essential gcc-arm-none-eabi doxygen cmake python3
RUN mkdir /data
WORKDIR /data

View File

@@ -0,0 +1,3 @@
#!/usr/bin/bash
doxygen ./firmware/docs/Doxyfile

View File

@@ -0,0 +1,11 @@
#!/usr/bin/bash
cd ./firmware/build
rm -rf *
export PICO_SDK_PATH_OVERRIDE="/data/firmware/lib/pico-sdk"
echo $PICO_SDK_PATH_OVERRIDE
cmake ..
cmake --build . --config Debug
make -j4 all

File diff suppressed because it is too large Load Diff

BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,5 @@
set(PICO_EXAMPLE_URL_BASE "https://github.com/raspberrypi/pico-examples/tree/HEAD")
macro(example_auto_set_url TARGET)
file(RELATIVE_PATH URL_REL_PATH "${PICO_EXAMPLES_PATH}" "${CMAKE_CURRENT_LIST_DIR}")
pico_set_program_url(${TARGET} "${PICO_EXAMPLE_URL_BASE}/${URL_REL_PATH}")
endmacro()

View File

@@ -0,0 +1,13 @@
SET(FreeRTOS_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/FreeRTOS-Kernel)
FILE(GLOB FreeRTOS_src ${FreeRTOS_DIR}/*.c)
add_library(FreeRTOS STATIC
${FreeRTOS_src}
${FreeRTOS_DIR}/portable/GCC/ARM_CM0/port.c
${FreeRTOS_DIR}/portable/MemMang/heap_4.c
)
target_include_directories(FreeRTOS PUBLIC
${FreeRTOS_DIR}/portable/GCC/ARM_CM0/
${FreeRTOS_DIR}/include/
)

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
cd build
make -j10

View File

@@ -0,0 +1,8 @@
#!/usr/bin/bash
if ! scripts/build.sh; then
exit
else
scripts/flash.exp main.elf
fi

View File

@@ -0,0 +1,21 @@
#!/usr/bin/expect
set timeout 30
set input_file [lindex $argv 0]
spawn telnet localhost 4444
expect "> "
send "program $input_file verify\n"
expect "** Programming Finished **"
send "reset halt\n"
expect "> "
send "rp2040.core1 arp_reset assert 0\n"
expect "> "
send "rp2040.core0 arp_reset assert 0\n"
expect "> "
send "exit\n"
exit

View File

@@ -0,0 +1,3 @@
#!/usr/bin/bash
openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -c "program $1 verify reset exit"

View File

@@ -0,0 +1,4 @@
#!/usr/bin/bash
sudo openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg

View File

@@ -0,0 +1,2 @@
#!/usr/bin/bash
minicom -D $1

View File

@@ -0,0 +1,13 @@
#!/usr/bin/expect
set timeout 30
set input_file [lindex $argv 0]
spawn telnet localhost 4444
expect "> "
send "reset\n"
expect "> "
send "exit\n"
exit

View File

@@ -0,0 +1,14 @@
/**
* @file main.c
* @author AlexanderHD27
* @brief Main file of the RPi Pico Firmware for the Oscilloscope-Renderer
* @version 0.1
* @date 2024-02-15
*
* @copyright Copyright (c) 2024
*
*/
int main() {
}