Skip to content

Commit

Permalink
Merge pull request #1682 from Ralim/pinecilv2-memory
Browse files Browse the repository at this point in the history
Adjust how heap and ram sections are allocated
  • Loading branch information
Ralim committed May 15, 2023
2 parents f1e2bf9 + df69377 commit 4fcfa93
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 45 deletions.
7 changes: 4 additions & 3 deletions source/Core/BSP/Pinecilv2/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ uint16_t ADCReadings[ADC_NORM_SAMPLES]; // room for 32 lots of the pair of readi

// Heap

extern uint8_t _heap_start;
extern uint8_t _heap_size; // @suppress("Type cannot be resolved")
extern uint8_t __HeapBase;
extern uint8_t __HeapLimit; // @suppress("Type cannot be resolved")
const uint32_t _heap_size = ((&__HeapLimit) - (&__HeapBase));
static HeapRegion_t xHeapRegions[] = {
{&_heap_start, (unsigned int)&_heap_size},
{&__HeapBase, (unsigned int)_heap_size},
{NULL, 0}, /* Terminates the array. */
{NULL, 0} /* Terminates the array. */
};
Expand Down
46 changes: 23 additions & 23 deletions source/Core/BSP/Pinecilv2/bl_mcu_sdk/common/misc/compiler/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#define BL_WR_BYTE(addr, val) ((*(volatile uint8_t *)(uintptr_t)(addr)) = (val))
#define BL_RDWD_FRM_BYTEP(p) ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0]))

#define BL_WRWD_TO_BYTEP(p, val) \
{ \
p[0] = val & 0xff; \
p[1] = (val >> 8) & 0xff; \
p[2] = (val >> 16) & 0xff; \
p[3] = (val >> 24) & 0xff; \
}
#define BL_WRWD_TO_BYTEP(p, val) \
{ \
p[0] = val & 0xff; \
p[1] = (val >> 8) & 0xff; \
p[2] = (val >> 16) & 0xff; \
p[3] = (val >> 24) & 0xff; \
}
/**
* @brief Register access macro
*/
Expand All @@ -31,25 +31,25 @@
#define BL_GET_REG_BITS_VAL(val, bitname) (((val)&bitname##_MSK) >> bitname##_POS)
#define BL_SET_REG_BITS_VAL(val, bitname, bitval) (((val)&bitname##_UMSK) | ((uint32_t)(bitval) << bitname##_POS))
#define BL_IS_REG_BIT_SET(val, bitname) (((val) & (1U << (bitname##_POS))) != 0)
#define BL_DRV_DUMMY \
{ \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
}
#define BL_DRV_DUMMY \
{ \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
}

/* Std driver attribute macro*/
#ifndef BFLB_USE_CUSTOM_LD_SECTIONS
//#define ATTR_UNI_SYMBOL
#define ATTR_STRINGIFY(x) #x
#define ATTR_TOSTRING(x) ATTR_STRINGIFY(x)
#define ATTR_UNI_SYMBOL __FILE__ ATTR_TOSTRING(__LINE__)
#define ATTR_CLOCK_SECTION __attribute__((section(".sclock_rlt_code." ATTR_UNI_SYMBOL)))
#define ATTR_CLOCK_CONST_SECTION __attribute__((section(".sclock_rlt_const." ATTR_UNI_SYMBOL)))
#define ATTR_TCM_SECTION __attribute__((section(".tcm_code." ATTR_UNI_SYMBOL)))
#define ATTR_TCM_CONST_SECTION __attribute__((section(".tcm_const." ATTR_UNI_SYMBOL)))
#define ATTR_DTCM_SECTION __attribute__((section(".tcm_data")))
// #define ATTR_UNI_SYMBOL
#define ATTR_STRINGIFY(x) #x
#define ATTR_TOSTRING(x) ATTR_STRINGIFY(x)
#define ATTR_UNI_SYMBOL __FILE__ ATTR_TOSTRING(__LINE__)
#define ATTR_CLOCK_SECTION __attribute__((section(".sclock_rlt_code." ATTR_UNI_SYMBOL)))
#define ATTR_CLOCK_CONST_SECTION __attribute__((section(".sclock_rlt_const." ATTR_UNI_SYMBOL)))
#define ATTR_TCM_SECTION __attribute__((section(".tcm_code." ATTR_UNI_SYMBOL)))
#define ATTR_TCM_CONST_SECTION __attribute__((section(".tcm_const." ATTR_UNI_SYMBOL)))
// #define ATTR_DTCM_SECTION __attribute__((section(".tcm_data")))
#define ATTR_HSRAM_SECTION __attribute__((section(".hsram_code")))
#define ATTR_DMA_RAM_SECTION __attribute__((section(".system_ram")))
#define ATTR_NOCACHE_RAM_SECTION __attribute__((section(".nocache_ram")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ OUTPUT_ARCH( "riscv" )
ENTRY(_enter)

StackSize = 0x800; /* 2KB */
HeapSize = 0x800; /* 2KB */

__EM_SIZE = DEFINED(ble_controller_init) ? 8K : 0K;

MEMORY
{
xip_memory (rx) : ORIGIN = 0x23000000, LENGTH = 1022K
itcm_memory (rx) : ORIGIN = 0x22014000, LENGTH = 16K
itcm_memory (rx) : ORIGIN = 0x22014000, LENGTH = 12K
dtcm_memory (rx) : ORIGIN = 0x42017000, LENGTH = 4K
ram_memory (!rx) : ORIGIN = 0x42018000, LENGTH = 64K
rsvd_memory (!rx) : ORIGIN = 0x42028000, LENGTH = 1K
ram2_memory (!rx) : ORIGIN = 0x42028400, LENGTH = (31K - __EM_SIZE)
ram_memory (!rx) : ORIGIN = 0x42018000, LENGTH = 96K
hbn_memory (rx) : ORIGIN = 0x40010000, LENGTH = 0xE00 /* hbn ram 4K used 3.5K*/
}

Expand Down Expand Up @@ -211,21 +209,27 @@ SECTIONS
__tcm_data_end__ = .;
} > dtcm_memory

/* .heap_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of heap sections, and assign
* values to heap symbols later */
.heap_dummy (NOLOAD):

/*************************************************************************/
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy (NOLOAD):
{
. = ALIGN(0x4);
. = . + HeapSize;
. = . + StackSize;
. = ALIGN(0x4);
} > dtcm_memory

_HeapBase = ORIGIN(dtcm_memory) + LENGTH(dtcm_memory) - StackSize - HeapSize;
_HeapSize = HeapSize;
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(dtcm_memory) + LENGTH(dtcm_memory);
PROVIDE( __freertos_irq_stack_top = __StackTop);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(_HeapBase >= __tcm_data_end__, "region RAM overflowed with stack")
ASSERT(__StackLimit >= __tcm_data_end__, "region RAM overflowed with stack")
/*************************************************************************/

/*************************************************************************/
/* .stack_dummy section doesn't contains any symbols. It is only
Expand Down Expand Up @@ -311,17 +315,16 @@ SECTIONS
. = ALIGN(4);
__HeapBase = .;

/*__end__ = .;*/
/*end = __end__;*/
KEEP(*(.heap*))

. = ALIGN(4);
__HeapLimit = .;
} > ram_memory

PROVIDE (__heap_min_size = 0x400);
__HeapLimit = ORIGIN(ram_memory) + LENGTH(ram_memory);

PROVIDE( _heap_start = ORIGIN(ram2_memory) );
PROVIDE( _heap_size = LENGTH(ram2_memory) );
ASSERT((__HeapLimit - __HeapBase ) >= __heap_min_size, "heap size is too short.")

}

2 changes: 0 additions & 2 deletions source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,10 @@ $(HEXFILE_DIR)/$(model)_font_compressed_%.elf : \

$(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile
@test -d $(@D) || mkdir -p $(@D)
@echo Compiling ${<}
@$(CC) -c $(CFLAGS) $< -o $@

$(OUTPUT_DIR)/%.o : %.cpp Makefile
@test -d $(@D) || mkdir -p $(@D)
@echo Compiling ${<}
@$(CPP) -c $(CXXFLAGS) $< -o $@

$(OUT_OBJS_S): $(OUTPUT_DIR)/%.o: %.S Makefile
Expand Down

0 comments on commit 4fcfa93

Please sign in to comment.