Skip to content

Commit

Permalink
rp2040: Add a bazel rule for flashing
Browse files Browse the repository at this point in the history
Change-Id: I13baea1b64e3b2488dcba78fc05d9df0264b1300
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/216314
Pigweed-Auto-Submit: Aaron Green <[email protected]>
Commit-Queue: Aaron Green <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
cramertj authored and CQ Bot Account committed Jun 20, 2024
1 parent 23df123 commit d9bba58
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pw_system/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ load(
)
load("//pw_system/py:console.bzl", "device_console", "device_simulator_console")
load("//targets/host_device_simulator:transition.bzl", "host_device_simulator_binary")
load("//targets/rp2040:flash.bzl", "flash_rp2040")
load("//targets/rp2040:transition.bzl", "rp2040_binary")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -438,6 +439,12 @@ rp2040_binary(
binary = ":system_example",
)

flash_rp2040(
name = "flash_rp2040_system_example",
testonly = True,
rp2040_binary = ":rp2040_system_example",
)

# Start :simulator_system_example and connect to it with pw console.
device_simulator_console(
name = "simulator_system_example_console",
Expand Down
40 changes: 40 additions & 0 deletions targets/rp2040/flash.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Bazel macros for flashing an rp2040 binary."""

load("@bazel_skylib//rules:native_binary.bzl", "native_binary")

def flash_rp2040(
name,
rp2040_binary,
**kwargs):
"""Flash the binary to a connected rp2040 device.
Args:
name: The name of this flash_rp2040 rule.
rp2040_binary: The binary target to flash.
**kwargs: Forwarded to the underlying native_binary rule.
"""
data = [rp2040_binary]
args = ["$(rootpath " + rp2040_binary + ")"]

native_binary(
name = name,
src = "@pigweed//targets/rp2040/py:flash",
args = args,
data = data,
# Note: out is mandatory in older bazel-skylib versions.
out = name + ".exe",
**kwargs
)

0 comments on commit d9bba58

Please sign in to comment.