1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +03:00

[Taranis X9E] Variables moved to CCM Memory. Around 45k RAM saved.

This commit is contained in:
bsongis 2015-05-09 08:47:46 +02:00
parent 1086ae85e5
commit 5680f00fd3
15 changed files with 246 additions and 51 deletions

View file

@ -818,7 +818,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO))
CPPSRC += targets/sky9x/bluetooth.cpp
endif
ifeq ($(DEBUG), YES)
SRC += targets/sky9x/syscalls.c
SRC += syscalls.c
endif
endif
@ -880,7 +880,6 @@ ifeq ($(PCB), TARANIS)
ifeq ($(SUPPORT_D16_EU_ONLY), YES)
CPPDEFS += -DMODULE_D16_EU_ONLY_SUPPORT
endif
LDSCRIPT = targets/taranis/stm32_flash_bl.ld
TRGT = arm-none-eabi-
OPT = s
BITMAPS += $(patsubst %.png,%.lbm,$(wildcard bitmaps/Taranis/*.png)) bitmaps/Taranis/mainmenu.lbm
@ -900,11 +899,13 @@ ifeq ($(PCB), TARANIS)
CPPDEFS += -DHSE_VALUE=12000000
ifeq ($(PCBREV), REV9E)
STM32LIBPATH = $(THIRDPARTY)/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries
CPPDEFS += -DSTM32F40_41xxx
CPPDEFS += -DSTM32F4 -DSTM32F40_41xxx
INCDIRS += $(STM32LIBPATH)/CMSIS/Device/ST/STM32F4xx/Include $(STM32LIBPATH)/CMSIS/Include $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/inc
LDSCRIPT = targets/taranis/stm32f4_flash.ld
else
STM32LIBPATH= $(THIRDPARTY)/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries
INCDIRS += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/inc $(STM32LIBPATH)/CMSIS/Device/ST/STM32F2xx/Include $(STM32LIBPATH)/CMSIS/include
LDSCRIPT = targets/taranis/stm32f2_flash.ld
endif
STM32USBPATH = $(THIRDPARTY)/STM32_USB-Host-Device_Lib_V2.1.0/Libraries
INCDIRS += $(STM32USBPATH)/STM32_USB_OTG_Driver/inc $(STM32USBPATH)/STM32_USB_Device_Library/Core/inc
@ -956,7 +957,7 @@ ifeq ($(PCB), TARANIS)
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Core/src/usbd_ioreq.c
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Core/src/usbd_req.c
EXTRABOARDSRC += targets/taranis/usbd_usr.cpp
SRC += targets/sky9x/syscalls.c
SRC += syscalls.c
ifeq ($(USB), JOYSTICK)
CPPDEFS += -DUSB_JOYSTICK
SRC += targets/taranis/usbd_hid_joystick.c

View file

@ -465,10 +465,12 @@ const int16_t alawTable[256] = { -5504, -5248, -6016, -5760, -4480, -4224, -4992
const int16_t ulawTable[256] = { -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412, -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316, -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436, -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, -876, -844, -812, -780, -748, -716, -684, -652, -620, -588, -556, -524, -492, -460, -428, -396, -372, -356, -340, -324, -308, -292, -276, -260, -244, -228, -212, -196, -180, -164, -148, -132, -120, -112, -104, -96, -88, -80, -72, -64, -56, -48, -40, -32, -24, -16, -8, 0, 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, 876, 844, 812, 780, 748, 716, 684, 652, 620, 588, 556, 524, 492, 460, 428, 396, 372, 356, 340, 324, 308, 292, 276, 260, 244, 228, 212, 196, 180, 164, 148, 132, 120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 };
AudioQueue audioQueue;
AudioBuffer audioBuffers[AUDIO_BUFFER_COUNT] _NOCCM;
AudioQueue::AudioQueue()
{
memset(this, 0, sizeof(AudioQueue));
memset(audioBuffers, 0, sizeof(audioBuffers));
}
void AudioQueue::start()
@ -476,7 +478,6 @@ void AudioQueue::start()
state = 1;
}
#define CODEC_ID_PCM_S16LE 1
#define CODEC_ID_PCM_ALAW 6
#define CODEC_ID_PCM_MULAW 7

View file

@ -67,6 +67,8 @@ struct AudioBuffer {
uint8_t state;
};
extern AudioBuffer audioBuffers[AUDIO_BUFFER_COUNT];
enum FragmentTypes {
FRAGMENT_EMPTY,
FRAGMENT_TONE,
@ -197,14 +199,14 @@ class AudioQueue {
inline AudioBuffer * getNextFilledBuffer()
{
if (buffers[bufferRIdx].state == AUDIO_BUFFER_PLAYING) {
buffers[bufferRIdx].state = AUDIO_BUFFER_FREE;
if (audioBuffers[bufferRIdx].state == AUDIO_BUFFER_PLAYING) {
audioBuffers[bufferRIdx].state = AUDIO_BUFFER_FREE;
bufferRIdx = nextBufferIdx(bufferRIdx);
}
uint8_t idx = bufferRIdx;
do {
AudioBuffer * buffer = &buffers[idx];
AudioBuffer * buffer = &audioBuffers[idx];
if (buffer->state == AUDIO_BUFFER_FILLED) {
buffer->state = AUDIO_BUFFER_PLAYING;
bufferRIdx = idx;
@ -219,7 +221,7 @@ class AudioQueue {
bool filledAtleast(int noBuffers) {
int count = 0;
for(int n= 0; n<AUDIO_BUFFER_COUNT; ++n) {
if (buffers[n].state == AUDIO_BUFFER_FILLED) {
if (audioBuffers[n].state == AUDIO_BUFFER_FILLED) {
if (++count >= noBuffers) {
return true;
}
@ -243,7 +245,6 @@ class AudioQueue {
ToneContext priorityContext;
ToneContext varioContext;
AudioBuffer buffers[AUDIO_BUFFER_COUNT];
uint8_t bufferRIdx;
uint8_t bufferWIdx;
@ -254,7 +255,7 @@ class AudioQueue {
inline AudioBuffer * getEmptyBuffer()
{
AudioBuffer * buffer = &buffers[bufferWIdx];
AudioBuffer * buffer = &audioBuffers[bufferWIdx];
if (buffer->state == AUDIO_BUFFER_FREE)
return buffer;
else

View file

@ -38,11 +38,11 @@
#include "../../timers.h"
#if defined(REVPLUS) && defined(LCD_DUAL_BUFFER)
display_t displayBuf1[DISPLAY_BUF_SIZE];
display_t displayBuf2[DISPLAY_BUF_SIZE];
display_t displayBuf1[DISPLAY_BUF_SIZE] _NOCCM;
display_t displayBuf2[DISPLAY_BUF_SIZE] _NOCCM;
display_t * displayBuf = displayBuf1;
#else
display_t displayBuf[DISPLAY_BUF_SIZE];
display_t displayBuf[DISPLAY_BUF_SIZE] _NOCCM;
#endif
void lcd_clear()

View file

@ -212,6 +212,12 @@
#define ROTARY_ENCODER_NAVIGATION
#endif
#if defined(STM32F4)
#define _NOCCM __attribute__((section(".ram")))
#else
#define _NOCCM
#endif
#if defined(SIMU) || defined(CPUARM) || GCC_VERSION < 472
typedef int32_t int24_t;
#else
@ -706,7 +712,8 @@ extern uint8_t flightModeTransitionLast;
extern int _end;
extern int _estack;
extern int _main_stack_start;
#define getAvailableMemory() ((unsigned int)((unsigned char *)&_main_stack_start - heap))
extern int _heap_end;
#define getAvailableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap))
#endif
void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms);

View file

@ -41,8 +41,8 @@ uint8_t s_current_protocol[NUM_MODULES] = { MODULES_INIT(255) };
uint16_t failsafeCounter[NUM_MODULES] = { MODULES_INIT(100) };
uint8_t moduleFlag[NUM_MODULES] = { 0 };
ModulePulsesData modulePulsesData[NUM_MODULES];
TrainerPulsesData trainerPulsesData;
ModulePulsesData modulePulsesData[NUM_MODULES] _NOCCM;
TrainerPulsesData trainerPulsesData _NOCCM;
void setupPulses(unsigned int port)
{

View file

@ -54,7 +54,7 @@
#undef errno
extern int errno;
extern int _end;
extern int _main_stack_start;
extern int _heap_end;
/*----------------------------------------------------------------------------
* Exported functions
@ -66,7 +66,7 @@ extern int _getpid ( void ) ;
unsigned char *heap = (unsigned char *)&_end;
extern caddr_t _sbrk(int nbytes)
{
if (heap + nbytes < (unsigned char *)&_main_stack_start) {
if (heap + nbytes < (unsigned char *)&_heap_end) {
unsigned char *prev_heap = heap;
heap += nbytes;
return (caddr_t) prev_heap;

View file

@ -66,7 +66,7 @@
#define NUMBER_ANALOG_ADC1 10
#endif
uint16_t Analog_values[NUMBER_ANALOG];
uint16_t Analog_values[NUMBER_ANALOG] _NOCCM;
void adcInit()
{

View file

@ -91,7 +91,7 @@ STM32USBPATH = ../../../thirdparty/STM32_USB-Host-Device_Lib_V2.1.0/Libraries
#
ifeq ($(PCB), TARANIS)
ARCH = ARM
LDSCRIPT = ../stm32_ramBoot.ld
LDSCRIPT = ../stm32_ramboot.ld
TRGT = arm-none-eabi-
CPPDEFS += -DHSE_VALUE=12000000
CPPDEFS += -DPCBTARANIS -DEEPROM_RLC

View file

@ -230,6 +230,11 @@ void release_spi (void)
}
#ifdef SD_USE_DMA
#if defined(STM32F4)
WORD rw_workbyte[1] _NOCCM;
#endif
/*-----------------------------------------------------------------------*/
/* Transmit/Receive Block using DMA (Platform dependent. STM32 here) */
/*-----------------------------------------------------------------------*/
@ -243,7 +248,11 @@ void stm32_dma_transfer(
)
{
DMA_InitTypeDef DMA_InitStructure;
WORD dummy[] = { 0xffff };
#if defined(STM32F4)
rw_workbyte[0] = 0xffff;
#else
WORD rw_workbyte[] = { 0xffff };
#endif
DMA_DeInit(SD_DMA_Stream_SPI_RX);
DMA_DeInit(SD_DMA_Stream_SPI_TX);
@ -258,10 +267,10 @@ void stm32_dma_transfer(
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode =DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold =DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst =DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst =DMA_PeripheralBurst_Single;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
// separate RX & TX
if (receive) {
@ -269,14 +278,14 @@ void stm32_dma_transfer(
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_Init(SD_DMA_Stream_SPI_RX, &DMA_InitStructure);
DMA_InitStructure.DMA_Memory0BaseAddr = (DWORD)dummy;
DMA_InitStructure.DMA_Memory0BaseAddr = (DWORD)rw_workbyte;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_Init(SD_DMA_Stream_SPI_TX, &DMA_InitStructure);
}
else {
#if _FS_READONLY == 0
DMA_InitStructure.DMA_Memory0BaseAddr = (DWORD)dummy;
DMA_InitStructure.DMA_Memory0BaseAddr = (DWORD)rw_workbyte;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_Init(SD_DMA_Stream_SPI_RX, &DMA_InitStructure);
@ -399,6 +408,10 @@ void power_off (void)
/* Receive a data packet from MMC */
/*-----------------------------------------------------------------------*/
#if defined(SD_USE_DMA) && defined(STM32F4)
uint8_t sd_buff[512] _NOCCM;
#endif
static
BOOL rcvr_datablock (
BYTE *buff, /* Data buffer to store received data */
@ -418,8 +431,11 @@ BOOL rcvr_datablock (
return FALSE; /* If not valid data token, return with error */
}
#ifdef SD_USE_DMA
stm32_dma_transfer( TRUE, buff, btr );
#if defined(SD_USE_DMA) && defined(STM32F4)
stm32_dma_transfer(TRUE, sd_buff, btr);
memcpy(buff, sd_buff, btr);
#elif defined(SD_USE_DMA)
stm32_dma_transfer(TRUE, buff, btr);
#else
do { /* Receive the data block into buffer */
rcvr_spi_m(buff++);
@ -463,8 +479,11 @@ BOOL xmit_datablock (
xmit_spi(token); /* transmit data token */
if (token != 0xFD) { /* Is data token */
#ifdef SD_USE_DMA
stm32_dma_transfer( FALSE, buff, 512 );
#if defined(SD_USE_DMA) && defined(STM32F4)
memcpy(sd_buff, buff, 512);
stm32_dma_transfer(FALSE, sd_buff, 512);
#elif defined(SD_USE_DMA)
stm32_dma_transfer(FALSE, buff, 512);
#else
wc = 0;
do { /* transmit the 512 byte data block to MMC */

View file

@ -54,7 +54,6 @@ void initLcdSpi()
configure_pins( LCD_GPIO_PIN_A0, PIN_OUTPUT | PIN_PORTC | PIN_OS50) ;
configure_pins( LCD_GPIO_PIN_MOSI|LCD_GPIO_PIN_CLK, PIN_PORTC | PIN_OS50 | PIN_PER_6 | PIN_PERIPHERAL ) ;
// NVIC_SetPriority( DMA1_Stream7_IRQn, 8 ) ;
NVIC_EnableIRQ(DMA1_Stream7_IRQn) ;
DMA1->HIFCR |= DMA_HIFCR_CTCIF7; //clear interrupt flag
@ -69,7 +68,6 @@ void initLcdSpi()
DMA1_Stream7->NDTR = LCD_W*LCD_H/8*4 ;
}
static void LCD_Init()
{
WriteCommand(0x2F); //Internal pump control

View file

@ -26,7 +26,7 @@ _estack = 0x20020000; /* end of 128K SRAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
/*Main stack end*/
/* Main stack end */
_main_stack_start = _estack - _Main_Stack_Size;
/* Specify the memory areas */

View file

@ -1,7 +1,7 @@
/*
*****************************************************************************
**
** File : stm32_flash.ld
** File : stm32f2_flash.ld
**
** Abstract : Linker script for STM32F205 Device with
** 0.5MByte FLASH, 128KByte SRAM
@ -13,19 +13,6 @@
**
** Target : STMicroelectronics STM32
**
** Environment : Atollic TrueSTUDIO(R)
**
** Distribution: The file is distributed <20>as is,<2C> without any warranty
** of any kind.
**
** (c)Copyright Atollic AB.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the Atollic TrueSTUDIO(R) toolchain.
**
*****************************************************************************
*/
@ -39,8 +26,9 @@ _estack = 0x20020000; /* end of 128K SRAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
/*Main stack end*/
/* Main stack end */
_main_stack_start = _estack - _Main_Stack_Size;
_heap_end = _main_stack_start;
/* Specify the memory areas */
MEMORY

View file

@ -0,0 +1,180 @@
/*
*****************************************************************************
**
** File : stm32f4_flash.ld
**
** Abstract : Linker script for STM32F407 Device with
** 0.5MByte FLASH, 128KByte SRAM, 64KByte CCM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x10010000; /* end of 64K CCM */
_heap_end = 0x20020000; /* end of 128K SRAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
/* Main stack end */
_main_stack_start = _estack - _Main_Stack_Size;
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
CCM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
/* The program code and other data goes into FLASH */
.text :
{
FILL(0xFFFF)
CREATE_OBJECT_SYMBOLS
KEEP(*(.isr_boot_vector)) /* Startup code */
*(.bootrodata)
*(.bootrodata.*)
. = 32768; /* Set the start of the main program */
_stext = .; /* Provide the name for the start of this section */
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array*))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = .;
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT ( _sidata )
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >CCM
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
/* __bss_start__ = _sbss; */
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
/* __bss_end__ = _ebss; */
} >CCM
/* collect all uninitialized .ccm sections */
.ram (NOLOAD) :
{
. = ALIGN(4);
_sram = .;
/* __ccm_start__ = _sccm; */
*(.ram)
. = ALIGN(4);
_eram = .;
/* __ccm_end__ = _eccm; */
} >RAM
PROVIDE ( end = _eram );
PROVIDE ( _end = _eram );
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
. = . + _Min_Heap_Size;
. = . + _Main_Stack_Size;
. = ALIGN(4);
} >RAM
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}