I was porting NuttX to a STM32F401 board and I was getting this error:
ABCDF
mm_initialize: Heap: start=0x200017b0 size=92240
mm_addregion: Region 1: base=0x200017b0 size=92240
irq_unexpected_isr: ERROR irq: 3
up_assert: Assertion failed at file:irq/irq_unexpectedisr.c line: 65
up_registerdump: R0: 80000000 200017b8 20017ff8 00016840 200011d4 200017b0 20018000 00016840
up_registerdump: R8: 00000000 00000000 00000000 00000000 00000000 20001770 08003c67 08003c90
up_registerdump: xPSR: 21000200 PRIMASK: 00000000 CONTROL: 00000000
up_registerdump: EXC_RETURN: fffffff9
up_dumpstate: sp: 20000bb0
up_dumpstate: IRQ stack:
up_dumpstate: base: 20000c00
up_dumpstate: size: 00000800
up_stackdump: 20000ba0: 20000bb0 00000400 20000c00 08000cdb 00000000 00000000 00000000 00000000
up_stackdump: 20000bc0: 20001770 08003c67 08003c90 0800e8a4 00000000 0800159d 08001581 08001561
up_stackdump: 20000be0: 00000000 080012c1 00000000 20001724 200017b0 20018000 00016840 08000df7
up_dumpstate: sp: 20001770
up_dumpstate: User stack:
up_dumpstate: base: 200017ac
up_dumpstate: size: 00000400
up_stackdump: 20001760: 00000000 08003c67 08003c90 21000200 00000001 200017b0 00016850 20000ccc
up_stackdump: 20001780: 20000ccc 20000c04 00000003 20000d9c 080013cb 200017b0 00016850 00000000
up_stackdump: 200017a0: 0800020d 00000000 ffffffff 00000000 00000008 80000000 00016840 00000008
The first thing that catch my attention was the heap size=92240! This microcontroller has 64KB, so it is not possible to have a heap memory bigger than 64KB.
I noticed the CONFIG_RAM_SIZE was defined with high value (96KB) then I changed it to:
CONFIG_RAM_SIZE=65536
But it took no effect!
Then I changed the nuttx/boards/arm/stm32/nucleo-f4x1re/scripts/f401re.ld to the right values:
MEMORY
{
flash (rx) : ORIGIN = 0x08000000, LENGTH = 128K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
}
This not luck!! What a challenge!?
Then I decided to search where mm_initialize and mm_addregion are called inside arch/arm/src/stm32 and found some important information at stm32_allocateheap.c
/* Most members of both the STM32F20xxx and STM32F40xxx families have 128Kib
* in two banks:
*
* 1) 112KiB of System SRAM beginning at address 0x2000:0000
* 2) 16KiB of System SRAM beginning at address 0x2001:c000
*
* The STM32F401 family is an exception and has only 64KiB or 96Kib total on one
* bank:
And:
/* The STM32 F2 and the STM32 F401/F411 have no CCM SRAM */
And finally:
# if defined(CONFIG_STM32_STM32F401xBC)
# define SRAM1_END 0x20010000
# elif defined(CONFIG_STM32_STM32F401xDE)
# define SRAM1_END 0x20018000
Yes, that was the issue: my board is powered by STM32F401RCT6 but my .config was:
# CONFIG_STM32_STM32F401xBC is not set
CONFIG_STM32_STM32F401xDE=y
After changing it to MCU to STM32F401RC I saw it in my .config:
CONFIG_STM32_STM32F401xBC=y
# CONFIG_STM32_STM32F401xDE is not set
And now everything worked as expected!
NuttShell (NSH) NuttX-12.3.0-RC0
nsh> ?
help usage: help [-v] [<cmd>]
. cd exit mount source uptime
[ cp false mv test usleep
? cmp help printf time xd
alias dirname hexdump pwd true
unalias dd kill rm truncate
basename dmesg ls rmdir uname
break echo mkdir set umount
cat exec mkrd sleep unset
Builtin Apps:
nsh sh
nsh> uname -a
NuttX 12.3.0-RC0 6cad7e9582-dirty Oct 12 2023 15:36:23 arm stm32f401rc-rs485
nsh>
Note: I found a user that faced similar issue: https://nuttx.yahoogroups.narkive.com/1j3cuqjV/stm32f410-support but probably he never figured out this issue (he never replied later and I never saw he again in the NuttX community). The only reason because I succeed is because I never give up and I investigate deeper!