From 3113d96497853af196fa63a987e8c3ff550209c8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 30 Oct 2020 11:16:52 -0400 Subject: [PATCH] keep target as L476; minimize RAM usage --- Makefile | 13 ++++--- STM32L432xC_stmdsp.ld | 85 +++++++++++++++++++++++++++++++++++++++++++ cfg/chconf.h | 44 +++++++++++----------- cfg/halconf.h | 10 ++--- cfg/mcuconf.h | 5 +-- source/main.cpp | 11 +++--- 6 files changed, 127 insertions(+), 41 deletions(-) create mode 100644 STM32L432xC_stmdsp.ld diff --git a/Makefile b/Makefile index f35692a..95a3b7b 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ # Compiler options here. ifeq ($(USE_OPT),) USE_OPT = -Og -ggdb -fomit-frame-pointer -falign-functions=16 -mtune=cortex-m4 +# USE_OPT = -Os -fomit-frame-pointer -falign-functions=16 -mtune=cortex-m4 endif # C specific options here (added to USE_OPT). @@ -55,7 +56,7 @@ endif # Stack size to be allocated to the Cortex-M process stack. This stack is # the stack used by the main() thread. ifeq ($(USE_PROCESS_STACKSIZE),) - USE_PROCESS_STACKSIZE = 4096 + USE_PROCESS_STACKSIZE = 2048 endif # Stack size to the allocated to the Cortex-M main/exceptions stack. This @@ -100,10 +101,10 @@ include $(CHIBIOS)/os/license/license.mk include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32l4xx.mk # HAL-OSAL files (optional). include $(CHIBIOS)/os/hal/hal.mk -#include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform.mk -#include $(CHIBIOS)/os/hal/boards/ST_STM32L476_DISCOVERY/board.mk -include $(CHIBIOS)/os/hal/boards/ST_NUCLEO32_L432KC/board.mk -include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform_l432.mk +include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform.mk +include $(CHIBIOS)/os/hal/boards/ST_STM32L476_DISCOVERY/board.mk +#include $(CHIBIOS)/os/hal/boards/ST_NUCLEO32_L432KC/board.mk +#include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform_l432.mk include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk # RTOS files (optional). include $(CHIBIOS)/os/rt/rt.mk @@ -117,7 +118,7 @@ include $(CHIBIOS)/tools/mk/autobuild.mk # Define linker script file here. #LDSCRIPT= $(STARTUPLD)/STM32L476xG.ld -LDSCRIPT= $(STARTUPLD)/STM32L432xC.ld +LDSCRIPT= STM32L432xC_stmdsp.ld # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. diff --git a/STM32L432xC_stmdsp.ld b/STM32L432xC_stmdsp.ld new file mode 100644 index 0000000..0226659 --- /dev/null +++ b/STM32L432xC_stmdsp.ld @@ -0,0 +1,85 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed 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. +*/ + +/* + * STM32L432xC memory setup. + */ +MEMORY +{ + flash0 (rx) : org = 0x08000000, len = 256k + flash1 (rx) : org = 0x00000000, len = 0 + flash2 (rx) : org = 0x00000000, len = 0 + flash3 (rx) : org = 0x00000000, len = 0 + flash4 (rx) : org = 0x00000000, len = 0 + flash5 (rx) : org = 0x00000000, len = 0 + flash6 (rx) : org = 0x00000000, len = 0 + flash7 (rx) : org = 0x00000000, len = 0 + ram0 (wx) : org = 0x20000000, len = 48k /* Save 16k of SRAM2 for loaded ELF */ + ram1 (wx) : org = 0x00000000, len = 0 + ram2 (wx) : org = 0x00000000, len = 0 + ram3 (wx) : org = 0x00000000, len = 0 + ram4 (wx) : org = 0x00000000, len = 0 + ram5 (wx) : org = 0x00000000, len = 0 + ram6 (wx) : org = 0x00000000, len = 0 + ram7 (wx) : org = 0x00000000, len = 0 +} + +/* For each data/text section two region are defined, a virtual region + and a load region (_LMA suffix).*/ + +/* Flash region to be used for exception vectors.*/ +REGION_ALIAS("VECTORS_FLASH", flash0); +REGION_ALIAS("VECTORS_FLASH_LMA", flash0); + +/* Flash region to be used for constructors and destructors.*/ +REGION_ALIAS("XTORS_FLASH", flash0); +REGION_ALIAS("XTORS_FLASH_LMA", flash0); + +/* Flash region to be used for code text.*/ +REGION_ALIAS("TEXT_FLASH", flash0); +REGION_ALIAS("TEXT_FLASH_LMA", flash0); + +/* Flash region to be used for read only data.*/ +REGION_ALIAS("RODATA_FLASH", flash0); +REGION_ALIAS("RODATA_FLASH_LMA", flash0); + +/* Flash region to be used for various.*/ +REGION_ALIAS("VARIOUS_FLASH", flash0); +REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); + +/* Flash region to be used for RAM(n) initialization data.*/ +REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); + +/* RAM region to be used for Main stack. This stack accommodates the processing + of all exceptions and interrupts.*/ +REGION_ALIAS("MAIN_STACK_RAM", ram0); + +/* RAM region to be used for the process stack. This is the stack used by + the main() function.*/ +REGION_ALIAS("PROCESS_STACK_RAM", ram0); + +/* RAM region to be used for data segment.*/ +REGION_ALIAS("DATA_RAM", ram0); +REGION_ALIAS("DATA_RAM_LMA", flash0); + +/* RAM region to be used for BSS segment.*/ +REGION_ALIAS("BSS_RAM", ram0); + +/* RAM region to be used for the default heap.*/ +REGION_ALIAS("HEAP_RAM", ram0); + +/* Generic rules inclusion.*/ +INCLUDE rules.ld diff --git a/cfg/chconf.h b/cfg/chconf.h index 7e11588..04570c1 100644 --- a/cfg/chconf.h +++ b/cfg/chconf.h @@ -167,7 +167,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_REGISTRY) -#define CH_CFG_USE_REGISTRY TRUE +#define CH_CFG_USE_REGISTRY FALSE #endif /** @@ -178,7 +178,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_WAITEXIT) -#define CH_CFG_USE_WAITEXIT TRUE +#define CH_CFG_USE_WAITEXIT FALSE #endif /** @@ -235,7 +235,7 @@ * @note Requires @p CH_CFG_USE_MUTEXES. */ #if !defined(CH_CFG_USE_CONDVARS) -#define CH_CFG_USE_CONDVARS TRUE +#define CH_CFG_USE_CONDVARS FALSE #endif /** @@ -247,7 +247,7 @@ * @note Requires @p CH_CFG_USE_CONDVARS. */ #if !defined(CH_CFG_USE_CONDVARS_TIMEOUT) -#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE +#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE #endif /** @@ -269,7 +269,7 @@ * @note Requires @p CH_CFG_USE_EVENTS. */ #if !defined(CH_CFG_USE_EVENTS_TIMEOUT) -#define CH_CFG_USE_EVENTS_TIMEOUT TRUE +#define CH_CFG_USE_EVENTS_TIMEOUT FALSE #endif /** @@ -280,7 +280,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_MESSAGES) -#define CH_CFG_USE_MESSAGES TRUE +#define CH_CFG_USE_MESSAGES FALSE #endif /** @@ -306,7 +306,7 @@ * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. */ #if !defined(CH_CFG_USE_DYNAMIC) -#define CH_CFG_USE_DYNAMIC TRUE +#define CH_CFG_USE_DYNAMIC FALSE #endif /** @} */ @@ -353,7 +353,7 @@ * @note Requires @p CH_CFG_USE_MEMCORE. */ #if !defined(CH_CFG_MEMCORE_SIZE) -#define CH_CFG_MEMCORE_SIZE 0 +#define CH_CFG_MEMCORE_SIZE (3 * 1024) #endif /** @@ -389,7 +389,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_OBJ_FIFOS) -#define CH_CFG_USE_OBJ_FIFOS TRUE +#define CH_CFG_USE_OBJ_FIFOS FALSE #endif /** @@ -400,7 +400,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_PIPES) -#define CH_CFG_USE_PIPES TRUE +#define CH_CFG_USE_PIPES FALSE #endif /** @@ -411,7 +411,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_OBJ_CACHES) -#define CH_CFG_USE_OBJ_CACHES TRUE +#define CH_CFG_USE_OBJ_CACHES FALSE #endif /** @@ -422,7 +422,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_DELEGATES) -#define CH_CFG_USE_DELEGATES TRUE +#define CH_CFG_USE_DELEGATES FALSE #endif /** @@ -433,7 +433,7 @@ * @note The default is @p TRUE. */ #if !defined(CH_CFG_USE_JOBS) -#define CH_CFG_USE_JOBS TRUE +#define CH_CFG_USE_JOBS FALSE #endif /** @} */ @@ -453,7 +453,7 @@ * @note The default is @p FALSE. */ #if !defined(CH_CFG_USE_FACTORY) -#define CH_CFG_USE_FACTORY TRUE +#define CH_CFG_USE_FACTORY FALSE #endif /** @@ -469,42 +469,42 @@ * @brief Enables the registry of generic objects. */ #if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY) -#define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE +#define CH_CFG_FACTORY_OBJECTS_REGISTRY FALSE #endif /** * @brief Enables factory for generic buffers. */ #if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS) -#define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE +#define CH_CFG_FACTORY_GENERIC_BUFFERS FALSE #endif /** * @brief Enables factory for semaphores. */ #if !defined(CH_CFG_FACTORY_SEMAPHORES) -#define CH_CFG_FACTORY_SEMAPHORES TRUE +#define CH_CFG_FACTORY_SEMAPHORES FALSE #endif /** * @brief Enables factory for mailboxes. */ #if !defined(CH_CFG_FACTORY_MAILBOXES) -#define CH_CFG_FACTORY_MAILBOXES TRUE +#define CH_CFG_FACTORY_MAILBOXES FALSE #endif /** * @brief Enables factory for objects FIFOs. */ #if !defined(CH_CFG_FACTORY_OBJ_FIFOS) -#define CH_CFG_FACTORY_OBJ_FIFOS TRUE +#define CH_CFG_FACTORY_OBJ_FIFOS FALSE #endif /** * @brief Enables factory for Pipes. */ #if !defined(CH_CFG_FACTORY_PIPES) || defined(__DOXYGEN__) -#define CH_CFG_FACTORY_PIPES TRUE +#define CH_CFG_FACTORY_PIPES FALSE #endif /** @} */ @@ -556,7 +556,7 @@ * @note The default is @p FALSE. */ #if !defined(CH_DBG_ENABLE_ASSERTS) -#define CH_DBG_ENABLE_ASSERTS TRUE +#define CH_DBG_ENABLE_ASSERTS FALSE #endif /** @@ -752,7 +752,7 @@ /*===========================================================================*/ // Enable syscall support -#define PORT_USE_SYSCALL TRUE +#define PORT_USE_SYSCALL FALSE #endif /* CHCONF_H */ diff --git a/cfg/halconf.h b/cfg/halconf.h index bb6dd3a..24c6fde 100644 --- a/cfg/halconf.h +++ b/cfg/halconf.h @@ -142,7 +142,7 @@ * @brief Enables the SERIAL subsystem. */ #if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL TRUE +#define HAL_USE_SERIAL FALSE #endif /** @@ -230,7 +230,7 @@ * @note Disabling this option saves both code and data space. */ #if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) -#define ADC_USE_WAIT TRUE +#define ADC_USE_WAIT FALSE #endif /** @@ -238,7 +238,7 @@ * @note Disabling this option saves both code and data space. */ #if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) -#define ADC_USE_MUTUAL_EXCLUSION TRUE +#define ADC_USE_MUTUAL_EXCLUSION FALSE #endif /*===========================================================================*/ @@ -290,7 +290,7 @@ * @note Disabling this option saves both code and data space. */ #if !defined(DAC_USE_WAIT) || defined(__DOXYGEN__) -#define DAC_USE_WAIT TRUE +#define DAC_USE_WAIT FALSE #endif /** @@ -298,7 +298,7 @@ * @note Disabling this option saves both code and data space. */ #if !defined(DAC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) -#define DAC_USE_MUTUAL_EXCLUSION TRUE +#define DAC_USE_MUTUAL_EXCLUSION FALSE #endif /*===========================================================================*/ diff --git a/cfg/mcuconf.h b/cfg/mcuconf.h index 3a246fa..929e049 100644 --- a/cfg/mcuconf.h +++ b/cfg/mcuconf.h @@ -32,9 +32,8 @@ #define MCUCONF_H #define STM32L4xx_MCUCONF -//#define STM32L476_MCUCONF -#define STM32L432_MCUCONF -//#define STM32L433_MCUCONF +#define STM32L476_MCUCONF +//#define STM32L432_MCUCONF /* * HAL driver system settings. diff --git a/source/main.cpp b/source/main.cpp index 43abc22..414d2f7 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -21,7 +21,8 @@ constexpr unsigned int MAX_ELF_FILE_SIZE = 8 * 1024; constexpr unsigned int MAX_ERROR_QUEUE_SIZE = 8; -constexpr unsigned int MAX_SAMPLE_BUFFER_SIZE = 8000; +constexpr unsigned int MAX_SAMPLE_BUFFER_SIZE = 6000; +constexpr unsigned int MAX_SIGGEN_BUFFER_SIZE = 3000; enum class RunStatus : char { @@ -61,7 +62,7 @@ static Error error_queue_pop() static msg_t conversionMBBuffer[4]; static MAILBOX_DECL(conversionMB, conversionMBBuffer, 4); -static THD_WORKING_AREA(conversionThreadWA, 1024); +static THD_WORKING_AREA(conversionThreadWA, 2048); static THD_FUNCTION(conversionThread, arg); static time_measurement_t conversion_time_measurement; @@ -80,7 +81,7 @@ static std::array 0 CC_ALIGN(CACHE_LINE_SIZE) #endif -static std::array dac2_samples; +static std::array dac2_samples; static uint8_t elf_file_store[MAX_ELF_FILE_SIZE]; static elf::entry_t elf_entry = nullptr; @@ -116,7 +117,7 @@ int main() } static unsigned int dac_sample_count = MAX_SAMPLE_BUFFER_SIZE; -static unsigned int dac2_sample_count = MAX_SAMPLE_BUFFER_SIZE; +static unsigned int dac2_sample_count = MAX_SIGGEN_BUFFER_SIZE; static unsigned int adc_sample_count = MAX_SAMPLE_BUFFER_SIZE; void main_loop() @@ -160,7 +161,7 @@ void main_loop() case 'D': if (usbserial::read(&cmd[1], 2) == 2) { unsigned int count = cmd[1] | (cmd[2] << 8); - if (count <= MAX_SAMPLE_BUFFER_SIZE / 2) { + if (count <= MAX_SIGGEN_BUFFER_SIZE) { dac2_sample_count = count; usbserial::read(&dac2_samples[0], dac2_sample_count * sizeof(dacsample_t)); } else {