-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from wjklimek1/stm32h503_nucleo
Support for STM32H503 on Nucleo board
- Loading branch information
Showing
30 changed files
with
2,463 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
cmake_minimum_required(VERSION 3.17) | ||
|
||
include(${CMAKE_CURRENT_LIST_DIR}/../family_support.cmake) | ||
|
||
project(tinyuf2 C ASM) | ||
set(CMAKE_EXECUTABLE_SUFFIX .elf) | ||
|
||
#------------------------------------ | ||
# TinyUF2 | ||
#------------------------------------ | ||
add_executable(tinyuf2 | ||
board_flash.c | ||
boards.c | ||
${TOP}/lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | ||
) | ||
target_link_options(tinyuf2 PUBLIC | ||
"LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/linker/stm32h5_boot.ld" | ||
) | ||
|
||
family_configure_tinyuf2(tinyuf2 OPT_MCU_STM32H5) | ||
family_flash_jlink(tinyuf2) | ||
family_flash_stlink(tinyuf2) | ||
|
||
#------------------------------------ | ||
# Application (e.g self update) | ||
#------------------------------------ | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/self_update) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/blinky) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# List of git submodules that is included as part of the UF2 version | ||
GIT_SUBMODULES = tinyusb | ||
|
||
include ../make.mk | ||
include port.mk | ||
include ../rules.mk | ||
|
||
#------------------------------------------ | ||
# Self-update | ||
#------------------------------------------ | ||
|
||
# directory containing Makefile for building update app | ||
SELF_DIR = apps/self_update | ||
|
||
$(SELF_DIR)/bootloader_bin.c: $(BUILD)/$(OUTNAME).bin | ||
$(PYTHON3) $(TOP)/lib/uf2/utils/uf2conv.py --carray $^ -o $@ | ||
|
||
# remove bootloader_bin.c at the end to force re-generate each time | ||
self-update: $(SELF_DIR)/bootloader_bin.c | ||
make -C $(SELF_DIR) BOARD=$(BOARD) LOG=$(LOG) LOGGER=$(LOGGER) self-update | ||
@rm -f $^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# TinyUF2 for STM32H5 | ||
|
||
TinyUF2 occupies around 16Kb + 1KB for CF2 in flash. Since H5 has uniform sector size of 8KB, ideally we would have bootloader size set to 24KB. However, due to the fact that only H503 can protect/secure individual sector, the rest of H5 family (H52x, H56x) can only secure flash in 4-sector (group) unit. Therefore application should start at | ||
- H503: `0x08006000`, boot size is 24KB | ||
- H52x, H56x, H57x: `0x08008000`, boot size is 32KB | ||
To create a UF2 image from a .bin file, either use family option `STM32H5` or its magic number as follows: | ||
|
||
From hex | ||
|
||
``` | ||
uf2conv.py -c -f 0x4e8f1c5d firmware.hex | ||
uf2conv.py -c -f STM32H5 firmware.hex | ||
``` | ||
|
||
From bin for H503 | ||
|
||
``` | ||
uf2conv.py -c -b 0x08006000 -f STM32H5 firmware.bin | ||
uf2conv.py -c -b 0x08006000 -f 0x4e8f1c5d firmware.bin | ||
``` | ||
|
||
From bin for H52x, H56x, H57x | ||
|
||
``` | ||
uf2conv.py -c -b 0x08008000 -f STM32H5 firmware.bin | ||
uf2conv.py -c -b 0x08008000 -f 0x4e8f1c5d firmware.bin | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 $@ $^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
@echo "not implemented yet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#------------------------------------ | ||
# Self Update | ||
# This file is meant to be include by add_subdirectory() in the root CMakeLists.txt | ||
#------------------------------------ | ||
|
||
# Generate bootloader_bin.c | ||
add_custom_command(OUTPUT bootloader_bin.c | ||
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o bootloader_bin.c $<TARGET_FILE_DIR:tinyuf2>/tinyuf2.bin | ||
DEPENDS tinyuf2 | ||
) | ||
|
||
# self_update target | ||
add_executable(self_update | ||
${TOP}/apps/self_update/self_update.c | ||
${CMAKE_CURRENT_LIST_DIR}/../../boards.c | ||
${CMAKE_CURRENT_LIST_DIR}/../../board_flash.c | ||
${CMAKE_CURRENT_BINARY_DIR}/bootloader_bin.c | ||
) | ||
|
||
target_include_directories(self_update PUBLIC | ||
${TOP}/src | ||
) | ||
target_compile_definitions(self_update PUBLIC | ||
TINYUF2_SELF_UPDATE | ||
BUILD_NO_TINYUSB | ||
BUILD_APPLICATION | ||
) | ||
target_link_options(self_update PUBLIC | ||
"LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/../../linker/stm32h5_app.ld" | ||
) | ||
|
||
family_configure_common(self_update) | ||
family_add_uf2(self_update ${UF2_FAMILY_ID}) | ||
family_flash_uf2(self_update ${UF2_FAMILY_ID}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
PORT = stm32h5 | ||
OUTNAME = update-tinyuf2-$(BOARD) | ||
|
||
# skip bootloader src | ||
BUILD_APPLICATION = 1 | ||
|
||
# skip tinyusb src | ||
BUILD_NO_TINYUSB = 1 | ||
|
||
CFLAGS += -DTINYUF2_SELF_UPDATE -Wno-error=stringop-overread | ||
|
||
include ../../../make.mk | ||
include ../../port.mk | ||
|
||
SRC_C += \ | ||
apps/self_update/self_update.c \ | ||
$(CURRENT_PATH)/bootloader_bin.c | ||
|
||
include ../../../rules.mk | ||
|
||
self-update: $(BUILD)/$(OUTNAME).uf2 | ||
|
||
$(BUILD)/$(OUTNAME).uf2: $(BUILD)/$(OUTNAME).hex | ||
@echo CREATE $@ | ||
$(PYTHON3) $(TOP)/lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^ |
Oops, something went wrong.