From abc49a6a136372d8cb2ee7dfb5ef8957307e28bc Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Thu, 13 Jun 2019 05:52:40 -0600 Subject: [PATCH] arch/arm/src/stm32l4: if SRAM3 is used as heap, do not power it off in stop 2 mode. --- arch/arm/src/lpc31xx/lpc31_allocateheap.c | 2 +- arch/arm/src/stm32f7/stm32_allocateheap.c | 6 +-- arch/arm/src/stm32h7/stm32_allocateheap.c | 2 +- arch/arm/src/stm32l4/Kconfig | 11 +++++- .../src/stm32l4/hardware/stm32l4xrxx_rcc.h | 1 + arch/arm/src/stm32l4/stm32l4_allocateheap.c | 37 ++++++++----------- arch/arm/src/stm32l4/stm32l4_pmstop.c | 8 +++- net/local/local_fifo.c | 2 +- sched/Kconfig | 6 +-- 9 files changed, 42 insertions(+), 33 deletions(-) diff --git a/arch/arm/src/lpc31xx/lpc31_allocateheap.c b/arch/arm/src/lpc31xx/lpc31_allocateheap.c index 348285cf0c..83ce8b65d5 100644 --- a/arch/arm/src/lpc31xx/lpc31_allocateheap.c +++ b/arch/arm/src/lpc31xx/lpc31_allocateheap.c @@ -124,7 +124,7 @@ #if CONFIG_MM_REGIONS != LPC31_NEXT_REGIONS # if CONFIG_MM_REGIONS < LPC31_NEXT_REGIONS -# error "CONFIG_MM_REGIONS is large enough for the selected memory regions" +# error "CONFIG_MM_REGIONS is not large enough for the selected memory regions" # else # error "CONFIG_MM_REGIONS is too large for the selected memory regions" # endif diff --git a/arch/arm/src/stm32f7/stm32_allocateheap.c b/arch/arm/src/stm32f7/stm32_allocateheap.c index 92749a054c..913946183d 100644 --- a/arch/arm/src/stm32f7/stm32_allocateheap.c +++ b/arch/arm/src/stm32f7/stm32_allocateheap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/stm32f7/up_allocateheap.c + * arch/arm/src/stm32f7/stm32_allocateheap.c * * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -383,7 +383,7 @@ void up_addregion(void) { #if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) - /* Allow user-mode access to the STM32F20xxx/STM32F40xxx SRAM2 heap */ + /* Allow user-mode access to the SRAM2 heap */ stm32_mpu_uheap((uintptr_t)SRAM2_START, SRAM2_END-SRAM2_START); @@ -393,7 +393,7 @@ void up_addregion(void) up_heap_color((FAR void *)SRAM2_START, SRAM2_END-SRAM2_START); - /* Add the STM32F20xxx/STM32F40xxx SRAM2 user heap region. */ + /* Add the SRAM2 user heap region. */ kumm_addregion((FAR void *)SRAM2_START, SRAM2_END-SRAM2_START); diff --git a/arch/arm/src/stm32h7/stm32_allocateheap.c b/arch/arm/src/stm32h7/stm32_allocateheap.c index cbc1456d61..d6e87182f0 100644 --- a/arch/arm/src/stm32h7/stm32_allocateheap.c +++ b/arch/arm/src/stm32h7/stm32_allocateheap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/stm32h7/up_allocateheap.c + * arch/arm/src/stm32h7/stm32_allocateheap.c * * Copyright (C) 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/arch/arm/src/stm32l4/Kconfig b/arch/arm/src/stm32l4/Kconfig index 99ec2395c4..c75e3e4770 100644 --- a/arch/arm/src/stm32l4/Kconfig +++ b/arch/arm/src/stm32l4/Kconfig @@ -857,7 +857,7 @@ config STM32L4_IO_CONFIG_A bool default n -comment "STM32L4 SRAM2 Options" +comment "STM32L4 SRAM2 and SRAM3 Options" config STM32L4_SRAM2_HEAP bool "SRAM2 is used for heap" @@ -885,6 +885,15 @@ config STM32L4_SRAM2_INIT case, the board should handle the initialization itself at the appropriate time. +config STM32L4_SRAM3_HEAP + bool "SRAM3 is used for heap" + depends on STM32L4_STM32L4XR + default y + ---help--- + Add the STM32L4 SRAM3 to the heap for use by malloc(). + NOTE: you must also select an appropriate number of memory regions in the + 'Memory Management' section. + comment "STM32L4 Peripherals" menu "STM32L4 Peripheral Support" diff --git a/arch/arm/src/stm32l4/hardware/stm32l4xrxx_rcc.h b/arch/arm/src/stm32l4/hardware/stm32l4xrxx_rcc.h index 49b080c6f1..4a6731051c 100644 --- a/arch/arm/src/stm32l4/hardware/stm32l4xrxx_rcc.h +++ b/arch/arm/src/stm32l4/hardware/stm32l4xrxx_rcc.h @@ -600,6 +600,7 @@ #define RCC_AHB2SMENR_GPIOHSMEN (1 << 7) /* Bit 7: IO port H enable during Sleep mode */ #define RCC_AHB2SMENR_GPIOISMEN (1 << 8) /* Bit 8: IO port I enable during Sleep mode */ #define RCC_AHB2SMENR_SRAM2SMEN (1 << 9) /* Bit 9: SRAM2 enable during Sleep mode */ +#define RCC_AHB2SMENR_SRAM3SMEN (1 << 10) /* Bit 10: SRAM3 enable during Sleep mode */ #define RCC_AHB2SMENR_OTGFSSMEN (1 << 12) /* Bit 12: USB OTG FS module enable during Sleep mode */ #define RCC_AHB2SMENR_ADCSMEN (1 << 13) /* Bit 13: ADC interface enable during Sleep mode (common to all ADCs) */ #define RCC_AHB2SMENR_DCMISMEN (1 << 14) /* Bit 14: DCMI interface enable during Sleep mode */ diff --git a/arch/arm/src/stm32l4/stm32l4_allocateheap.c b/arch/arm/src/stm32l4/stm32l4_allocateheap.c index 2d68bc5ef1..ee64cebd22 100644 --- a/arch/arm/src/stm32l4/stm32l4_allocateheap.c +++ b/arch/arm/src/stm32l4/stm32l4_allocateheap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/stm32l4/up_allocateheap.c + * arch/arm/src/stm32l4/stm32l4_allocateheap.c * * Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -122,30 +122,23 @@ #ifdef STM32L4_SRAM3_SIZE # define SRAM3_START STM32L4_SRAM3_BASE # define SRAM3_END (SRAM3_START + STM32L4_SRAM3_SIZE) -# define CONFIG_STM32L4_SRAM3_HEAP #endif -#if defined(CONFIG_STM32L4_SRAM3_HEAP) -/* TODO: better check here */ -# if CONFIG_MM_REGIONS < 3 -# error you need at least 3 memory manager regions to support SRAM2 and SRAM3 -# endif +/* Some sanity checking. If multiple memory regions are defined, verify + * that CONFIG_MM_REGIONS is set to match the number of memory regions + * that we have been asked to add to the heap. + */ + +#if CONFIG_MM_REGIONS < defined(CONFIG_STM32L4_SRAM2_HEAP) + \ + defined(CONFIG_STM32L4_SRAM3_HEAP) + \ + defined(CONFIG_STM32L4_FSMC_SRAM_HEAP) + 1 +# error "You need more memory manager regions to support selected heap components" #endif -#if defined(CONFIG_STM32L4_SRAM2_HEAP) && defined(CONFIG_STM32L4_FSMC_SRAM_HEAP) -# if CONFIG_MM_REGIONS < 3 -# error you need at least 3 memory manager regions to support SRAM2 and FSMC -# endif -#endif - -#if defined(CONFIG_STM32L4_SRAM2_HEAP) || defined(CONFIG_STM32L4_FSMC_SRAM_HEAP) -# if CONFIG_MM_REGIONS < 2 -# error you need at least 2 memory manager regions to support SRAM2 or FSMC -# endif -#endif - -#if CONFIG_MM_REGIONS < 1 -# warning you have no heap; malloc() will fail. are you sure? +#if CONFIG_MM_REGIONS > defined(CONFIG_STM32L4_SRAM2_HEAP) + \ + defined(CONFIG_STM32L4_SRAM3_HEAP) + \ + defined(CONFIG_STM32L4_FSMC_SRAM_HEAP) + 1 +# warning "CONFIG_MM_REGIONS large enough but I do not know what some of the region(s) are" #endif /* If FSMC SRAM is going to be used as heap, then verify that the starting @@ -259,7 +252,7 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size) /* Allow user-mode access to the user heap memory */ - stm32l4_mpu_uheap((uintptr_t)ubase, usize); + stm32l4_mpu_uheap((uintptr_t)ubase, usize); #else /* Return the heap settings */ diff --git a/arch/arm/src/stm32l4/stm32l4_pmstop.c b/arch/arm/src/stm32l4/stm32l4_pmstop.c index d69ad47bd7..393cf1795d 100644 --- a/arch/arm/src/stm32l4/stm32l4_pmstop.c +++ b/arch/arm/src/stm32l4/stm32l4_pmstop.c @@ -146,9 +146,15 @@ int stm32l4_pmstop2(void) { uint32_t regval; + regval = getreg32(STM32L4_PWR_CR1); +#ifdef CONFIG_STM32L4_SRAM3_HEAP + /* SRAM3 is used as heap, so it must not be powered off in Stop 2 mode. */ + + regval |= PWR_CR1_RRSTP; +#endif + /* Select Stop 2 mode in power control register 1. */ - regval = getreg32(STM32L4_PWR_CR1); regval &= ~PWR_CR1_LPMS_MASK; regval |= PWR_CR1_LPMS_STOP2; putreg32(regval, STM32L4_PWR_CR1); diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index a3da6e678c..d48313df1f 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -330,7 +330,7 @@ static int local_set_policy(FAR struct file *filep, unsigned long policy) ret = file_ioctl(filep, PIPEIOC_POLICY, policy); if (ret < 0) { - nerr("ERROR: Failed to set FIFO buffer policty: %d\n", ret); + nerr("ERROR: Failed to set FIFO buffer policy: %d\n", ret); } return ret; diff --git a/sched/Kconfig b/sched/Kconfig index f9e28d51ad..70a3604a4a 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -489,11 +489,11 @@ config TASK_NAME_SIZE int "Maximum task name size" default 31 ---help--- - Spcifies that maximum size of a task name to save in the TCB. + Specifies the maximum size of a task name to save in the TCB. Useful if scheduler instrumentation is selected. Set to zero to disable. Excludes the NUL terminator; the actual allocated size - willl be TASK_NAME_SIZE + 1. The default of 31 then results in - a align-able 32-byte allocation.:: + will be TASK_NAME_SIZE + 1. The default of 31 then results in + a align-able 32-byte allocation. config MAX_TASKS int "Max number of tasks"