|
| 1 | +# Copyright (C) 2024 by Skyward |
| 2 | +# |
| 3 | +# This program is free software; you can redistribute it and/or |
| 4 | +# it under the terms of the GNU General Public License as published |
| 5 | +# the Free Software Foundation; either version 2 of the License, or |
| 6 | +# (at your option) any later version. |
| 7 | +# |
| 8 | +# This program is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +# GNU General Public License for more details. |
| 12 | +# |
| 13 | +# As a special exception, if other files instantiate templates or use |
| 14 | +# macros or inline functions from this file, or you compile this file |
| 15 | +# and link it with other works to produce a work based on this file, |
| 16 | +# this file does not by itself cause the resulting work to be covered |
| 17 | +# by the GNU General Public License. However the source code for this |
| 18 | +# file must still be made available in accordance with the GNU |
| 19 | +# Public License. This exception does not invalidate any other |
| 20 | +# why a work based on this file might be covered by the GNU General |
| 21 | +# Public License. |
| 22 | +# |
| 23 | +# You should have received a copy of the GNU General Public License |
| 24 | +# along with this program; if not, see <http://www.gnu.org/licenses/> |
| 25 | + |
| 26 | +# Creates a custom target to program the board |
| 27 | +# |
| 28 | +# miosix_add_program_target(<target> [DEPENDS <target1> <target2> ...]) |
| 29 | +# |
| 30 | +function(miosix_add_program_target TARGET) |
| 31 | + cmake_parse_arguments(PROGRAM "" "" "DEPENDS" ${ARGN}) |
| 32 | + |
| 33 | + if(NOT PROGRAM_DEPENDS) |
| 34 | + set(PROGRAM_DEPENDS ${TARGET}_bin ${TARGET}_hex) |
| 35 | + endif() |
| 36 | + |
| 37 | + get_target_property(PROGRAM_CMDLINE miosix PROGRAM_CMDLINE) |
| 38 | + if(PROGRAM_CMDLINE STREQUAL "PROGRAM_CMDLINE-NOTFOUND") |
| 39 | + set(PROGRAM_CMDLINE st-flash --connect-under-reset --reset write <binary> 0x8000000) |
| 40 | + endif() |
| 41 | + |
| 42 | + list(TRANSFORM PROGRAM_CMDLINE REPLACE <binary> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin) |
| 43 | + list(TRANSFORM PROGRAM_CMDLINE REPLACE <hex> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.hex) |
| 44 | + |
| 45 | + add_custom_target(${TARGET}_program ${PROGRAM_CMDLINE} |
| 46 | + DEPENDS ${PROGRAM_DEPENDS} |
| 47 | + VERBATIM |
| 48 | + ) |
| 49 | +endfunction() |
0 commit comments