working flake and blink example.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
84af3f0ab1
commit
9db9d5f192
8 changed files with 181 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -150,3 +150,7 @@ dkms.conf
|
|||
*.out
|
||||
*.app
|
||||
|
||||
# direnv cache
|
||||
.direnv
|
||||
# build directory
|
||||
build
|
||||
|
|
|
|||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "pico-sdk"]
|
||||
path = pico-sdk
|
||||
url = https://github.com/raspberrypi/pico-sdk
|
||||
22
CMakeLists.txt
Normal file
22
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
cmake_minimum_required(VERSION 3.13...3.27)
|
||||
|
||||
# initialize pico-sdk from submodule
|
||||
# note: this must happen before project()
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(my_project)
|
||||
|
||||
# initialize the Raspberry Pi Pico SDK
|
||||
set(PICO_BOARD, "pico")
|
||||
pico_sdk_init()
|
||||
|
||||
# rest of your project
|
||||
add_executable(hello_world
|
||||
hello_world.c
|
||||
)
|
||||
|
||||
# Add pico_stdlib library which aggregates commonly used features
|
||||
target_link_libraries(hello_world pico_stdlib)
|
||||
|
||||
# create map/bin/hex/uf2 file in addition to ELF.
|
||||
pico_add_extra_outputs(hello_world)
|
||||
64
flake.lock
generated
Normal file
64
flake.lock
generated
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": [
|
||||
"systems"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1737255904,
|
||||
"narHash": "sha256-r3fxHvh+M/mBgCZXOACzRFPsJdix2QSsKazb7VCXXo0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "eacdab35066b0bb1c9413c96898e326b76398a81",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-24.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
33
flake.nix
Normal file
33
flake.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
description = "flake for rp2040 dev";
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/release-24.11";
|
||||
systems.url = "github:nix-systems/default";
|
||||
flake-utils = {
|
||||
url = "github:numtide/flake-utils";
|
||||
inputs.systems.follows = "systems";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ nixpkgs, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
gcc
|
||||
cmake
|
||||
gnumake
|
||||
python312Full
|
||||
gcc-arm-embedded
|
||||
newlib
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
53
hello_world.c
Normal file
53
hello_world.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
// Pico W devices use a GPIO on the WIFI chip for the LED,
|
||||
// so when building for Pico W, CYW43_WL_GPIO_LED_PIN will be defined
|
||||
#ifdef CYW43_WL_GPIO_LED_PIN
|
||||
#include "pico/cyw43_arch.h"
|
||||
#endif
|
||||
|
||||
#ifndef LED_DELAY_MS
|
||||
#define LED_DELAY_MS 250
|
||||
#endif
|
||||
|
||||
// Perform initialisation
|
||||
int pico_led_init(void) {
|
||||
#if defined(PICO_DEFAULT_LED_PIN)
|
||||
// A device like Pico that uses a GPIO for the LED will define PICO_DEFAULT_LED_PIN
|
||||
// so we can use normal GPIO functionality to turn the led on and off
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
return PICO_OK;
|
||||
#elif defined(CYW43_WL_GPIO_LED_PIN)
|
||||
// For Pico W devices we need to initialise the driver etc
|
||||
return cyw43_arch_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Turn the led on or off
|
||||
void pico_set_led(bool led_on) {
|
||||
#if defined(PICO_DEFAULT_LED_PIN)
|
||||
// Just set the GPIO on or off
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, led_on);
|
||||
#elif defined(CYW43_WL_GPIO_LED_PIN)
|
||||
// Ask the wifi "driver" to set the GPIO on or off
|
||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_on);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main() {
|
||||
int rc = pico_led_init();
|
||||
hard_assert(rc == PICO_OK);
|
||||
while (true) {
|
||||
pico_set_led(true);
|
||||
sleep_ms(LED_DELAY_MS);
|
||||
pico_set_led(false);
|
||||
sleep_ms(LED_DELAY_MS);
|
||||
}
|
||||
}
|
||||
1
pico-sdk
Submodule
1
pico-sdk
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 95ea6acad131124694cda1c162c52cd30e0aece0
|
||||
Loading…
Add table
Add a link
Reference in a new issue