add blinky app to make it easier to test bootloader function
This commit is contained in:
parent
cd6493c8e0
commit
ab495e5a84
6 changed files with 153 additions and 2 deletions
90
apps/blinky/blinky.c
Normal file
90
apps/blinky/blinky.c
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "board_api.h"
|
||||||
|
|
||||||
|
// Blinky app to test tinyuf2 bootloader
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
uint8_t const RGB_WRITING[] = { 0xcc, 0x66, 0x00 };
|
||||||
|
uint8_t const RGB_OFF[] = { 0x00, 0x00, 0x00 };
|
||||||
|
static volatile uint32_t _timer_count = 0;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
TUF2_LOG1_LOCATION();
|
||||||
|
board_init();
|
||||||
|
TUF2_LOG1_LOCATION();
|
||||||
|
board_timer_start(1);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void board_timer_handler(void)
|
||||||
|
{
|
||||||
|
_timer_count++;
|
||||||
|
|
||||||
|
if ((_timer_count & 0xfful) == 0) {
|
||||||
|
// Fast toggle with both LED and RGB
|
||||||
|
static bool is_on = false;
|
||||||
|
is_on = !is_on;
|
||||||
|
|
||||||
|
// fast blink LED if available
|
||||||
|
board_led_write(is_on ? 0xff : 0x000);
|
||||||
|
|
||||||
|
// blink RGB if available
|
||||||
|
board_rgb_write(is_on ? RGB_WRITING : RGB_OFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Logger newlib retarget
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
// Enable only with LOG is enabled (Note: ESP32-S2 has built-in support already)
|
||||||
|
#if TUF2_LOG // && (CFG_TUSB_MCU != OPT_MCU_ESP32S2)
|
||||||
|
|
||||||
|
#if defined(LOGGER_RTT)
|
||||||
|
#include "SEGGER_RTT.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__attribute__ ((used)) int _write (int fhdl, const void *buf, size_t count)
|
||||||
|
{
|
||||||
|
(void) fhdl;
|
||||||
|
|
||||||
|
#if defined(LOGGER_RTT)
|
||||||
|
SEGGER_RTT_Write(0, (char*) buf, (int) count);
|
||||||
|
return count;
|
||||||
|
#else
|
||||||
|
return board_uart_write(buf, count);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -234,6 +234,7 @@ function(family_add_uf2 TARGET FAMILY_ID)
|
||||||
set(BIN_FILE $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.${BIN_EXT})
|
set(BIN_FILE $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.${BIN_EXT})
|
||||||
|
|
||||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||||
|
COMMAND echo ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} ${ADDR_OPT} -c -o $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.uf2 ${BIN_FILE}
|
||||||
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} ${ADDR_OPT} -c -o $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.uf2 ${BIN_FILE}
|
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} ${ADDR_OPT} -c -o $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.uf2 ${BIN_FILE}
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
@ -264,6 +265,7 @@ function(family_flash_jlink TARGET)
|
||||||
set(BIN_FILE $<TARGET_FILE:${TARGET}>)
|
set(BIN_FILE $<TARGET_FILE:${TARGET}>)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# flash with jlink
|
||||||
file(GENERATE
|
file(GENERATE
|
||||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
|
||||||
CONTENT "halt
|
CONTENT "halt
|
||||||
|
|
@ -277,6 +279,17 @@ exit"
|
||||||
DEPENDS ${TARGET}
|
DEPENDS ${TARGET}
|
||||||
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if ${JLINK_IF} -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
|
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if ${JLINK_IF} -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# erase with jlink
|
||||||
|
file(GENERATE
|
||||||
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-erase.jlink
|
||||||
|
CONTENT "halt
|
||||||
|
erase
|
||||||
|
exit
|
||||||
|
")
|
||||||
|
add_custom_target(${TARGET}-erase-jlink
|
||||||
|
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if ${JLINK_IF} -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-erase.jlink
|
||||||
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,3 +207,8 @@ OPENOCD_WCH ?= /home/${USER}/app/riscv-openocd-wch/src/openocd
|
||||||
OPENOCD_WCH_OPTION ?=
|
OPENOCD_WCH_OPTION ?=
|
||||||
flash-openocd-wch: $(BUILD)/$(OUTNAME).elf
|
flash-openocd-wch: $(BUILD)/$(OUTNAME).elf
|
||||||
$(OPENOCD_WCH) $(OPENOCD_WCH_OPTION) -c init -c halt -c "flash write_image $<" -c reset -c exit
|
$(OPENOCD_WCH) $(OPENOCD_WCH_OPTION) -c init -c halt -c "flash write_image $<" -c reset -c exit
|
||||||
|
|
||||||
|
#-------------------- Flash with uf2 -----------------
|
||||||
|
UF2CONV_PY = $(TOP)/lib/uf2/utils/uf2conv.py
|
||||||
|
flash-uf2: $(BUILD)/$(OUTNAME).uf2
|
||||||
|
python ${UF2CONV_PY} -f ${UF2_FAMILY_ID} --deploy $^
|
||||||
|
|
|
||||||
24
ports/stm32h5/apps/blinky/CMakeLists.txt
Normal file
24
ports/stm32h5/apps/blinky/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#------------------------------------
|
||||||
|
# This file is meant to be include by add_subdirectory() in the root CMakeLists.txt
|
||||||
|
#------------------------------------
|
||||||
|
|
||||||
|
# self_update target
|
||||||
|
add_executable(blinky
|
||||||
|
${TOP}/apps/blinky/blinky.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../boards.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../board_flash.c
|
||||||
|
)
|
||||||
|
target_include_directories(blinky PUBLIC
|
||||||
|
${TOP}/src
|
||||||
|
)
|
||||||
|
target_compile_definitions(blinky PUBLIC
|
||||||
|
BUILD_NO_TINYUSB
|
||||||
|
BUILD_APPLICATION
|
||||||
|
)
|
||||||
|
target_link_options(blinky PUBLIC
|
||||||
|
"LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/../../linker/stm32h5_app.ld"
|
||||||
|
)
|
||||||
|
|
||||||
|
family_configure_common(blinky)
|
||||||
|
family_add_uf2(blinky ${UF2_FAMILY_ID})
|
||||||
|
family_flash_uf2(blinky ${UF2_FAMILY_ID})
|
||||||
19
ports/stm32h5/apps/blinky/Makefile
Normal file
19
ports/stm32h5/apps/blinky/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
PORT = stm32h5
|
||||||
|
OUTNAME = blinky-$(BOARD)
|
||||||
|
|
||||||
|
BUILD_APPLICATION = 1
|
||||||
|
BUILD_NO_TINYUSB = 1
|
||||||
|
|
||||||
|
include ../../../make.mk
|
||||||
|
include ../../port.mk
|
||||||
|
|
||||||
|
SRC_C += \
|
||||||
|
apps/blinky/blinky.c \
|
||||||
|
|
||||||
|
include ../../../rules.mk
|
||||||
|
|
||||||
|
uf2: $(BUILD)/$(OUTNAME).uf2
|
||||||
|
|
||||||
|
$(BUILD)/$(OUTNAME).uf2: $(BUILD)/$(OUTNAME).hex
|
||||||
|
@echo CREATE $@
|
||||||
|
$(PYTHON3) $(TOP)/lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^
|
||||||
|
|
@ -62,11 +62,11 @@ int main(void) {
|
||||||
|
|
||||||
// if not DFU mode, jump to App
|
// if not DFU mode, jump to App
|
||||||
if (!check_dfu_mode()) {
|
if (!check_dfu_mode()) {
|
||||||
TU_LOG1("Jump to application\r\n");
|
TUF2_LOG1("Jump to application\r\n");
|
||||||
if (board_teardown) board_teardown();
|
if (board_teardown) board_teardown();
|
||||||
if (board_teardown2) board_teardown2();
|
if (board_teardown2) board_teardown2();
|
||||||
board_app_jump();
|
board_app_jump();
|
||||||
TU_LOG1("Failed to jump\r\n");
|
TUF2_LOG1("Failed to jump\r\n");
|
||||||
while (1) {}
|
while (1) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue