Initial commit
This commit is contained in:
		
						commit
						d8f669a465
					
				
					 8 changed files with 197 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								.clangd
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.clangd
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
CompileFlags:
 | 
			
		||||
  CompilationDatabase: build
 | 
			
		||||
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
build/
 | 
			
		||||
.cache/
 | 
			
		||||
							
								
								
									
										24
									
								
								CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
cmake_minimum_required(VERSION 3.13)
 | 
			
		||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 | 
			
		||||
 | 
			
		||||
# initialize the SDK based on PICO_SDK_PATH
 | 
			
		||||
# note: this must happen before project()
 | 
			
		||||
include(pico_sdk_import.cmake)
 | 
			
		||||
 | 
			
		||||
project(police_colors)
 | 
			
		||||
 | 
			
		||||
# initialize the Raspberry Pi Pico SDK
 | 
			
		||||
pico_sdk_init()
 | 
			
		||||
 | 
			
		||||
# rest of your project
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
add_executable(police_colors
 | 
			
		||||
        police_colors.c
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
# pull in common dependencies
 | 
			
		||||
target_link_libraries(police_colors pico_stdlib)
 | 
			
		||||
 | 
			
		||||
# create map/bin/hex file etc.
 | 
			
		||||
pico_add_extra_outputs(police_colors)
 | 
			
		||||
							
								
								
									
										12
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
> [!NOTE]
 | 
			
		||||
> If we want to use clangd, we need to modify the cmake command like so:
 | 
			
		||||
> `cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_BOARD=pico ..`
 | 
			
		||||
> clangd needs the option `--query-driver=/usr/bin/arm-none-eabi-g*` to process includes properly, which cannot be set in the .clangd file due to security issues. This needs to be added to the lsp config.
 | 
			
		||||
 | 
			
		||||
> [!NOTE]
 | 
			
		||||
> Enable debug symbols with `make -j4`
 | 
			
		||||
 | 
			
		||||
> [!NOTE]
 | 
			
		||||
> Run `echo "adapter speed 10000" | nc localhost 4444` once (after starting the openocd server with `openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg`) to get faster upload speeds
 | 
			
		||||
 | 
			
		||||
`tio /dev/ttyACM#` to monitor UART
 | 
			
		||||
							
								
								
									
										6
									
								
								debug.fish
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								debug.fish
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
#!/bin/fish
 | 
			
		||||
cd build
 | 
			
		||||
#cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_BOARD=pico ..
 | 
			
		||||
make -j4
 | 
			
		||||
#echo "adapter speed 10000" | nc localhost 4444
 | 
			
		||||
echo "program build/police_colors.elf verify reset" | nc -N localhost 4444 &>/dev/null
 | 
			
		||||
							
								
								
									
										84
									
								
								pico_sdk_import.cmake
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								pico_sdk_import.cmake
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,84 @@
 | 
			
		|||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
 | 
			
		||||
 | 
			
		||||
# This can be dropped into an external project to help locate this SDK
 | 
			
		||||
# It should be include()ed prior to project()
 | 
			
		||||
 | 
			
		||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
 | 
			
		||||
    set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
 | 
			
		||||
    message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
 | 
			
		||||
    set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
 | 
			
		||||
    message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
 | 
			
		||||
    set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
 | 
			
		||||
    message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
 | 
			
		||||
    set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
 | 
			
		||||
    message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
 | 
			
		||||
  set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
 | 
			
		||||
  message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
 | 
			
		||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
 | 
			
		||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
 | 
			
		||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
 | 
			
		||||
 | 
			
		||||
if (NOT PICO_SDK_PATH)
 | 
			
		||||
    if (PICO_SDK_FETCH_FROM_GIT)
 | 
			
		||||
        include(FetchContent)
 | 
			
		||||
        set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
 | 
			
		||||
        if (PICO_SDK_FETCH_FROM_GIT_PATH)
 | 
			
		||||
            get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
 | 
			
		||||
        endif ()
 | 
			
		||||
        # GIT_SUBMODULES_RECURSE was added in 3.17
 | 
			
		||||
        if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
 | 
			
		||||
            FetchContent_Declare(
 | 
			
		||||
                    pico_sdk
 | 
			
		||||
                    GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
 | 
			
		||||
                    GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
 | 
			
		||||
                    GIT_SUBMODULES_RECURSE FALSE
 | 
			
		||||
            )
 | 
			
		||||
        else ()
 | 
			
		||||
            FetchContent_Declare(
 | 
			
		||||
                    pico_sdk
 | 
			
		||||
                    GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
 | 
			
		||||
                    GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
 | 
			
		||||
            )
 | 
			
		||||
        endif ()
 | 
			
		||||
 | 
			
		||||
        if (NOT pico_sdk)
 | 
			
		||||
            message("Downloading Raspberry Pi Pico SDK")
 | 
			
		||||
            FetchContent_Populate(pico_sdk)
 | 
			
		||||
            set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
 | 
			
		||||
        endif ()
 | 
			
		||||
        set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
 | 
			
		||||
    else ()
 | 
			
		||||
        message(FATAL_ERROR
 | 
			
		||||
                "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
 | 
			
		||||
                )
 | 
			
		||||
    endif ()
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
 | 
			
		||||
if (NOT EXISTS ${PICO_SDK_PATH})
 | 
			
		||||
    message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
 | 
			
		||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
 | 
			
		||||
    message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
 | 
			
		||||
 | 
			
		||||
include(${PICO_SDK_INIT_CMAKE_FILE})
 | 
			
		||||
							
								
								
									
										62
									
								
								police_colors.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								police_colors.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,62 @@
 | 
			
		|||
#include "pico/stdlib.h"
 | 
			
		||||
#include <pico/stdio_uart.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#define LED_DELAY_MS 80
 | 
			
		||||
#define LED_WHITE 2
 | 
			
		||||
#define LED_BLUE 3
 | 
			
		||||
#define LED_GREEN 4
 | 
			
		||||
#define LED_RED 5
 | 
			
		||||
 | 
			
		||||
int pico_led_init(void) {
 | 
			
		||||
  gpio_init(PICO_DEFAULT_LED_PIN);
 | 
			
		||||
  gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
 | 
			
		||||
  gpio_init(LED_WHITE);
 | 
			
		||||
  gpio_set_dir(LED_WHITE, GPIO_OUT);
 | 
			
		||||
  gpio_init(LED_BLUE);
 | 
			
		||||
  gpio_set_dir(LED_BLUE, GPIO_OUT);
 | 
			
		||||
  gpio_init(LED_GREEN);
 | 
			
		||||
  gpio_set_dir(LED_GREEN, GPIO_OUT);
 | 
			
		||||
  gpio_init(LED_RED);
 | 
			
		||||
  gpio_set_dir(LED_RED, GPIO_OUT);
 | 
			
		||||
  return PICO_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pico_set_led(bool led_on) {}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
  int rc = pico_led_init();
 | 
			
		||||
  hard_assert(rc == PICO_OK);
 | 
			
		||||
 | 
			
		||||
  // Set up our UART with the required speed.
 | 
			
		||||
  stdio_uart_init();
 | 
			
		||||
 | 
			
		||||
  // Normally, a call to sleep_ms would freeze the device
 | 
			
		||||
  // while connected to a debugger. We could use busy_wait_ms
 | 
			
		||||
  // as a work-around, but we'll disable this feature instead.
 | 
			
		||||
  timer_get_instance(0)->dbgpause = 0;
 | 
			
		||||
 | 
			
		||||
  gpio_put(PICO_DEFAULT_LED_PIN, true);
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < 1000000; i++) {
 | 
			
		||||
    // Send out a string, with CR/LF conversions
 | 
			
		||||
    printf("BEEP BOOP POLICE!!! %d \n\r", i);
 | 
			
		||||
    gpio_put(LED_RED, true);
 | 
			
		||||
    sleep_ms(2);
 | 
			
		||||
    gpio_put(LED_RED, false);
 | 
			
		||||
    sleep_ms(LED_DELAY_MS);
 | 
			
		||||
    gpio_put(LED_RED, true);
 | 
			
		||||
    sleep_ms(2);
 | 
			
		||||
    gpio_put(LED_RED, false);
 | 
			
		||||
    sleep_ms(LED_DELAY_MS);
 | 
			
		||||
    gpio_put(LED_BLUE, true);
 | 
			
		||||
    sleep_ms(2);
 | 
			
		||||
    gpio_put(LED_BLUE, false);
 | 
			
		||||
    sleep_ms(LED_DELAY_MS);
 | 
			
		||||
    gpio_put(LED_BLUE, true);
 | 
			
		||||
    sleep_ms(2);
 | 
			
		||||
    gpio_put(LED_BLUE, false);
 | 
			
		||||
    sleep_ms(LED_DELAY_MS);
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								test.fish
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										5
									
								
								test.fish
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
#!/bin/fish
 | 
			
		||||
cd build
 | 
			
		||||
make
 | 
			
		||||
#echo "adapter speed 10000" | nc localhost 4444
 | 
			
		||||
echo "program build/police_colors.elf verify reset" | nc -N localhost 4444 &>/dev/null
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue