Skip to content

Commit

Permalink
* Debug options for STM32CubeIDE and debug features/options for SWD/S…
Browse files Browse the repository at this point in the history
…WO (when using HYDRAFW_DEBUG=1)

Tested with success using  STM32CubeIDE 1.4.2 with HydraBus v1 + STLINK-V3SET
  • Loading branch information
bvernoux committed Aug 28, 2020
1 parent 229a947 commit 0099a03
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ endif

# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -Os -fomit-frame-pointer -falign-functions=16 -std=gnu89 --specs=nosys.specs
USE_OPT = -fomit-frame-pointer -falign-functions=16 -std=gnu89 --specs=nosys.specs
endif

ifeq ($(HYDRAFW_DEBUG),1)
HYDRAFW_OPTS += -DMAKE_DEBUG
# Host Debug is either async trace via SWO or Semihosting
# Leave disabled if using neither.
HYDRAFW_OPTS += -DUSE_HOST_DEBUG
USE_OPT += -ggdb
USE_OPT += -fstack-usage
USE_OPT += -Og
USE_OPT += -Wshadow
USE_OPT += -Wformat=2
USE_LTO = no
else
USE_OPT += -Os
endif

# C specific options here (added to USE_OPT).
Expand Down
28 changes: 24 additions & 4 deletions src/drv/stm32cube/bsp_print_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@
#include <stdio.h> /* vsnprintf */
#include <stdarg.h> /* va_list / va_start / va_end */

#ifdef MAKE_DEBUG
// undef USE_SWO to use semihosting as debug output
#define USE_SWO TRUE
#endif

/** \brief print debug through Semi Hosting(SWD debug) & SWV
*
* \param data const char*
* \param size const uint32_t
* \return void
*
*/
#ifdef MAKE_DEBUG
void print_dbg(const char *data, const uint32_t size)
{
#ifdef USE_HOST_DEBUG
#ifndef USE_SWO
static uint32_t args[3];

args[0] = 1;
Expand All @@ -40,15 +48,20 @@ void print_dbg(const char *data, const uint32_t size)
"mov r1, %0\n"
"bkpt 0x00AB" : : "r"(args) : "r0", "r1");

#if 0
#else
{
int i;
uint32_t i;
/* SWV Debug requires PB3 configured as SWO & connected to SWD last pin */
for(i = 0; i<size; i++)
ITM_SendChar(data[i]); /* core_cm4.h */
}
#endif
#else
(void)data;
(void)size;
#endif
}
#endif

/** \brief printf debug through Semi Hosting(SWD debug)
*
Expand All @@ -57,16 +70,19 @@ void print_dbg(const char *data, const uint32_t size)
* \return void
*
*/
#ifdef MAKE_DEBUG
void printf_dbg(const char *fmt, ...)
{
#ifdef USE_HOST_DEBUG
int real_size;
va_list va_args;
#define PRINTF_DBG_BUFFER_SIZE (80)
static char printf_dbg_string[PRINTF_DBG_BUFFER_SIZE+1];
static uint32_t args[3];

va_start(va_args, fmt);
real_size = vsnprintf(printf_dbg_string, PRINTF_DBG_BUFFER_SIZE, fmt, va_args);
#ifndef USE_SWO
static uint32_t args[3];
/* Semihosting SWI print through SWD/JTAG debugger */
args[0] = 1;
args[1] = (uint32_t)printf_dbg_string;
Expand All @@ -75,7 +91,7 @@ void printf_dbg(const char *fmt, ...)
"mov r1, %0\n"
"bkpt 0x00AB" : : "r"(args) : "r0", "r1");

#if 0
#else
{
int i;
/* SWV Debug requires PB3 configured as SWO & connected to SWD last pin */
Expand All @@ -84,4 +100,8 @@ void printf_dbg(const char *fmt, ...)
}
#endif
va_end(va_args);
#else
(void)fmt;
#endif
}
#endif
8 changes: 8 additions & 0 deletions src/drv/stm32cube/bsp_print_dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ limitations under the License.
#ifndef _BSP_PRINT_DBG_H_
#define _BSP_PRINT_DBG_H_

#ifndef MAKE_DEBUG

#define print_dbg(...)
#define printf_dbg(...)

#else

/* Low level print debug through Semi Hosting(SWD debug) */
void print_dbg(const char *data, const uint32_t size);

/* Low level printf debug through Semi Hosting(SWD debug) */
void printf_dbg(const char *fmt, ...);
#endif

#endif /* _BSP_PRINT_DBG_H_ */
8 changes: 4 additions & 4 deletions src/hydranfc/file_fmt_pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ int sniff_create_pcap_file(uint8_t* buffer, uint32_t size);
int file_fmt_create_pcap(FIL *file_handle);
int file_fmt_flush_close(FIL *file_handle, uint8_t* buffer, uint32_t size);

__attribute__ ((always_inline)) inline
//__attribute__ ((always_inline)) inline
void sniff_write_pcap_global_header(void);

__attribute__ ((always_inline)) inline
//__attribute__ ((always_inline)) inline
void sniff_write_pcap_packet_header (uint32_t nb_cycles_start);

__attribute__ ((always_inline)) inline
//__attribute__ ((always_inline)) inline
void sniff_write_data_header (uint8_t pow, uint32_t protocol, uint32_t speed, uint32_t nb_cycles_end, uint32_t parity);

__attribute__ ((always_inline)) inline
//__attribute__ ((always_inline)) inline
void sniff_write_pcap_data(uint8_t data);

uint32_t sniffer_get_size_pcap(void);
Expand Down
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "hydrabus/hydrabus_serprog.h"

#include "bsp.h"
#include "bsp_print_dbg.h"

#include "script.h"

Expand Down Expand Up @@ -151,6 +152,12 @@ int main(void)

bsp_scs_dwt_cycle_counter_enabled();

#ifdef MAKE_DEBUG
// set SWO on PB3
palSetPadMode(GPIOB, 3, PAL_MODE_ALTERNATE(0));
printf_dbg("DEBUG Trace started\n");
#endif

/* Configure PA0 (UBTN), PA4 (ULED) and initialize the SD driver. */
hydrabus_init();

Expand Down

0 comments on commit 0099a03

Please sign in to comment.