-
Notifications
You must be signed in to change notification settings - Fork 3k
Use SRAM2 32Kbytes on STM32L475 / L476 and L486 devices #6172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0efc876
02b2b01
f551255
815be94
9865744
6795325
28a43b5
d1e6e8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
****************************************************************************** | ||
* @file l4_retarget.c | ||
* @author MCD Application Team | ||
* @brief CMSIS Cortex-M4 Core Peripheral Access Layer Source File for STM32L475xG | ||
****************************************************************************** | ||
* @attention | ||
* | ||
* <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2> | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
****************************************************************************** | ||
*/ | ||
#if (defined(TWO_RAM_REGIONS) && defined(__GNUC__) && !defined(__CC_ARM)) | ||
#include <errno.h> | ||
#include "stm32l4xx.h" | ||
extern uint32_t __mbed_sbrk_start; | ||
extern uint32_t __mbed_krbs_start; | ||
|
||
#define STM32L4_HEAP_ALIGN 32 | ||
#define STM32L4_ALIGN_UP(X, ALIGN) (((X) + (ALIGN) - 1) & ~((ALIGN) - 1)) | ||
/** | ||
* The default implementation of _sbrk() (in platform/mbed_retarget.cpp) for GCC_ARM requires one-region model (heap and | ||
* stack share one region), which doesn't fit two-region model (heap and stack are two distinct regions), for example, | ||
* STM32L475xG locates heap on SRAM1 and stack on SRAM2. | ||
* Define __wrap__sbrk() to override the default _sbrk(). It is expected to get called through gcc | ||
* hooking mechanism ('-Wl,--wrap,_sbrk') or in _sbrk(). | ||
*/ | ||
void *__wrap__sbrk(int incr) | ||
{ | ||
static uint32_t heap_ind = (uint32_t) &__mbed_sbrk_start; | ||
uint32_t heap_ind_old = STM32L4_ALIGN_UP(heap_ind, STM32L4_HEAP_ALIGN); | ||
uint32_t heap_ind_new = STM32L4_ALIGN_UP(heap_ind_old + incr, STM32L4_HEAP_ALIGN); | ||
|
||
if (heap_ind_new > &__mbed_krbs_start) { | ||
errno = ENOMEM; | ||
return (void *) -1; | ||
} | ||
|
||
heap_ind = heap_ind_new; | ||
|
||
return (void *) heap_ind_old; | ||
} | ||
#endif /* GCC_ARM toolchain && TWO_RAM_REGIONS*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,21 @@ | |
|
||
#ifndef INITIAL_SP | ||
|
||
#if (defined(TARGET_STM32F051R8) ||\ | ||
#if (defined(TARGET_STM32L475VG) ||\ | ||
defined(TARGET_STM32L476RG) ||\ | ||
defined(TARGET_STM32L476JG) ||\ | ||
defined(TARGET_STM32L476VG) ||\ | ||
defined(TARGET_STM32L486RG)) | ||
/* only GCC_ARM and IAR toolchains have the stack on SRAM2 */ | ||
#if (((defined(__GNUC__) && !defined(__CC_ARM)) ||\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not for ARMCC? only those 2 toolchains are here supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume will be created as a new PR that will address ARMCC support for this. I would like to avoid having different behavior between toolchains There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will do it . |
||
defined(__IAR_SYSTEMS_ICC__ )) &&\ | ||
defined(TWO_RAM_REGIONS)) | ||
#define INITIAL_SP (0x10008000UL) | ||
#else | ||
#define INITIAL_SP (0x20018000UL) | ||
#endif /* toolchains */ | ||
|
||
#elif (defined(TARGET_STM32F051R8) ||\ | ||
defined(TARGET_STM32F100RB) ||\ | ||
defined(TARGET_STM32L031K6) ||\ | ||
defined(TARGET_STM32L053C8) ||\ | ||
|
@@ -68,12 +82,7 @@ | |
#elif defined(TARGET_STM32L152RE) | ||
#define INITIAL_SP (0x20014000UL) | ||
|
||
#elif (defined(TARGET_STM32F401RE) ||\ | ||
defined(TARGET_STM32L475VG) ||\ | ||
defined(TARGET_STM32L476RG) ||\ | ||
defined(TARGET_STM32L476JG) ||\ | ||
defined(TARGET_STM32L476VG) ||\ | ||
defined(TARGET_STM32L486RG)) | ||
#elif defined(TARGET_STM32F401RE) | ||
#define INITIAL_SP (0x20018000UL) | ||
|
||
#elif (defined(TARGET_STM32F207ZG) ||\ | ||
|
@@ -110,5 +119,15 @@ | |
#endif | ||
|
||
#endif // INITIAL_SP | ||
#if (defined(__GNUC__) && !defined(__CC_ARM) && defined(TWO_RAM_REGIONS)) | ||
extern uint32_t __StackLimit[]; | ||
extern uint32_t __StackTop[]; | ||
extern uint32_t __end__[]; | ||
extern uint32_t __HeapLimit[]; | ||
#define HEAP_START ((unsigned char*)__end__) | ||
#define HEAP_SIZE ((uint32_t)((uint32_t)__HeapLimit - (uint32_t)HEAP_START)) | ||
#define ISR_STACK_START ((unsigned char*)__StackLimit) | ||
#define ISR_STACK_SIZE ((uint32_t)((uint32_t)__StackTop - (uint32_t)__StackLimit)) | ||
#endif | ||
|
||
#endif // MBED_MBED_RTX_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1552,7 +1552,7 @@ | |
} | ||
}, | ||
"detect_code": ["0765"], | ||
"macros_add": ["USBHOST_OTHER"], | ||
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is fine here but instead of macro, if this is a config that would result in MBED_CONF_MULTIPLE_RAM_REGIONS (if there are 3 , would it matter? if yes, then two is fine in the name) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0xc0170 the 'TWO' means that heap and stack are located in 2 separate ram regions. |
||
"device_has_add": ["ANALOGOUT", "CAN", "LOWPOWERTIMER", "SERIAL_ASYNCH", "SERIAL_FC", "TRNG", "FLASH"], | ||
"release_versions": ["2", "5"], | ||
"device_name": "STM32L476RG", | ||
|
@@ -1571,7 +1571,7 @@ | |
} | ||
}, | ||
"detect_code": ["0766"], | ||
"macros_add": ["USBHOST_OTHER"], | ||
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"], | ||
"device_has_add": ["ANALOGOUT", "CAN", "LOWPOWERTIMER", "SERIAL_ASYNCH", "SERIAL_FC", "TRNG", "FLASH"], | ||
"release_versions": ["5"], | ||
"device_name": "STM32L476JG" | ||
|
@@ -1863,7 +1863,7 @@ | |
}, | ||
"supported_form_factors": ["ARDUINO"], | ||
"detect_code": ["0764"], | ||
"macros_add": ["USBHOST_OTHER"], | ||
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"], | ||
"device_has_add": ["ANALOGOUT", "CAN", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"], | ||
"release_versions": ["2", "5"], | ||
"device_name": "STM32L475VG", | ||
|
@@ -1885,7 +1885,7 @@ | |
} | ||
}, | ||
"detect_code": ["0820"], | ||
"macros_add": ["USBHOST_OTHER"], | ||
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"], | ||
"device_has_add": ["ANALOGOUT", "CAN", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"], | ||
"release_versions": ["2", "5"], | ||
"device_name": "STM32L476VG", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaner would be nuvoton would also define two ram regions so we would have just one config and no target here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0xc0170 you are right.
I suggest we create an issue in mbed-os so that NUVOTON can use the same define once this PR is merged. What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, can be done separately, would be nice o t have a tracking issue so we do not forget, thanks