Skip to content

stm32: If the memory usage is high, the flash is abnormal. #14779

@KwonTae-young

Description

@KwonTae-young

Describe the bug
If the memory usage on the STM32 board is high, flash will behave abnormally.
If you do flash, the board will not do anything.

To Reproduce
The test was stm32f4_disco.
I modified hello_world slightly to increase memory usage.

Steps to reproduce the behavior:

west init zephyrproject -m https://github.com/KwonTae-young/zephyr/ --mr memory_usage_flash
cd zephyrproject/zephyr
source zephyr-env.sh
mkdir samples/hello_world/build
cd samples/hello_world/build/
cmake -DBOARD=stm32f4_disco ..
make -j8 flash

Expected behavior
I expected to see hello world in console.

Impact
If memory usage is high, flash will behave abnormally.

Screenshots or console output
Memory usage is 83.59%.
No errors occur during build and flash.
image

root:build# pwd
/tmp/zephyrproject/zephyr/samples/hello_world/build
root:build# 
root:build# cmake -DBOARD=stm32f4_disco ..
Zephyr version: 1.14.0
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.6.7", minimum required is "3.4") 
-- Selected BOARD stm32f4_disco
-- Found west: /usr/local/bin/west (found suitable version "0.5.6", minimum required is "0.5.4")
-- Loading /tmp/zephyrproject/zephyr/boards/arm/stm32f4_disco/stm32f4_disco.dts as base
-- Overlaying /tmp/zephyrproject/zephyr/dts/common/common.dts
Parsing Kconfig tree in /tmp/zephyrproject/zephyr/Kconfig
Loading /tmp/zephyrproject/zephyr/boards/arm/stm32f4_disco/stm32f4_disco_defconfig as base
Merging /tmp/zephyrproject/zephyr/samples/hello_world/prj.conf
Configuration written to '/tmp/zephyrproject/zephyr/samples/hello_world/build/zephyr/.config'
-- Cache files will be written to: /root/.cache/zephyr
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- The ASM compiler identification is GNU
-- Found assembler: /opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Performing Test toolchain_is_ok
-- Performing Test toolchain_is_ok - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/zephyrproject/zephyr/samples/hello_world/build
root:build# 
root:build# 
root:build# make -j8 flash
Scanning dependencies of target driver_validation_h_target
Scanning dependencies of target syscall_macros_h_target
Scanning dependencies of target kobj_types_h_target
Scanning dependencies of target syscall_list_h_target
[  2%] Generating include/generated/syscall_macros.h
[  2%] Generating include/generated/driver-validation.h
[  3%] Generating include/generated/kobj-types-enum.h, include/generated/otype-to-str.h
[  4%] Generating misc/generated/syscalls.json
[  4%] Built target syscall_macros_h_target
[  4%] Generating include/generated/syscall_dispatch.c, include/generated/syscall_list.h
[  4%] Built target driver_validation_h_target
[  4%] Built target kobj_types_h_target
[  6%] Built target syscall_list_h_target
Scanning dependencies of target offsets
[  7%] Building C object zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj
[  7%] Built target offsets
Scanning dependencies of target offsets_h
[  8%] Generating include/generated/offsets.h
[  8%] Built target offsets_h
Scanning dependencies of target app
Scanning dependencies of target kernel
Scanning dependencies of target zephyr
Scanning dependencies of target arch__arm__core__cortex_m
Scanning dependencies of target arch__arm__core
Scanning dependencies of target linker_script_target
Scanning dependencies of target lib__libc__minimal
Scanning dependencies of target arch__arm__core__cortex_m__mpu
[  9%] Generating linker.cmd
[  9%] Built target linker_script_target
Scanning dependencies of target boards__arm__stm32f4_disco
[  9%] Building C object CMakeFiles/app.dir/src/main.c.obj
[  9%] Building C object zephyr/arch/arch/arm/core/cortex_m/mpu/CMakeFiles/arch__arm__core__cortex_m__mpu.dir/arm_core_mpu.c.obj
[ 10%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/atoi.c.obj
[ 11%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/device.c.obj
[ 12%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtol.c.obj
[ 13%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtoul.c.obj
[ 14%] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/vector_table.S.obj
[ 15%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/malloc.c.obj
[ 16%] Building C object zephyr/boards/arm/stm32f4_disco/CMakeFiles/boards__arm__stm32f4_disco.dir/pinmux.c.obj
[ 17%] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/reset.S.obj
[ 18%] Building C object zephyr/CMakeFiles/zephyr.dir/arch/common/isr_tables.c.obj
[ 18%] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/nmi_on_reset.S.obj
[ 19%] Linking C static library app/libapp.a
[ 20%] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/prep_c.c.obj
[ 21%] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/exc_exit.S.obj
[ 21%] Built target app
[ 22%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/irq_init.c.obj
[ 23%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/errno.c.obj
[ 23%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strncasecmp.c.obj
[ 24%] Building C object zephyr/arch/arch/arm/core/cortex_m/mpu/CMakeFiles/arch__arm__core__cortex_m__mpu.dir/arm_mpu.c.obj
[ 25%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strstr.c.obj
[ 26%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/string.c.obj
[ 26%] Building C object zephyr/CMakeFiles/zephyr.dir/arch/common/sw_isr_common.c.obj
[ 27%] Linking C static library libboards__arm__stm32f4_disco.a
[ 28%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/prf.c.obj
[ 29%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/stdout_console.c.obj
Scanning dependencies of target drivers__gpio
[ 30%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/sprintf.c.obj
[ 31%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/swap.c.obj
[ 31%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/idle.c.obj
[ 31%] Built target boards__arm__stm32f4_disco
[ 32%] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/scb.c.obj
[ 32%] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/fprintf.c.obj
Scanning dependencies of target drivers__pwm
[ 33%] Linking C static library liblib__libc__minimal.a
[ 34%] Linking C static library libarch__arm__core__cortex_m__mpu.a
[ 35%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc32_sw.c.obj
[ 35%] Built target lib__libc__minimal
[ 36%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/init.c.obj
[ 37%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc16_sw.c.obj
[ 37%] Built target arch__arm__core__cortex_m__mpu
[ 38%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc8_sw.c.obj
Scanning dependencies of target drivers__serial
[ 39%] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/nmi.c.obj
[ 40%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc7_sw.c.obj
[ 41%] Building C object zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_stm32.c.obj
[ 42%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mailbox.c.obj
[ 43%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/fdtable.c.obj
[ 44%] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/swap_helper.S.obj
[ 45%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mem_slab.c.obj
[ 45%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/fault.c.obj
[ 46%] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_stm32.c.obj
[ 47%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mempool.c.obj
[ 48%] Building C object zephyr/drivers/pwm/CMakeFiles/drivers__pwm.dir/pwm_stm32.c.obj
[ 50%] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/exc_manage.c.obj
[ 51%] Linking C static library libdrivers__gpio.a
[ 51%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/mempool.c.obj
[ 52%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/msg_q.c.obj
[ 53%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/irq_manage.c.obj
[ 54%] Linking C static library libdrivers__serial.a
[ 55%] Linking C static library libarch__arm__core__cortex_m.a
[ 55%] Built target drivers__gpio
[ 55%] Built target drivers__serial
[ 56%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/rb.c.obj
[ 57%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/thread.c.obj
[ 58%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/thread_entry.c.obj
[ 58%] Linking C static library libdrivers__pwm.a
[ 58%] Built target arch__arm__core__cortex_m
[ 58%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mutex.c.obj
[ 59%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/pipes.c.obj
[ 60%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/work_q.c.obj
[ 61%] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/printk.c.obj
[ 62%] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/cpu_idle.S.obj
[ 62%] Built target drivers__pwm
[ 63%] Building C object zephyr/CMakeFiles/zephyr.dir/misc/generated/configs.c.obj
[ 64%] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/st_stm32/common/arm_mpu_regions.c.obj
[ 64%] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/st_stm32/stm32f4/soc.c.obj
[ 65%] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/fault_s.S.obj
[ 66%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/fatal.c.obj
[ 67%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/sys_fatal_error_handler.c.obj
[ 68%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/sched.c.obj
[ 67%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/queue.c.obj
[ 69%] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/st_stm32/common/stm32cube_hal.c.obj
[ 70%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/st/stm32cube/stm32f4xx/soc/system_stm32f4xx.c.obj
[ 71%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_hal.c.obj
[ 72%] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/thread_abort.c.obj
[ 73%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_hal_rcc.c.obj
[ 73%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_hal_tim.c.obj
[ 74%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/sem.c.obj
[ 75%] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/isr_wrapper.S.obj
[ 76%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/stack.c.obj
[ 76%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/system_work_q.c.obj
[ 77%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/interrupt_controller/exti_stm32.c.obj
[ 78%] Building C object zephyr/CMakeFiles/zephyr.dir/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_utils.c.obj
[ 79%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/console/uart_console.c.obj
[ 80%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/thread.c.obj
[ 81%] Linking C static library libarch__arm__core.a
[ 82%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/clock_control/stm32f4x_ll_clock.c.obj
[ 83%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/clock_control/stm32_ll_clock.c.obj
[ 84%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/thread_abort.c.obj
[ 85%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/work_q.c.obj
[ 86%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/version.c.obj
[ 86%] Built target arch__arm__core
[ 86%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/pinmux/stm32/pinmux_stm32.c.obj
[ 87%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/smp.c.obj
[ 87%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/timeout.c.obj
[ 88%] Building C object zephyr/kernel/CMakeFiles/kernel.dir/timer.c.obj
[ 89%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/timer/sys_clock_init.c.obj
[ 90%] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/timer/cortex_m_systick.c.obj
[ 91%] Linking C static library libkernel.a
[ 91%] Built target kernel
[ 92%] Linking C static library libzephyr.a
[ 92%] Built target zephyr
Scanning dependencies of target zephyr_prebuilt
[ 93%] Building C object zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj
[ 94%] Linking C executable zephyr_prebuilt.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       14040 B         1 MB      1.34%
            SRAM:      164352 B       192 KB     83.59%
        IDT_LIST:         184 B         2 KB      8.98%
[ 94%] Built target zephyr_prebuilt
Scanning dependencies of target linker_pass_final_script_target
[ 95%] Generating linker_pass_final.cmd
[ 95%] Built target linker_pass_final_script_target
[ 96%] Generating isr_tables.c
Scanning dependencies of target kernel_elf
[ 97%] Building C object zephyr/CMakeFiles/kernel_elf.dir/misc/empty_file.c.obj
[ 98%] Building C object zephyr/CMakeFiles/kernel_elf.dir/isr_tables.c.obj
[ 98%] Linking C executable zephyr.elf
Generating files from zephyr.elf for board: stm32f4_disco
[ 98%] Built target kernel_elf
Scanning dependencies of target flash
[100%] Flashing stm32f4_disco
Using runner: openocd
Open On-Chip Debugger 0.10.0+dev-g0b1cbf175-dirty (2019-03-08-20:54)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 2000 kHz
Info : STLINK V2J25M14 (API v2) VID:PID 0483:374B
Info : Target voltage: 2.889911
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* stm32f4x.cpu       hla_target little stm32f4x.cpu       running
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080011ac msp: 0x200277a0
auto erase enabled
Info : device id = 0x10076413
Info : flash size = 1024 kbytes
wrote 16384 bytes from file /tmp/zephyrproject/zephyr/samples/hello_world/build/zephyr/zephyr.elf in 1.886646s (8.481 KiB/s)
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080011ac msp: 0x200277a0
verified 14040 bytes in 0.173583s (78.988 KiB/s)
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
shutdown command invoked
[100%] Built target flash
root:build# 

However, you can not see any output from the console.


Environment (please complete the following information):

  • OS: Ubuntu 18.04
  • Toolchain: Zephyr SDK 0.10.0
  • Commit SHA: 1f6ab22

Additional context

  1. Test on another board
    I also tested it in nrf52840_pca10056.
    Even if memory usage is 99.6%, it will work after flash.
    image
***** Booting Zephyr OS zephyr-v1.13.0-5942-g1f6ab221f242 *****   
Hello World! nrf52840_pca10056                                    
0x20000008                                                        
sizeof(test) = 256000 
  1. Change memory usage
    stm32f4_disco reduces the memory usage to 63.25%, and the flash works normally.
    Below is the console output by memory usage in stm32f4_disco.
  • SIZE = 30000(63.25%)
***** Booting Zephyr OS zephyr-v1.13.0-5942-g1f6ab221f242 *****
Hello World! stm32f4_disco
0x20000008
sizeof(test) = 120000
  • SIZE = 40000(83.59%)

  1. Flash with ST-Link Utility
    I tried to flash zephyr.bin generated by build using ST-Link Utility.
    The result was the same.
    image

I'm sorry I do not have enough English.
Thank you.

Metadata

Metadata

Labels

bugThe issue is a bug, or the PR is fixing a bugplatform: STM32ST Micro STM32priority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions