Skip to content

stm32/profiler.c: Add gprof-compatible profiling for STM32. #5926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ports/stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@ LDFLAGS += --gc-sections

# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g -DPENDSV_DEBUG
CFLAGS += -DPENDSV_DEBUG
COPT = -O0
else
COPT += -Os -DNDEBUG
endif

# Always enable symbols -- They're occasionally useful, and don't make it into the
# final .bin/.hex/.dfu so the extra size doesn't matter.
CFLAGS += -g

# Options for mpy-cross
MPY_CROSS_FLAGS += -march=armv7m

Expand Down Expand Up @@ -320,7 +324,7 @@ SRC_C = \
adc.c \
$(wildcard $(BOARD_DIR)/*.c)

SRC_O = \
SRC_O += \
$(STARTUP_FILE) \
$(SYSTEM_FILE)

Expand All @@ -342,6 +346,18 @@ SRC_O += \
endif
endif

ifeq ($(MICROPY_ENABLE_PROFILER),1)
SRC_C += \
profiler.c \

SRC_O += \
profiler_mcount.o \

$(BUILD)/py/%.o: CFLAGS += -pg

CFLAGS += -DMICROPY_ENABLE_PROFILER
endif

SRC_HAL = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES)xx_,\
hal.c \
hal_adc.c \
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/boards/common_basic.ld
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SECTIONS
.text :
{
. = ALIGN(4);
_stext = .; /* define a global symbol at start of code */
*(.text*) /* .text* sections (code) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
/* *(.glue_7) */ /* glue arm to thumb code */
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/boards/common_bl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SECTIONS
.text :
{
. = ALIGN(4);
_stext = .; /* define a global symbol at start of code */
*(.text*) /* .text* sections (code) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
/* *(.glue_7) */ /* glue arm to thumb code */
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/boards/common_blifs.ld
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SECTIONS
.text :
{
. = ALIGN(4);
_stext = .; /* define a global symbol at start of code */
*(.text*) /* .text* sections (code) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
/* *(.glue_7) */ /* glue arm to thumb code */
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/boards/common_ifs.ld
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SECTIONS
.text :
{
. = ALIGN(4);
_stext = .; /* define a global symbol at start of code */
*(.text*) /* .text* sections (code) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
/* *(.glue_7) */ /* glue arm to thumb code */
Expand Down
12 changes: 11 additions & 1 deletion ports/stm32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@

// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t machine_module;
extern const struct _mp_obj_module_t profiler_module;
extern const struct _mp_obj_module_t pyb_module;
extern const struct _mp_obj_module_t stm_module;
extern const struct _mp_obj_module_t mp_module_ubinascii;
Expand All @@ -239,8 +240,14 @@ extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_network;
extern const struct _mp_obj_module_t mp_module_onewire;

#if MICROPY_ENABLE_PROFILER
#define PROFILER_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_profiler), MP_ROM_PTR(&profiler_module) },
#else
#define PROFILER_BUILTIN_MODULE
#endif

#if MICROPY_PY_STM
#define STM_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_stm), MP_ROM_PTR(&stm_module) },
#define STM_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_stm), MP_ROM_PTR(&stm_module) },
#else
#define STM_BUILTIN_MODULE
#endif
Expand All @@ -264,6 +271,7 @@ extern const struct _mp_obj_module_t mp_module_onewire;

#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
PROFILER_BUILTIN_MODULE \
{ MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
STM_BUILTIN_MODULE \
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
Expand Down Expand Up @@ -332,6 +340,8 @@ struct _mp_bluetooth_btstack_root_pointers_t;
/* list of registered NICs */ \
mp_obj_list_t mod_network_nic_list; \
\
uint8_t *profiling_buffer;
\
MICROPY_PORT_ROOT_POINTER_MBEDTLS \
MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE \
MICROPY_PORT_ROOT_POINTER_BLUETOOTH_BTSTACK \
Expand Down
Loading