This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 1afbfb099eb arch/arm/src/rp23xx: Fix PSRAM heap init and no-PSRAM
fallback
1afbfb099eb is described below
commit 1afbfb099ebfb27c23f5244efc5d41cb414f2a58
Author: Shubham S Taple <[email protected]>
AuthorDate: Sat Nov 21 09:00:39 2026 +0000
arch/arm/src/rp23xx: Fix PSRAM heap init and no-PSRAM fallback
The separate-PSRAM-heap path was broken in three ways:
1. up_extraheaps_init() still used the removed config.heap field
(config.heap = KRN_HEAP). struct mm_heap_config_s now exposes
allocheap instead. Set config.allocheap = true so the heap
control block, and therefore its mutex, is allocated from the
kernel heap in SRAM.
2. up_allocate_kheap() and up_allocate_heap() unconditionally
used g_idle_topstack / PSRAM_START without checking whether
PSRAM was actually fitted. On boards without PSRAM this
yielded a zero-sized user heap and a kernel heap that ran
into the user region. Detect the PSRAM size and fall back
to splitting internal SRAM between the kernel heap
(CONFIG_MM_KERNEL_HEAPSIZE) and the user heap. The protected
build uses USERSPACE->us_bssend as the base of the split.
3. g_psramheap was file-static, so nothing outside
rp23xx_heaps.c could refer to the PSRAM heap. Drop static
and declare it extern in a new rp23xx_heaps.h header as
the documentation refers.
Also add the missing <nuttx/userspace.h> include needed by the
CONFIG_BUILD_PROTECTED paths, and assert that the computed heap
range is non-empty.
Signed-off-by: Shubham S Taple <[email protected]>
---
arch/arm/src/rp23xx/rp23xx_heaps.c | 56 +++++++++++++++++++++++++++++++++-----
arch/arm/src/rp23xx/rp23xx_heaps.h | 50 ++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 7 deletions(-)
diff --git a/arch/arm/src/rp23xx/rp23xx_heaps.c
b/arch/arm/src/rp23xx/rp23xx_heaps.c
index 39e2bf61582..190353eca5c 100644
--- a/arch/arm/src/rp23xx/rp23xx_heaps.c
+++ b/arch/arm/src/rp23xx/rp23xx_heaps.c
@@ -29,10 +29,15 @@
#include <nuttx/kmalloc.h>
#include <nuttx/mm/mm.h>
+#ifdef CONFIG_BUILD_PROTECTED
+# include <nuttx/userspace.h>
+#endif
+
#include <string.h>
#include "arm_internal.h"
#include "rp23xx_psram.h"
+#include "rp23xx_heaps.h"
#if defined(CONFIG_RP23XX_PSRAM)
@@ -52,7 +57,7 @@
* Public Functions
****************************************************************************/
#if defined(CONFIG_RP23XX_PSRAM_HEAP_SEPARATE)
-static struct mm_heap_s *g_psramheap;
+struct mm_heap_s *g_psramheap;
#endif
/* up_initialize() calls arm_addregion() whenever CONFIG_MM_REGIONS > 1.
@@ -91,21 +96,58 @@ void arm_addregion(void)
void up_allocate_kheap(void **heap_start, size_t *heap_size)
{
- *heap_start = (void *)g_idle_topstack;
+#ifdef CONFIG_BUILD_PROTECTED
+ uintptr_t base = (uintptr_t) USERSPACE->us_bssend;
+#else
+ uintptr_t base = g_idle_topstack;
+#endif
#ifdef CONFIG_ARCH_PGPOOL_PBASE
- *heap_size = CONFIG_ARCH_PGPOOL_PBASE - g_idle_topstack;
+ size_t end = CONFIG_ARCH_PGPOOL_PBASE;
#else
- *heap_size = CONFIG_RAM_END - g_idle_topstack;
+ size_t end = CONFIG_RAM_END;
#endif
+
+ *heap_start = (void *)base;
+ if (rp23xx_psram_size() > 0)
+ {
+ DEBUGASSERT(base <= end);
+ *heap_size = end - base;
+ }
+ else
+ {
+ *heap_size = CONFIG_MM_KERNEL_HEAPSIZE;
+ }
}
/* Use the external PSRAM as the default user heap */
void up_allocate_heap(void **heap_start, size_t *heap_size)
{
- *heap_start = PSRAM_START;
- *heap_size = rp23xx_psram_size();
+ size_t psram_size = rp23xx_psram_size();
+
+ if (psram_size > 0)
+ {
+ *heap_start = PSRAM_START;
+ *heap_size = psram_size;
+ }
+ else
+ {
+#ifdef CONFIG_BUILD_PROTECTED
+ uintptr_t base = (uintptr_t)USERSPACE->us_bssend +
+ CONFIG_MM_KERNEL_HEAPSIZE;
+#else
+ uintptr_t base = g_idle_topstack + CONFIG_MM_KERNEL_HEAPSIZE;
+#endif
+#ifdef CONFIG_ARCH_PGPOOL_PBASE
+ size_t end = CONFIG_ARCH_PGPOOL_PBASE;
+#else
+ size_t end = CONFIG_RAM_END;
+#endif
+ *heap_start = (void *)base;
+ DEBUGASSERT(base <= end);
+ *heap_size = end - base;
+ }
}
#elif defined (CONFIG_RP23XX_PSRAM_HEAP_SEPARATE)
@@ -126,7 +168,7 @@ void up_extraheaps_init(void)
*/
memset(&config, 0, sizeof(config));
- config.heap = KRN_HEAP;
+ config.allocheap = true;
config.name = "psram";
config.start = PSRAM_START;
config.size = psram_size;
diff --git a/arch/arm/src/rp23xx/rp23xx_heaps.h
b/arch/arm/src/rp23xx/rp23xx_heaps.h
new file mode 100644
index 00000000000..e7a8518ffc1
--- /dev/null
+++ b/arch/arm/src/rp23xx/rp23xx_heaps.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+ * arch/arm/src/rp23xx/rp23xx_heaps.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_RP23XX_RP23XX_HEAPS_H
+#define __ARCH_ARM_SRC_RP23XX_RP23XX_HEAPS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/mm/mm.h>
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+#if defined(CONFIG_RP23XX_PSRAM_HEAP_SEPARATE)
+extern struct mm_heap_s *g_psramheap;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_ARM_SRC_RP23XX_RP23XX_HEAPS_H */
\ No newline at end of file