Skip to content

Commit

Permalink
Add UDB flavour of the stm32h743xx HIC
Browse files Browse the repository at this point in the history
UDB enriches the DAPLink experience with additional features such as:
- A new USB CDC endpoint to flash and get logs from a second target.
- Another new USB CDC endpoint to interact with the HIC. Users can send easy shell commands to toggle pins, or to get any info from the HIC.
- Additional DAPLink debugging functionality: persistent fault info, breakpoints on asserts when debugger is connected to debug UDB, watchdog, backtraces
- Target power measurement

For more details see the source/hic_hal/stm32/stm32h743ii/extended_features folder.

Co-authored-by: Yangte Chen <yangtechen@google.com>
Co-authored-by: Eric Lee <eleenest@google.com>
  • Loading branch information
3 people committed Jun 30, 2022
1 parent ce911f8 commit 3c6ff9c
Show file tree
Hide file tree
Showing 101 changed files with 52,784 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/hic/stm32h743xx.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ Bootloader size is 128 KB
| HID LED | O | PG2 | 98 |
| CDC LED | O | PG3 | 99 |
| MSC LED | O | PG4 | 100 |

## UDB (Universal Debug Board) Additions
UDB is a special flavor of the stm32h743xx HIC, which enriches the DAPLink experience with additional features such as:
- A new USB CDC endpoint to flash and get logs from a second target.
- Another new USB CDC endpoint to interact with the HIC. Users can send easy shell commands to toggle pins, or to get any info from the HIC.
- Additional DAPLink debugging functionality: persistent fault info, breakpoints on asserts when debugger is connected to debug UDB, watchdog, backtraces
- Target power measurement
9 changes: 9 additions & 0 deletions projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ projects:
- records/family/all_family.yaml
- records/usb/usb-bulk.yaml
- records/daplink/usb-cdc-single-uart.yaml
stm32h743ii_udb_bl:
- *stm32h743ii_bl
- records/board/stm32h743ii_udb_bl.yaml
stm32h743ii_udb_if:
- *module_if
- *module_hic_stm32h743ii
- records/family/all_family.yaml
- records/usb/usb-bulk.yaml
- records/board/stm32h743ii_udb_if.yaml #extends DAPLink with additional features for the UDB project

# Other projects
k20dx_ep_agora_if:
Expand Down
10 changes: 10 additions & 0 deletions records/board/stm32h743ii_udb_bl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
common:
includes:
- source/hic_hal/stm32/stm32h743ii/extended_features/include/udb_version.h
sources:
hic_hal:
- source/hic_hal/stm32/stm32h743ii/extended_features/source/udb_version.c
tool_specific:
gcc_arm:
linker_file:
- source/hic_hal/stm32/stm32h743ii/extended_features/include/udb.ld
30 changes: 30 additions & 0 deletions records/board/stm32h743ii_udb_if.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
common:
macros:
# Add DAPLink macros below
- MAIN_TASK_STACK=2048
- DAPLINK_BOOTLOADER_UPDATE
- ASSERT_BUF_SIZE=65
- USB_CDC_ACM_EP_COUNT=3
# Add UDB config macros below
- UDB
- SUPPORT_CMD_HISTORY
- NLUIF_PRINT_RESULT
# Add build feature macros below
- BUILD_FEATURE_UDB_ASSERT
includes:
- projectfiles/make_gcc_arm/stm32h743ii_udb_bl/build/bootloader_image.c
- source/hic_hal/stm32/stm32h743ii/extended_features/include
- source/hic_hal/stm32/stm32h743ii/extended_features/lib/nlutilities/include
- source/hic_hal/stm32/stm32h743ii/extended_features/console/include
- source/hic_hal/stm32/stm32h743ii/extended_features/lib/nlbacktrace/include
sources:
board:
- source/board/stm32h743ii.c
family:
- source/family/st/stm32h743ii/target.c
hic_hal:
- source/hic_hal/stm32/stm32h743ii/extended_features/source
- source/hic_hal/stm32/stm32h743ii/extended_features/lib/nlutilities/source
- source/hic_hal/stm32/stm32h743ii/extended_features/console/source
- source/hic_hal/stm32/stm32h743ii/extended_features/lib/nlbacktrace/source
- source/hic_hal/stm32/stm32h743ii/extended_features/usb
121 changes: 121 additions & 0 deletions source/board/stm32h743ii.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,127 @@
#include "target_board.h"
#include <stdio.h>

#ifdef UDB
#include "i2c.h"
#include "udb_version.h"
#include "udb_extended_features_task.h"
#include "udb_power_measurement.h"
#include "udb_log.h"
#include "udb_version.h"
#include "nluif_udb-daplink.h"
#include "util.h"
#include "udb_fault_info.h"
#include "udb_watchdog.h"
#include "udb_fault_info.h"
#include "udb_uptime.h"

#define UDB_WATCHDOG_TIMEOUT_S (10U)

#define UDB_30MS_MULTIPLIER_TO_30SEC (1000)
#define UDB_30MS_MULTIPLIER_TO_10MIN (1000 * 20)

#define UDB_LED_30MS_MULTIPLER_NORMAL (50ULL)
#define UDB_LED_30MS_MULTIPLER_UNCLEARED_FAULT_INFO (5ULL)

#ifdef UDB_DEBUG
#define UDB_CHECK_FAULT_INFO_TARGET_COUNT UDB_30MS_MULTIPLIER_TO_30SEC
#else
#define UDB_CHECK_FAULT_INFO_TARGET_COUNT UDB_30MS_MULTIPLIER_TO_10MIN
#endif

static uint64_t s_30ms_hook_counter = 0;
static uint64_t s_connected_led_blink_period = UDB_LED_30MS_MULTIPLER_NORMAL;

extern void udb_config_init(void);

static void udb_welcome_message(void)
{
char ver_buf[UDB_VERSION_MAX_LENGTH];

printf("Welcome to\n");
printf("\t ______ ______ \n");
printf("\t|\\ /|( __ \\ ( ___ \\ \n");
printf("\t| ) ( || ( \\ )| ( ) ) \n");
printf("\t| | | || | ) || (__/ / \n");
printf("\t| | | || | | || __ ( \n");
printf("\t| | | || | ) || ( \\ \\ \n");
printf("\t| (___) || (__/ )| )___) ) \n");
printf("\t(_______)(______/ |/ \\___/ \n\n");

udb_get_interface_version((uint8_t*)ver_buf, UDB_VERSION_MAX_LENGTH);
printf("Interface version: %s\n", ver_buf);
udb_get_bootloader_version((uint8_t*)ver_buf, UDB_VERSION_MAX_LENGTH);
printf("Bootloader version: %s\n", ver_buf);

printf("To know more about udb, visit go/udb.\n");
printf("Please report issues at go/udb-bug.\n");
printf("You can start typing commands.\n");

uif_prompt();
}

static void prerun_board_config(void)
{
int status;

udb_uptime_init();

status = i2c_init();
util_assert(status == UDB_SUCCESS);

udb_read_hw_version();
udb_config_init();

udb_extended_features_task_create();

status = udb_power_measurement_init();
util_assert(status == UDB_SUCCESS);

udb_check_unexpected_watchdog_reset();
}

void board_30ms_hook()
{
udb_uptime_update();
if (udb_is_fault_info_uncleared())
{
s_connected_led_blink_period = UDB_LED_30MS_MULTIPLER_UNCLEARED_FAULT_INFO;
}
else
{
s_connected_led_blink_period = UDB_LED_30MS_MULTIPLER_NORMAL;
}

if (s_30ms_hook_counter == 0)
{
// Code that needs to run once after the bootloader update and all other
// initialization finished

udb_watchdog_init(UDB_WATCHDOG_TIMEOUT_S);
udb_welcome_message();
}

udb_watchdog_refresh();

if ((s_30ms_hook_counter % s_connected_led_blink_period) == 0)
{
HAL_GPIO_TogglePin( CONNECTED_LED_PORT, CONNECTED_LED_PIN);
}

if (((s_30ms_hook_counter % UDB_CHECK_FAULT_INFO_TARGET_COUNT) == 0) && udb_is_fault_info_uncleared())
{
udb_print_fault_info();
}

if (udb_log_cdc_ready())
{
udb_log_flush();
}

s_30ms_hook_counter++;
}
#endif // UDB

// return non-zero value to make all image incompatible
uint8_t board_detect_incompatible_image(const uint8_t *data, uint32_t size)
{
Expand Down
Loading

0 comments on commit 3c6ff9c

Please sign in to comment.