1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Bazel macros for flashing an rp2040 binary.""" 15 16load("@bazel_skylib//rules:native_binary.bzl", "native_binary") 17 18def _flash_rp2( 19 name, 20 chip, 21 binary, 22 **kwargs): 23 data = [binary] 24 args = ["--chip", chip, "$(rootpath " + binary + ")"] 25 26 native_binary( 27 name = name, 28 src = str(Label("//targets/rp2040/py:flash")), 29 args = args, 30 data = data, 31 # Note: out is mandatory in older bazel-skylib versions. 32 out = name + ".exe", 33 **kwargs 34 ) 35 36def flash_rp2040( 37 name, 38 rp2040_binary, 39 **kwargs): 40 """Flash the binary to a connected rp2040 device. 41 42 Args: 43 name: The name of this flash_rp2040 rule. 44 rp2040_binary: The binary target to flash. 45 **kwargs: Forwarded to the underlying native_binary rule. 46 """ 47 _flash_rp2(name, "RP2040", rp2040_binary, **kwargs) 48 49def flash_rp2350( 50 name, 51 rp2350_binary, 52 **kwargs): 53 """Flash the binary to a connected rp2350 device. 54 55 Args: 56 name: The name of this flash_rp2350 rule. 57 rp2350_binary: The binary target to flash. 58 **kwargs: Forwarded to the underlying native_binary rule. 59 """ 60 _flash_rp2(name, "RP2350", rp2350_binary, **kwargs) 61