forked from xuos/xiuos
Add extern sram support on stm32f407zgt6 for XiUOS
it is perfect
This commit is contained in:
commit
92301257f3
|
@ -91,10 +91,6 @@ void SystemInit(void)
|
||||||
RCC->CR &= (uint32_t)0xFFFBFFFF;
|
RCC->CR &= (uint32_t)0xFFFBFFFF;
|
||||||
RCC->CIR = 0x00000000;
|
RCC->CIR = 0x00000000;
|
||||||
|
|
||||||
#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
|
|
||||||
SystemInitExtMemCtl();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VECT_TAB_SRAM
|
#ifdef VECT_TAB_SRAM
|
||||||
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET;
|
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -47,6 +47,7 @@ extern int Stm32HwRtcInit();
|
||||||
extern int Stm32HwTouchBusInit(void);
|
extern int Stm32HwTouchBusInit(void);
|
||||||
extern int Stm32HwCanBusInit(void);
|
extern int Stm32HwCanBusInit(void);
|
||||||
extern int HwSdioInit();
|
extern int HwSdioInit();
|
||||||
|
extern int HwSramInit(void);
|
||||||
|
|
||||||
static void ClockConfiguration()
|
static void ClockConfiguration()
|
||||||
{
|
{
|
||||||
|
@ -142,6 +143,9 @@ struct InitSequenceDesc _board_init[] =
|
||||||
#endif
|
#endif
|
||||||
#ifdef BSP_USING_SDIO
|
#ifdef BSP_USING_SDIO
|
||||||
{"hw sdcard init",HwSdioInit},
|
{"hw sdcard init",HwSdioInit},
|
||||||
|
#endif
|
||||||
|
#ifdef BSP_USING_EXTMEM
|
||||||
|
{ "hw extern sram", HwSramInit },
|
||||||
#endif
|
#endif
|
||||||
{ " NONE ",NONE },
|
{ " NONE ",NONE },
|
||||||
};
|
};
|
||||||
|
@ -155,16 +159,18 @@ void InitBoardHardware()
|
||||||
NVIC_Configuration();
|
NVIC_Configuration();
|
||||||
|
|
||||||
SysTickConfiguration();
|
SysTickConfiguration();
|
||||||
|
InitBoardMemory((void*)MEMORY_START_ADDRESS, (void*)MEMORY_END_ADDRESS);
|
||||||
|
|
||||||
#ifdef BSP_USING_UART
|
#ifdef BSP_USING_UART
|
||||||
Stm32HwUsartInit();
|
Stm32HwUsartInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef KERNEL_CONSOLE
|
#ifdef KERNEL_CONSOLE
|
||||||
InstallConsole(KERNEL_CONSOLE_BUS_NAME, KERNEL_CONSOLE_DRV_NAME, KERNEL_CONSOLE_DEVICE_NAME);
|
InstallConsole(KERNEL_CONSOLE_BUS_NAME, KERNEL_CONSOLE_DRV_NAME, KERNEL_CONSOLE_DEVICE_NAME);
|
||||||
KPrintf("\nconsole init completed.\n");
|
KPrintf("\nconsole init completed.\n");
|
||||||
|
|
||||||
KPrintf("board initialization......\n");
|
KPrintf("board initialization......\n");
|
||||||
#endif
|
#endif
|
||||||
InitBoardMemory((void*)MEMORY_START_ADDRESS, (void*)MEMORY_END_ADDRESS);
|
|
||||||
|
|
||||||
#ifdef SEPARATE_COMPILE
|
#ifdef SEPARATE_COMPILE
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ endif
|
||||||
menuconfig BSP_USING_EXTMEM
|
menuconfig BSP_USING_EXTMEM
|
||||||
bool "Using EXTMEM device"
|
bool "Using EXTMEM device"
|
||||||
default n
|
default n
|
||||||
|
select MEM_EXTERN_SRAM
|
||||||
if BSP_USING_EXTMEM
|
if BSP_USING_EXTMEM
|
||||||
source "$BSP_DIR/third_party_driver/extmem/Kconfig"
|
source "$BSP_DIR/third_party_driver/extmem/Kconfig"
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
if BSP_USING_EXTMEM
|
||||||
|
config EXTSRAM_MAX_NUM
|
||||||
|
int
|
||||||
|
default 4
|
||||||
|
|
||||||
|
config BSP_USING_FSMC_BANK1_NORSRAM3
|
||||||
|
bool "config fsmc bank1 sram3"
|
||||||
|
default n
|
||||||
|
if BSP_USING_FSMC_BANK1_NORSRAM3
|
||||||
|
config BANK1_NORSRAM3_SIZE
|
||||||
|
hex "config sram3 chip size"
|
||||||
|
default 0x100000
|
||||||
|
config BANK1_NORSRAM3_DATA_WIDTH
|
||||||
|
int "config sram3 chip data width"
|
||||||
|
default 16
|
||||||
|
endif
|
||||||
|
endif
|
|
@ -1,3 +1,3 @@
|
||||||
SRC_FILES := extmem.c
|
SRC_FILES := hardware_fsmc.c connect_fsmc.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -0,0 +1,162 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file connect_fsmc.c
|
||||||
|
* @brief support extern memory by fsmc
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2021-05-28
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "connect_fsmc.h"
|
||||||
|
#include "hardware_fsmc.h"
|
||||||
|
#include "hardware_gpio.h"
|
||||||
|
#include "hardware_rcc.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <xs_base.h>
|
||||||
|
|
||||||
|
#define FSMC_BANK1_NORSRAM3_START_ADDRESS 0x68000000
|
||||||
|
|
||||||
|
static FSMC_NORSRAMInitTypeDef hsram3;
|
||||||
|
static FSMC_NORSRAMTimingInitTypeDef hsram_read3;
|
||||||
|
static FSMC_NORSRAMTimingInitTypeDef hsram_write3;
|
||||||
|
|
||||||
|
extern void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint8 extsram_idx);
|
||||||
|
|
||||||
|
int HwSramInit(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
|
||||||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG, ENABLE);
|
||||||
|
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_10 | GPIO_Pin_12;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource11,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource13,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource0,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource1,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource2,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource3,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource4,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource5,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource13,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource14,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource15,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource0,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource1,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource2,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource3,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource4,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource5,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource10,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
hsram3.FSMC_ReadWriteTimingStruct = &hsram_read3;
|
||||||
|
hsram3.FSMC_WriteTimingStruct = &hsram_write3;
|
||||||
|
|
||||||
|
/* hsram3.Init */
|
||||||
|
hsram3.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
||||||
|
hsram3.FSMC_MemoryType = FSMC_MemoryType_SRAM;
|
||||||
|
hsram3.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
||||||
|
hsram3.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
||||||
|
hsram3.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
||||||
|
hsram3.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
||||||
|
hsram3.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
||||||
|
hsram3.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
||||||
|
hsram3.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
||||||
|
hsram3.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
||||||
|
|
||||||
|
hsram_read3.FSMC_AddressSetupTime = 0;
|
||||||
|
hsram_read3.FSMC_AddressHoldTime = 0;
|
||||||
|
hsram_read3.FSMC_DataSetupTime = 8;
|
||||||
|
hsram_read3.FSMC_BusTurnAroundDuration = 0;
|
||||||
|
hsram_read3.FSMC_CLKDivision = 0;
|
||||||
|
hsram_read3.FSMC_DataLatency = 0;
|
||||||
|
hsram_read3.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||||
|
|
||||||
|
hsram_write3.FSMC_AddressSetupTime = 0;
|
||||||
|
hsram_write3.FSMC_AddressHoldTime = 0;
|
||||||
|
hsram_write3.FSMC_DataSetupTime = 8;
|
||||||
|
hsram_write3.FSMC_BusTurnAroundDuration = 0;
|
||||||
|
hsram_write3.FSMC_CLKDivision = 0;
|
||||||
|
hsram_write3.FSMC_DataLatency = 0;
|
||||||
|
hsram_write3.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||||
|
|
||||||
|
#ifdef BSP_USING_FSMC_BANK1_NORSRAM3
|
||||||
|
hsram3.FSMC_Bank = FSMC_Bank1_NORSRAM3;
|
||||||
|
#if BANK1_NORSRAM3_DATA_WIDTH == 8
|
||||||
|
hsram3.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
|
||||||
|
#elif BANK1_NORSRAM3_DATA_WIDTH == 16
|
||||||
|
hsram3.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
||||||
|
#else
|
||||||
|
hsram3.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_32b;
|
||||||
|
#endif
|
||||||
|
FSMC_NORSRAMInit(&hsram3);
|
||||||
|
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
|
||||||
|
|
||||||
|
ExtSramInitBoardMemory((void*)(FSMC_BANK1_NORSRAM3_START_ADDRESS), (void*)((FSMC_BANK1_NORSRAM3_START_ADDRESS + BANK1_NORSRAM3_SIZE)), 2);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,336 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 AIIT XUOS Lab
|
|
||||||
* XiUOS is licensed under Mulan PSL v2.
|
|
||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
||||||
* You may obtain a copy of Mulan PSL v2 at:
|
|
||||||
* http://license.coscl.org.cn/MulanPSL2
|
|
||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
||||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the Mulan PSL v2 for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file extmem.c
|
|
||||||
* @brief support extmem function
|
|
||||||
* @version 1.0
|
|
||||||
* @author AIIT XUOS Lab
|
|
||||||
* @date 2021-04-25
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <extmem.h>
|
|
||||||
#include <stm32f4xx.h>
|
|
||||||
|
|
||||||
#if defined (DATA_IN_ExtSRAM) && defined (DATA_IN_ExtSDRAM)
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
void SystemInitExtMemCtl(void)
|
|
||||||
{
|
|
||||||
__IO uint32_t tmp = 0x00;
|
|
||||||
|
|
||||||
register uint32_t tmpreg = 0, timeout = 0xFFFF;
|
|
||||||
register __IO uint32_t index;
|
|
||||||
|
|
||||||
RCC->AHB1ENR |= 0x000001F8;
|
|
||||||
|
|
||||||
tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
|
|
||||||
|
|
||||||
GPIOD->AFR[0] = 0x00CCC0CC;
|
|
||||||
GPIOD->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOD->MODER = 0xAAAA0A8A;
|
|
||||||
GPIOD->OSPEEDR = 0xFFFF0FCF;
|
|
||||||
GPIOD->OTYPER = 0x00000000;
|
|
||||||
GPIOD->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOE->AFR[0] = 0xC00CC0CC;
|
|
||||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOE->MODER = 0xAAAA828A;
|
|
||||||
GPIOE->OSPEEDR = 0xFFFFC3CF;
|
|
||||||
GPIOE->OTYPER = 0x00000000;
|
|
||||||
GPIOE->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOF->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOF->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOF->MODER = 0xAA800AAA;
|
|
||||||
GPIOF->OSPEEDR = 0xAA800AAA;
|
|
||||||
GPIOF->OTYPER = 0x00000000;
|
|
||||||
GPIOF->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOG->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOG->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOG->MODER = 0xAAAAAAAA;
|
|
||||||
GPIOG->OSPEEDR = 0xAAAAAAAA;
|
|
||||||
GPIOG->OTYPER = 0x00000000;
|
|
||||||
GPIOG->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOH->AFR[0] = 0x00C0CC00;
|
|
||||||
GPIOH->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOH->MODER = 0xAAAA08A0;
|
|
||||||
GPIOH->OSPEEDR = 0xAAAA08A0;
|
|
||||||
GPIOH->OTYPER = 0x00000000;
|
|
||||||
GPIOH->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOI->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOI->AFR[1] = 0x00000CC0;
|
|
||||||
GPIOI->MODER = 0x0028AAAA;
|
|
||||||
GPIOI->OSPEEDR = 0x0028AAAA;
|
|
||||||
GPIOI->OTYPER = 0x00000000;
|
|
||||||
GPIOI->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCR[0] = 0x000019E4;
|
|
||||||
FMC_Bank5_6->SDTR[0] = 0x01115351;
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000011;
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index = 0; index<1000; index++);
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000012;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000073;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00046014;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDRTR;
|
|
||||||
FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1));
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDCR[0];
|
|
||||||
FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
|
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001011;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00000201;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
#if defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001091;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00110212;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
(void)(tmp);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#elif defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
|
|
||||||
void SystemInitExtMemCtl(void)
|
|
||||||
{
|
|
||||||
__IO uint32_t tmp = 0x00;
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
#if defined (DATA_IN_ExtSDRAM)
|
|
||||||
register uint32_t tmpreg = 0, timeout = 0xFFFF;
|
|
||||||
register __IO uint32_t index;
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
RCC->AHB1ENR |= 0x0000007D;
|
|
||||||
#else
|
|
||||||
RCC->AHB1ENR |= 0x000001F8;
|
|
||||||
#endif
|
|
||||||
tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
GPIOA->AFR[0] |= 0xC0000000;
|
|
||||||
GPIOA->AFR[1] |= 0x00000000;
|
|
||||||
GPIOA->MODER |= 0x00008000;
|
|
||||||
GPIOA->OSPEEDR |= 0x00008000;
|
|
||||||
GPIOA->OTYPER |= 0x00000000;
|
|
||||||
GPIOA->PUPDR |= 0x00000000;
|
|
||||||
|
|
||||||
GPIOC->AFR[0] |= 0x00CC0000;
|
|
||||||
GPIOC->AFR[1] |= 0x00000000;
|
|
||||||
GPIOC->MODER |= 0x00000A00;
|
|
||||||
GPIOC->OSPEEDR |= 0x00000A00;
|
|
||||||
GPIOC->OTYPER |= 0x00000000;
|
|
||||||
GPIOC->PUPDR |= 0x00000000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GPIOD->AFR[0] = 0x000000CC;
|
|
||||||
GPIOD->AFR[1] = 0xCC000CCC;
|
|
||||||
GPIOD->MODER = 0xA02A000A;
|
|
||||||
GPIOD->OSPEEDR = 0xA02A000A;
|
|
||||||
GPIOD->OTYPER = 0x00000000;
|
|
||||||
GPIOD->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOE->AFR[0] = 0xC00000CC;
|
|
||||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOE->MODER = 0xAAAA800A;
|
|
||||||
GPIOE->OSPEEDR = 0xAAAA800A;
|
|
||||||
GPIOE->OTYPER = 0x00000000;
|
|
||||||
GPIOE->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOF->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOF->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOF->MODER = 0xAA800AAA;
|
|
||||||
GPIOF->OSPEEDR = 0xAA800AAA;
|
|
||||||
GPIOF->OTYPER = 0x00000000;
|
|
||||||
GPIOF->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOG->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOG->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOG->MODER = 0xAAAAAAAA;
|
|
||||||
GPIOG->OSPEEDR = 0xAAAAAAAA;
|
|
||||||
GPIOG->OTYPER = 0x00000000;
|
|
||||||
GPIOG->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
GPIOH->AFR[0] = 0x00C0CC00;
|
|
||||||
GPIOH->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOH->MODER = 0xAAAA08A0;
|
|
||||||
GPIOH->OSPEEDR = 0xAAAA08A0;
|
|
||||||
GPIOH->OTYPER = 0x00000000;
|
|
||||||
GPIOH->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOI->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOI->AFR[1] = 0x00000CC0;
|
|
||||||
GPIOI->MODER = 0x0028AAAA;
|
|
||||||
GPIOI->OSPEEDR = 0x0028AAAA;
|
|
||||||
GPIOI->OTYPER = 0x00000000;
|
|
||||||
GPIOI->PUPDR = 0x00000000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDCR[0] = 0x00001954;
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDCR[0] = 0x000019E4;
|
|
||||||
#endif
|
|
||||||
FMC_Bank5_6->SDTR[0] = 0x01115351;
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000011;
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index = 0; index<1000; index++);
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000012;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDCMR = 0x000000F3;
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000073;
|
|
||||||
#endif
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00044014;
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00046014;
|
|
||||||
#endif
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDRTR;
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDRTR = (tmpreg | (0x0000050C<<1));
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDCR[0];
|
|
||||||
FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\
|
|
||||||
|| defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx)
|
|
||||||
|
|
||||||
#if defined(DATA_IN_ExtSRAM)
|
|
||||||
RCC->AHB1ENR |= 0x00000078;
|
|
||||||
tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN);
|
|
||||||
|
|
||||||
GPIOD->AFR[0] = 0x00CCC0CC;
|
|
||||||
GPIOD->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOD->MODER = 0xAAAA0A8A;
|
|
||||||
GPIOD->OSPEEDR = 0xFFFF0FCF;
|
|
||||||
GPIOD->OTYPER = 0x00000000;
|
|
||||||
GPIOD->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOE->AFR[0] = 0xC00CC0CC;
|
|
||||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOE->MODER = 0xAAAA828A;
|
|
||||||
GPIOE->OSPEEDR = 0xFFFFC3CF;
|
|
||||||
GPIOE->OTYPER = 0x00000000;
|
|
||||||
GPIOE->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOF->AFR[0] = 0x00CCCCCC;
|
|
||||||
GPIOF->AFR[1] = 0xCCCC0000;
|
|
||||||
GPIOF->MODER = 0xAA000AAA;
|
|
||||||
GPIOF->OSPEEDR = 0xFF000FFF;
|
|
||||||
GPIOF->OTYPER = 0x00000000;
|
|
||||||
GPIOF->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOG->AFR[0] = 0x00CCCCCC;
|
|
||||||
GPIOG->AFR[1] = 0x000000C0;
|
|
||||||
GPIOG->MODER = 0x00085AAA;
|
|
||||||
GPIOG->OSPEEDR = 0x000CAFFF;
|
|
||||||
GPIOG->OTYPER = 0x00000000;
|
|
||||||
GPIOG->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001011;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00000201;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
#if defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001091;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00110212;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx)\
|
|
||||||
|| defined(STM32F412Zx) || defined(STM32F412Vx)
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FSMCEN);
|
|
||||||
FSMC_Bank1->BTCR[2] = 0x00001011;
|
|
||||||
FSMC_Bank1->BTCR[3] = 0x00000201;
|
|
||||||
FSMC_Bank1E->BWTR[2] = 0x0FFFFFFF;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
(void)(tmp);
|
|
||||||
}
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
|
@ -11,18 +11,26 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file extmem.h
|
* @file connect_fsmc.h
|
||||||
* @brief support extmem function
|
* @brief declare stm32f407zgt6-board fsmc function
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2021-04-25
|
* @date 2021-05-28
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EXTMEM_H
|
#ifndef CONNECT_FSMC_H
|
||||||
#define EXTMEM_H
|
#define CONNECT_FSMC_H
|
||||||
|
|
||||||
#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
|
#include <xsconfig.h>
|
||||||
void SystemInitExtMemCtl(void);
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int HwSramInit(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -334,6 +334,7 @@ typedef struct
|
||||||
|
|
||||||
#define FSMC_MemoryDataWidth_8b ((uint32_t)0x00000000)
|
#define FSMC_MemoryDataWidth_8b ((uint32_t)0x00000000)
|
||||||
#define FSMC_MemoryDataWidth_16b ((uint32_t)0x00000010)
|
#define FSMC_MemoryDataWidth_16b ((uint32_t)0x00000010)
|
||||||
|
#define FSMC_MemoryDataWidth_32b ((uint32_t)0x00000020)
|
||||||
#define IS_FSMC_MEMORY_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
|
#define IS_FSMC_MEMORY_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
|
||||||
((WIDTH) == FSMC_MemoryDataWidth_16b))
|
((WIDTH) == FSMC_MemoryDataWidth_16b))
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,13 +13,6 @@ if BSP_USING_DMA
|
||||||
source "$BSP_DIR/third_party_driver/common/Kconfig"
|
source "$BSP_DIR/third_party_driver/common/Kconfig"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
menuconfig BSP_USING_EXTMEM
|
|
||||||
bool "Using EXTMEM device"
|
|
||||||
default n
|
|
||||||
if BSP_USING_EXTMEM
|
|
||||||
source "$BSP_DIR/third_party_driver/extmem/Kconfig"
|
|
||||||
endif
|
|
||||||
|
|
||||||
menuconfig BSP_USING_GPIO
|
menuconfig BSP_USING_GPIO
|
||||||
bool "Using GPIO device "
|
bool "Using GPIO device "
|
||||||
default y
|
default y
|
||||||
|
|
|
@ -5,11 +5,6 @@ ifeq ($(CONFIG_BSP_USING_CAN),y)
|
||||||
SRC_DIR += can
|
SRC_DIR += can
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_BSP_USING_EXTMEM),y)
|
|
||||||
SRC_DIR += extmem
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_BSP_USING_GPIO),y)
|
ifeq ($(CONFIG_BSP_USING_GPIO),y)
|
||||||
SRC_DIR += gpio
|
SRC_DIR += gpio
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
SRC_FILES := extmem.c
|
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
|
|
@ -1,336 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 AIIT XUOS Lab
|
|
||||||
* XiUOS is licensed under Mulan PSL v2.
|
|
||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
||||||
* You may obtain a copy of Mulan PSL v2 at:
|
|
||||||
* http://license.coscl.org.cn/MulanPSL2
|
|
||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
||||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the Mulan PSL v2 for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file extmem.c
|
|
||||||
* @brief support extmem function
|
|
||||||
* @version 1.0
|
|
||||||
* @author AIIT XUOS Lab
|
|
||||||
* @date 2021-04-25
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "stm32f4xx.h"
|
|
||||||
#include "extmem.h"
|
|
||||||
|
|
||||||
#if defined (DATA_IN_ExtSRAM) && defined (DATA_IN_ExtSDRAM)
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
void SystemInitExtMemCtl(void)
|
|
||||||
{
|
|
||||||
__IO uint32_t tmp = 0x00;
|
|
||||||
|
|
||||||
register uint32_t tmpreg = 0, timeout = 0xFFFF;
|
|
||||||
register __IO uint32_t index;
|
|
||||||
|
|
||||||
RCC->AHB1ENR |= 0x000001F8;
|
|
||||||
|
|
||||||
tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
|
|
||||||
|
|
||||||
GPIOD->AFR[0] = 0x00CCC0CC;
|
|
||||||
GPIOD->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOD->MODER = 0xAAAA0A8A;
|
|
||||||
GPIOD->OSPEEDR = 0xFFFF0FCF;
|
|
||||||
GPIOD->OTYPER = 0x00000000;
|
|
||||||
GPIOD->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOE->AFR[0] = 0xC00CC0CC;
|
|
||||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOE->MODER = 0xAAAA828A;
|
|
||||||
GPIOE->OSPEEDR = 0xFFFFC3CF;
|
|
||||||
GPIOE->OTYPER = 0x00000000;
|
|
||||||
GPIOE->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOF->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOF->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOF->MODER = 0xAA800AAA;
|
|
||||||
GPIOF->OSPEEDR = 0xAA800AAA;
|
|
||||||
GPIOF->OTYPER = 0x00000000;
|
|
||||||
GPIOF->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOG->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOG->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOG->MODER = 0xAAAAAAAA;
|
|
||||||
GPIOG->OSPEEDR = 0xAAAAAAAA;
|
|
||||||
GPIOG->OTYPER = 0x00000000;
|
|
||||||
GPIOG->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOH->AFR[0] = 0x00C0CC00;
|
|
||||||
GPIOH->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOH->MODER = 0xAAAA08A0;
|
|
||||||
GPIOH->OSPEEDR = 0xAAAA08A0;
|
|
||||||
GPIOH->OTYPER = 0x00000000;
|
|
||||||
GPIOH->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOI->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOI->AFR[1] = 0x00000CC0;
|
|
||||||
GPIOI->MODER = 0x0028AAAA;
|
|
||||||
GPIOI->OSPEEDR = 0x0028AAAA;
|
|
||||||
GPIOI->OTYPER = 0x00000000;
|
|
||||||
GPIOI->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCR[0] = 0x000019E4;
|
|
||||||
FMC_Bank5_6->SDTR[0] = 0x01115351;
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000011;
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index = 0; index<1000; index++);
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000012;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000073;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00046014;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDRTR;
|
|
||||||
FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1));
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDCR[0];
|
|
||||||
FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
|
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001011;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00000201;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
#if defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001091;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00110212;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
(void)(tmp);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#elif defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
|
|
||||||
void SystemInitExtMemCtl(void)
|
|
||||||
{
|
|
||||||
__IO uint32_t tmp = 0x00;
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
#if defined (DATA_IN_ExtSDRAM)
|
|
||||||
register uint32_t tmpreg = 0, timeout = 0xFFFF;
|
|
||||||
register __IO uint32_t index;
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
RCC->AHB1ENR |= 0x0000007D;
|
|
||||||
#else
|
|
||||||
RCC->AHB1ENR |= 0x000001F8;
|
|
||||||
#endif
|
|
||||||
tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
GPIOA->AFR[0] |= 0xC0000000;
|
|
||||||
GPIOA->AFR[1] |= 0x00000000;
|
|
||||||
GPIOA->MODER |= 0x00008000;
|
|
||||||
GPIOA->OSPEEDR |= 0x00008000;
|
|
||||||
GPIOA->OTYPER |= 0x00000000;
|
|
||||||
GPIOA->PUPDR |= 0x00000000;
|
|
||||||
|
|
||||||
GPIOC->AFR[0] |= 0x00CC0000;
|
|
||||||
GPIOC->AFR[1] |= 0x00000000;
|
|
||||||
GPIOC->MODER |= 0x00000A00;
|
|
||||||
GPIOC->OSPEEDR |= 0x00000A00;
|
|
||||||
GPIOC->OTYPER |= 0x00000000;
|
|
||||||
GPIOC->PUPDR |= 0x00000000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GPIOD->AFR[0] = 0x000000CC;
|
|
||||||
GPIOD->AFR[1] = 0xCC000CCC;
|
|
||||||
GPIOD->MODER = 0xA02A000A;
|
|
||||||
GPIOD->OSPEEDR = 0xA02A000A;
|
|
||||||
GPIOD->OTYPER = 0x00000000;
|
|
||||||
GPIOD->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOE->AFR[0] = 0xC00000CC;
|
|
||||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOE->MODER = 0xAAAA800A;
|
|
||||||
GPIOE->OSPEEDR = 0xAAAA800A;
|
|
||||||
GPIOE->OTYPER = 0x00000000;
|
|
||||||
GPIOE->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOF->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOF->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOF->MODER = 0xAA800AAA;
|
|
||||||
GPIOF->OSPEEDR = 0xAA800AAA;
|
|
||||||
GPIOF->OTYPER = 0x00000000;
|
|
||||||
GPIOF->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOG->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOG->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOG->MODER = 0xAAAAAAAA;
|
|
||||||
GPIOG->OSPEEDR = 0xAAAAAAAA;
|
|
||||||
GPIOG->OTYPER = 0x00000000;
|
|
||||||
GPIOG->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
GPIOH->AFR[0] = 0x00C0CC00;
|
|
||||||
GPIOH->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOH->MODER = 0xAAAA08A0;
|
|
||||||
GPIOH->OSPEEDR = 0xAAAA08A0;
|
|
||||||
GPIOH->OTYPER = 0x00000000;
|
|
||||||
GPIOH->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOI->AFR[0] = 0xCCCCCCCC;
|
|
||||||
GPIOI->AFR[1] = 0x00000CC0;
|
|
||||||
GPIOI->MODER = 0x0028AAAA;
|
|
||||||
GPIOI->OSPEEDR = 0x0028AAAA;
|
|
||||||
GPIOI->OTYPER = 0x00000000;
|
|
||||||
GPIOI->PUPDR = 0x00000000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDCR[0] = 0x00001954;
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDCR[0] = 0x000019E4;
|
|
||||||
#endif
|
|
||||||
FMC_Bank5_6->SDTR[0] = 0x01115351;
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000011;
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index = 0; index<1000; index++);
|
|
||||||
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000012;
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDCMR = 0x000000F3;
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00000073;
|
|
||||||
#endif
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00044014;
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDCMR = 0x00046014;
|
|
||||||
#endif
|
|
||||||
timeout = 0xFFFF;
|
|
||||||
while((tmpreg != 0) && (timeout-- > 0))
|
|
||||||
{
|
|
||||||
tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDRTR;
|
|
||||||
#if defined(STM32F446xx)
|
|
||||||
FMC_Bank5_6->SDRTR = (tmpreg | (0x0000050C<<1));
|
|
||||||
#else
|
|
||||||
FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tmpreg = FMC_Bank5_6->SDCR[0];
|
|
||||||
FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\
|
|
||||||
|| defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
|
|
||||||
|| defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx)
|
|
||||||
|
|
||||||
#if defined(DATA_IN_ExtSRAM)
|
|
||||||
RCC->AHB1ENR |= 0x00000078;
|
|
||||||
tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN);
|
|
||||||
|
|
||||||
GPIOD->AFR[0] = 0x00CCC0CC;
|
|
||||||
GPIOD->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOD->MODER = 0xAAAA0A8A;
|
|
||||||
GPIOD->OSPEEDR = 0xFFFF0FCF;
|
|
||||||
GPIOD->OTYPER = 0x00000000;
|
|
||||||
GPIOD->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOE->AFR[0] = 0xC00CC0CC;
|
|
||||||
GPIOE->AFR[1] = 0xCCCCCCCC;
|
|
||||||
GPIOE->MODER = 0xAAAA828A;
|
|
||||||
GPIOE->OSPEEDR = 0xFFFFC3CF;
|
|
||||||
GPIOE->OTYPER = 0x00000000;
|
|
||||||
GPIOE->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOF->AFR[0] = 0x00CCCCCC;
|
|
||||||
GPIOF->AFR[1] = 0xCCCC0000;
|
|
||||||
GPIOF->MODER = 0xAA000AAA;
|
|
||||||
GPIOF->OSPEEDR = 0xFF000FFF;
|
|
||||||
GPIOF->OTYPER = 0x00000000;
|
|
||||||
GPIOF->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
GPIOG->AFR[0] = 0x00CCCCCC;
|
|
||||||
GPIOG->AFR[1] = 0x000000C0;
|
|
||||||
GPIOG->MODER = 0x00085AAA;
|
|
||||||
GPIOG->OSPEEDR = 0x000CAFFF;
|
|
||||||
GPIOG->OTYPER = 0x00000000;
|
|
||||||
GPIOG->PUPDR = 0x00000000;
|
|
||||||
|
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001011;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00000201;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
#if defined(STM32F469xx) || defined(STM32F479xx)
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
|
||||||
FMC_Bank1->BTCR[2] = 0x00001091;
|
|
||||||
FMC_Bank1->BTCR[3] = 0x00110212;
|
|
||||||
FMC_Bank1E->BWTR[2] = 0x0fffffff;
|
|
||||||
#endif
|
|
||||||
#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx)\
|
|
||||||
|| defined(STM32F412Zx) || defined(STM32F412Vx)
|
|
||||||
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FSMCEN);
|
|
||||||
FSMC_Bank1->BTCR[2] = 0x00001011;
|
|
||||||
FSMC_Bank1->BTCR[3] = 0x00000201;
|
|
||||||
FSMC_Bank1E->BWTR[2] = 0x0FFFFFFF;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
(void)(tmp);
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -35,6 +35,7 @@ Modification:
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "connect_usart.h"
|
#include "connect_usart.h"
|
||||||
#include "connect_gpio.h"
|
#include "connect_gpio.h"
|
||||||
|
#include "connect_fsmc.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
extern void entry(void);
|
extern void entry(void);
|
||||||
|
@ -104,6 +105,9 @@ struct InitSequenceDesc _board_init[] =
|
||||||
{
|
{
|
||||||
#ifdef BSP_USING_GPIO
|
#ifdef BSP_USING_GPIO
|
||||||
{ "hw pin", Stm32HwGpioInit },
|
{ "hw pin", Stm32HwGpioInit },
|
||||||
|
#endif
|
||||||
|
#ifdef BSP_USING_EXTMEM
|
||||||
|
{ "hw extern sram", HwSramInit },
|
||||||
#endif
|
#endif
|
||||||
{ " NONE ",NONE },
|
{ " NONE ",NONE },
|
||||||
};
|
};
|
||||||
|
@ -117,6 +121,7 @@ void InitBoardHardware()
|
||||||
NVIC_Configuration();
|
NVIC_Configuration();
|
||||||
|
|
||||||
SysTickConfiguration();
|
SysTickConfiguration();
|
||||||
|
InitBoardMemory((void*)MEMORY_START_ADDRESS, (void*)MEMORY_END_ADDRESS);
|
||||||
#ifdef BSP_USING_UART
|
#ifdef BSP_USING_UART
|
||||||
Stm32HwUsartInit();
|
Stm32HwUsartInit();
|
||||||
#endif
|
#endif
|
||||||
|
@ -125,7 +130,6 @@ void InitBoardHardware()
|
||||||
KPrintf("\nconsole init completed.\n");
|
KPrintf("\nconsole init completed.\n");
|
||||||
KPrintf("board initialization......\n");
|
KPrintf("board initialization......\n");
|
||||||
#endif
|
#endif
|
||||||
InitBoardMemory((void*)MEMORY_START_ADDRESS, (void*)MEMORY_END_ADDRESS);
|
|
||||||
|
|
||||||
#ifdef SEPARATE_COMPILE
|
#ifdef SEPARATE_COMPILE
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,10 @@ if BSP_USING_UART
|
||||||
source "$BSP_DIR/third_party_driver/uart/Kconfig"
|
source "$BSP_DIR/third_party_driver/uart/Kconfig"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
menuconfig BSP_USING_EXTMEM
|
||||||
|
bool "Using extern memory"
|
||||||
|
default n
|
||||||
|
select MEM_EXTERN_SRAM
|
||||||
|
if BSP_USING_EXTMEM
|
||||||
|
source "$BSP_DIR/third_party_driver/extmem/Kconfig"
|
||||||
|
endif
|
||||||
|
|
|
@ -9,5 +9,8 @@ ifeq ($(CONFIG_BSP_USING_UART),y)
|
||||||
SRC_DIR += uart
|
SRC_DIR += uart
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_BSP_USING_EXTMEM),y)
|
||||||
|
SRC_DIR += extmem
|
||||||
|
endif
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
if BSP_USING_EXTMEM
|
||||||
|
config EXTSRAM_MAX_NUM
|
||||||
|
int
|
||||||
|
default 4
|
||||||
|
|
||||||
|
config BSP_USING_FSMC_BANK1_NORSRAM3
|
||||||
|
bool "config fsmc bank1 sram3"
|
||||||
|
default n
|
||||||
|
if BSP_USING_FSMC_BANK1_NORSRAM3
|
||||||
|
config BANK1_NORSRAM3_SIZE
|
||||||
|
hex "config sram3 chip size"
|
||||||
|
default 0x100000
|
||||||
|
config BANK1_NORSRAM3_DATA_WIDTH
|
||||||
|
int "config sram3 chip data width"
|
||||||
|
default 16
|
||||||
|
endif
|
||||||
|
endif
|
|
@ -0,0 +1,3 @@
|
||||||
|
SRC_FILES := hardware_fsmc.c connect_fsmc.c
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,162 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file connect_fsmc.c
|
||||||
|
* @brief support extern memory by fsmc
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2021-05-28
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "connect_fsmc.h"
|
||||||
|
#include "hardware_fsmc.h"
|
||||||
|
#include "hardware_gpio.h"
|
||||||
|
#include "hardware_rcc.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <xs_base.h>
|
||||||
|
|
||||||
|
#define FSMC_BANK1_NORSRAM3_START_ADDRESS 0x68000000
|
||||||
|
|
||||||
|
static FSMC_NORSRAMInitTypeDef hsram3;
|
||||||
|
static FSMC_NORSRAMTimingInitTypeDef hsram_read3;
|
||||||
|
static FSMC_NORSRAMTimingInitTypeDef hsram_write3;
|
||||||
|
|
||||||
|
extern void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint8 extsram_idx);
|
||||||
|
|
||||||
|
int HwSramInit(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
|
||||||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG, ENABLE);
|
||||||
|
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_10 | GPIO_Pin_12;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource11,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource13,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource0,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource1,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource2,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource3,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource4,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource5,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource13,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource14,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOF,GPIO_PinSource15,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource0,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource1,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource2,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource3,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource4,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource5,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource10,GPIO_AF_FSMC);
|
||||||
|
GPIO_PinAFConfig(GPIOG,GPIO_PinSource12,GPIO_AF_FSMC);
|
||||||
|
|
||||||
|
hsram3.FSMC_ReadWriteTimingStruct = &hsram_read3;
|
||||||
|
hsram3.FSMC_WriteTimingStruct = &hsram_write3;
|
||||||
|
|
||||||
|
/* hsram3.Init */
|
||||||
|
hsram3.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
||||||
|
hsram3.FSMC_MemoryType = FSMC_MemoryType_SRAM;
|
||||||
|
hsram3.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
||||||
|
hsram3.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
||||||
|
hsram3.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
||||||
|
hsram3.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
||||||
|
hsram3.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
||||||
|
hsram3.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
||||||
|
hsram3.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
||||||
|
hsram3.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
||||||
|
|
||||||
|
hsram_read3.FSMC_AddressSetupTime = 0;
|
||||||
|
hsram_read3.FSMC_AddressHoldTime = 0;
|
||||||
|
hsram_read3.FSMC_DataSetupTime = 8;
|
||||||
|
hsram_read3.FSMC_BusTurnAroundDuration = 0;
|
||||||
|
hsram_read3.FSMC_CLKDivision = 0;
|
||||||
|
hsram_read3.FSMC_DataLatency = 0;
|
||||||
|
hsram_read3.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||||
|
|
||||||
|
hsram_write3.FSMC_AddressSetupTime = 0;
|
||||||
|
hsram_write3.FSMC_AddressHoldTime = 0;
|
||||||
|
hsram_write3.FSMC_DataSetupTime = 8;
|
||||||
|
hsram_write3.FSMC_BusTurnAroundDuration = 0;
|
||||||
|
hsram_write3.FSMC_CLKDivision = 0;
|
||||||
|
hsram_write3.FSMC_DataLatency = 0;
|
||||||
|
hsram_write3.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||||
|
|
||||||
|
#ifdef BSP_USING_FSMC_BANK1_NORSRAM3
|
||||||
|
hsram3.FSMC_Bank = FSMC_Bank1_NORSRAM3;
|
||||||
|
#if BANK1_NORSRAM3_DATA_WIDTH == 8
|
||||||
|
hsram3.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
|
||||||
|
#elif BANK1_NORSRAM3_DATA_WIDTH == 16
|
||||||
|
hsram3.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
||||||
|
#else
|
||||||
|
hsram3.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_32b;
|
||||||
|
#endif
|
||||||
|
FSMC_NORSRAMInit(&hsram3);
|
||||||
|
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
|
||||||
|
|
||||||
|
ExtSramInitBoardMemory((void*)(FSMC_BANK1_NORSRAM3_START_ADDRESS), (void*)((FSMC_BANK1_NORSRAM3_START_ADDRESS + BANK1_NORSRAM3_SIZE)), 2);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 AIIT XUOS Lab
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
* xiuOS is licensed under Mulan PSL v2.
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
* You may obtain a copy of Mulan PSL v2 at:
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
* http://license.coscl.org.cn/MulanPSL2
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
@ -11,18 +11,26 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file extmem.h
|
* @file connect_fsmc.h
|
||||||
* @brief support extmem function
|
* @brief declare stm32f407zgt6-board fsmc function
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2021-04-25
|
* @date 2021-05-28
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EXTMEM_H
|
#ifndef CONNECT_FSMC_H
|
||||||
#define EXTMEM_H
|
#define CONNECT_FSMC_H
|
||||||
|
|
||||||
#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
|
#include <xsconfig.h>
|
||||||
void SystemInitExtMemCtl(void);
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int HwSramInit(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,689 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file stm32f4xx_fsmc.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @version V1.0.0
|
||||||
|
* @date 30-September-2011
|
||||||
|
* @brief This file contains all the functions prototypes for the FSMC firmware
|
||||||
|
* library.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||||
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||||
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||||
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||||
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||||
|
*
|
||||||
|
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file: hardware_fsmc.h
|
||||||
|
* @brief: define hardware fsmc function
|
||||||
|
* @version: 1.0
|
||||||
|
* @author: AIIT XUOS Lab
|
||||||
|
* @date: 2021/4/25
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*************************************************
|
||||||
|
File name: hardware_fsmc.h
|
||||||
|
Description: define hardware fsmc function
|
||||||
|
Others:
|
||||||
|
History:
|
||||||
|
1. Date: 2021-04-25
|
||||||
|
Author: AIIT XUOS Lab
|
||||||
|
Modification:
|
||||||
|
1. rename stm32f4xx_fsmc.h for XiUOS
|
||||||
|
*************************************************/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __HARDWARE_FSMC_H__
|
||||||
|
#define __HARDWARE_FSMC_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include <stm32f4xx.h>
|
||||||
|
|
||||||
|
/** @addtogroup STM32F4xx_StdPeriph_Driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup FSMC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Timing parameters For NOR/SRAM Banks
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t FSMC_AddressSetupTime; /*!< Defines the number of HCLK cycles to configure
|
||||||
|
the duration of the address setup time.
|
||||||
|
This parameter can be a value between 0 and 0xF.
|
||||||
|
@note This parameter is not used with synchronous NOR Flash memories. */
|
||||||
|
|
||||||
|
uint32_t FSMC_AddressHoldTime; /*!< Defines the number of HCLK cycles to configure
|
||||||
|
the duration of the address hold time.
|
||||||
|
This parameter can be a value between 0 and 0xF.
|
||||||
|
@note This parameter is not used with synchronous NOR Flash memories.*/
|
||||||
|
|
||||||
|
uint32_t FSMC_DataSetupTime; /*!< Defines the number of HCLK cycles to configure
|
||||||
|
the duration of the data setup time.
|
||||||
|
This parameter can be a value between 0 and 0xFF.
|
||||||
|
@note This parameter is used for SRAMs, ROMs and asynchronous multiplexed NOR Flash memories. */
|
||||||
|
|
||||||
|
uint32_t FSMC_BusTurnAroundDuration; /*!< Defines the number of HCLK cycles to configure
|
||||||
|
the duration of the bus turnaround.
|
||||||
|
This parameter can be a value between 0 and 0xF.
|
||||||
|
@note This parameter is only used for multiplexed NOR Flash memories. */
|
||||||
|
|
||||||
|
uint32_t FSMC_CLKDivision; /*!< Defines the period of CLK clock output signal, expressed in number of HCLK cycles.
|
||||||
|
This parameter can be a value between 1 and 0xF.
|
||||||
|
@note This parameter is not used for asynchronous NOR Flash, SRAM or ROM accesses. */
|
||||||
|
|
||||||
|
uint32_t FSMC_DataLatency; /*!< Defines the number of memory clock cycles to issue
|
||||||
|
to the memory before getting the first data.
|
||||||
|
The parameter value depends on the memory type as shown below:
|
||||||
|
- It must be set to 0 in case of a CRAM
|
||||||
|
- It is don't care in asynchronous NOR, SRAM or ROM accesses
|
||||||
|
- It may assume a value between 0 and 0xF in NOR Flash memories
|
||||||
|
with synchronous burst mode enable */
|
||||||
|
|
||||||
|
uint32_t FSMC_AccessMode; /*!< Specifies the asynchronous access mode.
|
||||||
|
This parameter can be a value of @ref FSMC_Access_Mode */
|
||||||
|
}FSMC_NORSRAMTimingInitTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FSMC NOR/SRAM Init structure definition
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t FSMC_Bank; /*!< Specifies the NOR/SRAM memory bank that will be used.
|
||||||
|
This parameter can be a value of @ref FSMC_NORSRAM_Bank */
|
||||||
|
|
||||||
|
uint32_t FSMC_DataAddressMux; /*!< Specifies whether the address and data values are
|
||||||
|
multiplexed on the databus or not.
|
||||||
|
This parameter can be a value of @ref FSMC_Data_Address_Bus_Multiplexing */
|
||||||
|
|
||||||
|
uint32_t FSMC_MemoryType; /*!< Specifies the type of external memory attached to
|
||||||
|
the corresponding memory bank.
|
||||||
|
This parameter can be a value of @ref FSMC_Memory_Type */
|
||||||
|
|
||||||
|
uint32_t FSMC_MemoryDataWidth; /*!< Specifies the external memory device width.
|
||||||
|
This parameter can be a value of @ref FSMC_Data_Width */
|
||||||
|
|
||||||
|
uint32_t FSMC_BurstAccessMode; /*!< Enables or disables the burst access mode for Flash memory,
|
||||||
|
valid only with synchronous burst Flash memories.
|
||||||
|
This parameter can be a value of @ref FSMC_Burst_Access_Mode */
|
||||||
|
|
||||||
|
uint32_t FSMC_AsynchronousWait; /*!< Enables or disables wait signal during asynchronous transfers,
|
||||||
|
valid only with asynchronous Flash memories.
|
||||||
|
This parameter can be a value of @ref FSMC_AsynchronousWait */
|
||||||
|
|
||||||
|
uint32_t FSMC_WaitSignalPolarity; /*!< Specifies the wait signal polarity, valid only when accessing
|
||||||
|
the Flash memory in burst mode.
|
||||||
|
This parameter can be a value of @ref FSMC_Wait_Signal_Polarity */
|
||||||
|
|
||||||
|
uint32_t FSMC_WrapMode; /*!< Enables or disables the Wrapped burst access mode for Flash
|
||||||
|
memory, valid only when accessing Flash memories in burst mode.
|
||||||
|
This parameter can be a value of @ref FSMC_Wrap_Mode */
|
||||||
|
|
||||||
|
uint32_t FSMC_WaitSignalActive; /*!< Specifies if the wait signal is asserted by the memory one
|
||||||
|
clock cycle before the wait state or during the wait state,
|
||||||
|
valid only when accessing memories in burst mode.
|
||||||
|
This parameter can be a value of @ref FSMC_Wait_Timing */
|
||||||
|
|
||||||
|
uint32_t FSMC_WriteOperation; /*!< Enables or disables the write operation in the selected bank by the FSMC.
|
||||||
|
This parameter can be a value of @ref FSMC_Write_Operation */
|
||||||
|
|
||||||
|
uint32_t FSMC_WaitSignal; /*!< Enables or disables the wait-state insertion via wait
|
||||||
|
signal, valid for Flash memory access in burst mode.
|
||||||
|
This parameter can be a value of @ref FSMC_Wait_Signal */
|
||||||
|
|
||||||
|
uint32_t FSMC_ExtendedMode; /*!< Enables or disables the extended mode.
|
||||||
|
This parameter can be a value of @ref FSMC_Extended_Mode */
|
||||||
|
|
||||||
|
uint32_t FSMC_WriteBurst; /*!< Enables or disables the write burst operation.
|
||||||
|
This parameter can be a value of @ref FSMC_Write_Burst */
|
||||||
|
|
||||||
|
FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct; /*!< Timing Parameters for write and read access if the ExtendedMode is not used*/
|
||||||
|
|
||||||
|
FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct; /*!< Timing Parameters for write access if the ExtendedMode is used*/
|
||||||
|
}FSMC_NORSRAMInitTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Timing parameters For FSMC NAND and PCCARD Banks
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t FSMC_SetupTime; /*!< Defines the number of HCLK cycles to setup address before
|
||||||
|
the command assertion for NAND-Flash read or write access
|
||||||
|
to common/Attribute or I/O memory space (depending on
|
||||||
|
the memory space timing to be configured).
|
||||||
|
This parameter can be a value between 0 and 0xFF.*/
|
||||||
|
|
||||||
|
uint32_t FSMC_WaitSetupTime; /*!< Defines the minimum number of HCLK cycles to CHECK the
|
||||||
|
command for NAND-Flash read or write access to
|
||||||
|
common/Attribute or I/O memory space (depending on the
|
||||||
|
memory space timing to be configured).
|
||||||
|
This parameter can be a number between 0x00 and 0xFF */
|
||||||
|
|
||||||
|
uint32_t FSMC_HoldSetupTime; /*!< Defines the number of HCLK clock cycles to hold address
|
||||||
|
(and data for write access) after the command deassertion
|
||||||
|
for NAND-Flash read or write access to common/Attribute
|
||||||
|
or I/O memory space (depending on the memory space timing
|
||||||
|
to be configured).
|
||||||
|
This parameter can be a number between 0x00 and 0xFF */
|
||||||
|
|
||||||
|
uint32_t FSMC_HiZSetupTime; /*!< Defines the number of HCLK clock cycles during which the
|
||||||
|
databus is kept in HiZ after the start of a NAND-Flash
|
||||||
|
write access to common/Attribute or I/O memory space (depending
|
||||||
|
on the memory space timing to be configured).
|
||||||
|
This parameter can be a number between 0x00 and 0xFF */
|
||||||
|
}FSMC_NAND_PCCARDTimingInitTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FSMC NAND Init structure definition
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t FSMC_Bank; /*!< Specifies the NAND memory bank that will be used.
|
||||||
|
This parameter can be a value of @ref FSMC_NAND_Bank */
|
||||||
|
|
||||||
|
uint32_t FSMC_Waitfeature; /*!< Enables or disables the Wait feature for the NAND Memory Bank.
|
||||||
|
This parameter can be any value of @ref FSMC_Wait_feature */
|
||||||
|
|
||||||
|
uint32_t FSMC_MemoryDataWidth; /*!< Specifies the external memory device width.
|
||||||
|
This parameter can be any value of @ref FSMC_Data_Width */
|
||||||
|
|
||||||
|
uint32_t FSMC_ECC; /*!< Enables or disables the ECC computation.
|
||||||
|
This parameter can be any value of @ref FSMC_ECC */
|
||||||
|
|
||||||
|
uint32_t FSMC_ECCPageSize; /*!< Defines the page size for the extended ECC.
|
||||||
|
This parameter can be any value of @ref FSMC_ECC_Page_Size */
|
||||||
|
|
||||||
|
uint32_t FSMC_TCLRSetupTime; /*!< Defines the number of HCLK cycles to configure the
|
||||||
|
delay between CLE low and RE low.
|
||||||
|
This parameter can be a value between 0 and 0xFF. */
|
||||||
|
|
||||||
|
uint32_t FSMC_TARSetupTime; /*!< Defines the number of HCLK cycles to configure the
|
||||||
|
delay between ALE low and RE low.
|
||||||
|
This parameter can be a number between 0x0 and 0xFF */
|
||||||
|
|
||||||
|
FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_CommonSpaceTimingStruct; /*!< FSMC Common Space Timing */
|
||||||
|
|
||||||
|
FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_AttributeSpaceTimingStruct; /*!< FSMC Attribute Space Timing */
|
||||||
|
}FSMC_NANDInitTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FSMC PCCARD Init structure definition
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t FSMC_Waitfeature; /*!< Enables or disables the Wait feature for the Memory Bank.
|
||||||
|
This parameter can be any value of @ref FSMC_Wait_feature */
|
||||||
|
|
||||||
|
uint32_t FSMC_TCLRSetupTime; /*!< Defines the number of HCLK cycles to configure the
|
||||||
|
delay between CLE low and RE low.
|
||||||
|
This parameter can be a value between 0 and 0xFF. */
|
||||||
|
|
||||||
|
uint32_t FSMC_TARSetupTime; /*!< Defines the number of HCLK cycles to configure the
|
||||||
|
delay between ALE low and RE low.
|
||||||
|
This parameter can be a number between 0x0 and 0xFF */
|
||||||
|
|
||||||
|
|
||||||
|
FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_CommonSpaceTimingStruct; /*!< FSMC Common Space Timing */
|
||||||
|
|
||||||
|
FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_AttributeSpaceTimingStruct; /*!< FSMC Attribute Space Timing */
|
||||||
|
|
||||||
|
FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_IOSpaceTimingStruct; /*!< FSMC IO Space Timing */
|
||||||
|
}FSMC_PCCARDInitTypeDef;
|
||||||
|
|
||||||
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Exported_Constants
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_NORSRAM_Bank
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_Bank1_NORSRAM1 ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_Bank1_NORSRAM2 ((uint32_t)0x00000002)
|
||||||
|
#define FSMC_Bank1_NORSRAM3 ((uint32_t)0x00000004)
|
||||||
|
#define FSMC_Bank1_NORSRAM4 ((uint32_t)0x00000006)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_NAND_Bank
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_Bank2_NAND ((uint32_t)0x00000010)
|
||||||
|
#define FSMC_Bank3_NAND ((uint32_t)0x00000100)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_PCCARD_Bank
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_Bank4_PCCARD ((uint32_t)0x00001000)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define IS_FSMC_NORSRAM_BANK(BANK) (((BANK) == FSMC_Bank1_NORSRAM1) || \
|
||||||
|
((BANK) == FSMC_Bank1_NORSRAM2) || \
|
||||||
|
((BANK) == FSMC_Bank1_NORSRAM3) || \
|
||||||
|
((BANK) == FSMC_Bank1_NORSRAM4))
|
||||||
|
|
||||||
|
#define IS_FSMC_NAND_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
|
||||||
|
((BANK) == FSMC_Bank3_NAND))
|
||||||
|
|
||||||
|
#define IS_FSMC_GETFLAG_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
|
||||||
|
((BANK) == FSMC_Bank3_NAND) || \
|
||||||
|
((BANK) == FSMC_Bank4_PCCARD))
|
||||||
|
|
||||||
|
#define IS_FSMC_IT_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
|
||||||
|
((BANK) == FSMC_Bank3_NAND) || \
|
||||||
|
((BANK) == FSMC_Bank4_PCCARD))
|
||||||
|
|
||||||
|
/** @defgroup FSMC_NOR_SRAM_Controller
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Data_Address_Bus_Multiplexing
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FSMC_DataAddressMux_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_DataAddressMux_Enable ((uint32_t)0x00000002)
|
||||||
|
#define IS_FSMC_MUX(MUX) (((MUX) == FSMC_DataAddressMux_Disable) || \
|
||||||
|
((MUX) == FSMC_DataAddressMux_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Memory_Type
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FSMC_MemoryType_SRAM ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_MemoryType_PSRAM ((uint32_t)0x00000004)
|
||||||
|
#define FSMC_MemoryType_NOR ((uint32_t)0x00000008)
|
||||||
|
#define IS_FSMC_MEMORY(MEMORY) (((MEMORY) == FSMC_MemoryType_SRAM) || \
|
||||||
|
((MEMORY) == FSMC_MemoryType_PSRAM)|| \
|
||||||
|
((MEMORY) == FSMC_MemoryType_NOR))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Data_Width
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FSMC_MemoryDataWidth_8b ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_MemoryDataWidth_16b ((uint32_t)0x00000010)
|
||||||
|
#define FSMC_MemoryDataWidth_32b ((uint32_t)0x00000020)
|
||||||
|
#define IS_FSMC_MEMORY_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
|
||||||
|
((WIDTH) == FSMC_MemoryDataWidth_16b))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Burst_Access_Mode
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FSMC_BurstAccessMode_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_BurstAccessMode_Enable ((uint32_t)0x00000100)
|
||||||
|
#define IS_FSMC_BURSTMODE(STATE) (((STATE) == FSMC_BurstAccessMode_Disable) || \
|
||||||
|
((STATE) == FSMC_BurstAccessMode_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_AsynchronousWait
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_AsynchronousWait_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_AsynchronousWait_Enable ((uint32_t)0x00008000)
|
||||||
|
#define IS_FSMC_ASYNWAIT(STATE) (((STATE) == FSMC_AsynchronousWait_Disable) || \
|
||||||
|
((STATE) == FSMC_AsynchronousWait_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Wait_Signal_Polarity
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_WaitSignalPolarity_Low ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_WaitSignalPolarity_High ((uint32_t)0x00000200)
|
||||||
|
#define IS_FSMC_WAIT_POLARITY(POLARITY) (((POLARITY) == FSMC_WaitSignalPolarity_Low) || \
|
||||||
|
((POLARITY) == FSMC_WaitSignalPolarity_High))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Wrap_Mode
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_WrapMode_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_WrapMode_Enable ((uint32_t)0x00000400)
|
||||||
|
#define IS_FSMC_WRAP_MODE(MODE) (((MODE) == FSMC_WrapMode_Disable) || \
|
||||||
|
((MODE) == FSMC_WrapMode_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Wait_Timing
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_WaitSignalActive_BeforeWaitState ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_WaitSignalActive_DuringWaitState ((uint32_t)0x00000800)
|
||||||
|
#define IS_FSMC_WAIT_SIGNAL_ACTIVE(ACTIVE) (((ACTIVE) == FSMC_WaitSignalActive_BeforeWaitState) || \
|
||||||
|
((ACTIVE) == FSMC_WaitSignalActive_DuringWaitState))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Write_Operation
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_WriteOperation_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_WriteOperation_Enable ((uint32_t)0x00001000)
|
||||||
|
#define IS_FSMC_WRITE_OPERATION(OPERATION) (((OPERATION) == FSMC_WriteOperation_Disable) || \
|
||||||
|
((OPERATION) == FSMC_WriteOperation_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Wait_Signal
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_WaitSignal_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_WaitSignal_Enable ((uint32_t)0x00002000)
|
||||||
|
#define IS_FSMC_WAITE_SIGNAL(SIGNAL) (((SIGNAL) == FSMC_WaitSignal_Disable) || \
|
||||||
|
((SIGNAL) == FSMC_WaitSignal_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Extended_Mode
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_ExtendedMode_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_ExtendedMode_Enable ((uint32_t)0x00004000)
|
||||||
|
|
||||||
|
#define IS_FSMC_EXTENDED_MODE(MODE) (((MODE) == FSMC_ExtendedMode_Disable) || \
|
||||||
|
((MODE) == FSMC_ExtendedMode_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Write_Burst
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FSMC_WriteBurst_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_WriteBurst_Enable ((uint32_t)0x00080000)
|
||||||
|
#define IS_FSMC_WRITE_BURST(BURST) (((BURST) == FSMC_WriteBurst_Disable) || \
|
||||||
|
((BURST) == FSMC_WriteBurst_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Address_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_ADDRESS_SETUP_TIME(TIME) ((TIME) <= 0xF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Address_Hold_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_ADDRESS_HOLD_TIME(TIME) ((TIME) <= 0xF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Data_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_DATASETUP_TIME(TIME) (((TIME) > 0) && ((TIME) <= 0xFF))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Bus_Turn_around_Duration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_TURNAROUND_TIME(TIME) ((TIME) <= 0xF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_CLK_Division
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_CLK_DIV(DIV) ((DIV) <= 0xF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Data_Latency
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_DATA_LATENCY(LATENCY) ((LATENCY) <= 0xF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Access_Mode
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_AccessMode_A ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_AccessMode_B ((uint32_t)0x10000000)
|
||||||
|
#define FSMC_AccessMode_C ((uint32_t)0x20000000)
|
||||||
|
#define FSMC_AccessMode_D ((uint32_t)0x30000000)
|
||||||
|
#define IS_FSMC_ACCESS_MODE(MODE) (((MODE) == FSMC_AccessMode_A) || \
|
||||||
|
((MODE) == FSMC_AccessMode_B) || \
|
||||||
|
((MODE) == FSMC_AccessMode_C) || \
|
||||||
|
((MODE) == FSMC_AccessMode_D))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_NAND_PCCARD_Controller
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Wait_feature
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_Waitfeature_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_Waitfeature_Enable ((uint32_t)0x00000002)
|
||||||
|
#define IS_FSMC_WAIT_FEATURE(FEATURE) (((FEATURE) == FSMC_Waitfeature_Disable) || \
|
||||||
|
((FEATURE) == FSMC_Waitfeature_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup FSMC_ECC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_ECC_Disable ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_ECC_Enable ((uint32_t)0x00000040)
|
||||||
|
#define IS_FSMC_ECC_STATE(STATE) (((STATE) == FSMC_ECC_Disable) || \
|
||||||
|
((STATE) == FSMC_ECC_Enable))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_ECC_Page_Size
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_ECCPageSize_256Bytes ((uint32_t)0x00000000)
|
||||||
|
#define FSMC_ECCPageSize_512Bytes ((uint32_t)0x00020000)
|
||||||
|
#define FSMC_ECCPageSize_1024Bytes ((uint32_t)0x00040000)
|
||||||
|
#define FSMC_ECCPageSize_2048Bytes ((uint32_t)0x00060000)
|
||||||
|
#define FSMC_ECCPageSize_4096Bytes ((uint32_t)0x00080000)
|
||||||
|
#define FSMC_ECCPageSize_8192Bytes ((uint32_t)0x000A0000)
|
||||||
|
#define IS_FSMC_ECCPAGE_SIZE(SIZE) (((SIZE) == FSMC_ECCPageSize_256Bytes) || \
|
||||||
|
((SIZE) == FSMC_ECCPageSize_512Bytes) || \
|
||||||
|
((SIZE) == FSMC_ECCPageSize_1024Bytes) || \
|
||||||
|
((SIZE) == FSMC_ECCPageSize_2048Bytes) || \
|
||||||
|
((SIZE) == FSMC_ECCPageSize_4096Bytes) || \
|
||||||
|
((SIZE) == FSMC_ECCPageSize_8192Bytes))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_TCLR_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_TCLR_TIME(TIME) ((TIME) <= 0xFF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_TAR_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_TAR_TIME(TIME) ((TIME) <= 0xFF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_SETUP_TIME(TIME) ((TIME) <= 0xFF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Wait_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_WAIT_TIME(TIME) ((TIME) <= 0xFF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Hold_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_HOLD_TIME(TIME) ((TIME) <= 0xFF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_HiZ_Setup_Time
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define IS_FSMC_HIZ_TIME(TIME) ((TIME) <= 0xFF)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Interrupt_sources
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_IT_RisingEdge ((uint32_t)0x00000008)
|
||||||
|
#define FSMC_IT_Level ((uint32_t)0x00000010)
|
||||||
|
#define FSMC_IT_FallingEdge ((uint32_t)0x00000020)
|
||||||
|
#define IS_FSMC_IT(IT) ((((IT) & (uint32_t)0xFFFFFFC7) == 0x00000000) && ((IT) != 0x00000000))
|
||||||
|
#define IS_FSMC_GET_IT(IT) (((IT) == FSMC_IT_RisingEdge) || \
|
||||||
|
((IT) == FSMC_IT_Level) || \
|
||||||
|
((IT) == FSMC_IT_FallingEdge))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup FSMC_Flags
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define FSMC_FLAG_RisingEdge ((uint32_t)0x00000001)
|
||||||
|
#define FSMC_FLAG_Level ((uint32_t)0x00000002)
|
||||||
|
#define FSMC_FLAG_FallingEdge ((uint32_t)0x00000004)
|
||||||
|
#define FSMC_FLAG_FEMPT ((uint32_t)0x00000040)
|
||||||
|
#define IS_FSMC_GET_FLAG(FLAG) (((FLAG) == FSMC_FLAG_RisingEdge) || \
|
||||||
|
((FLAG) == FSMC_FLAG_Level) || \
|
||||||
|
((FLAG) == FSMC_FLAG_FallingEdge) || \
|
||||||
|
((FLAG) == FSMC_FLAG_FEMPT))
|
||||||
|
|
||||||
|
#define IS_FSMC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFF8) == 0x00000000) && ((FLAG) != 0x00000000))
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* NOR/SRAM Controller functions **********************************************/
|
||||||
|
void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank);
|
||||||
|
void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
|
||||||
|
void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
|
||||||
|
void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState);
|
||||||
|
|
||||||
|
/* NAND Controller functions **************************************************/
|
||||||
|
void FSMC_NANDDeInit(uint32_t FSMC_Bank);
|
||||||
|
void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
|
||||||
|
void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
|
||||||
|
void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState);
|
||||||
|
void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState);
|
||||||
|
uint32_t FSMC_GetECC(uint32_t FSMC_Bank);
|
||||||
|
|
||||||
|
/* PCCARD Controller functions ************************************************/
|
||||||
|
void FSMC_PCCARDDeInit(void);
|
||||||
|
void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
|
||||||
|
void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
|
||||||
|
void FSMC_PCCARDCmd(FunctionalState NewState);
|
||||||
|
|
||||||
|
/* Interrupts and flags management functions **********************************/
|
||||||
|
void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState);
|
||||||
|
FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG);
|
||||||
|
void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG);
|
||||||
|
ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT);
|
||||||
|
void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*__HARDWARE_FSMC_H__ */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
|
@ -37,6 +37,10 @@ menu "Kernel feature"
|
||||||
help
|
help
|
||||||
Alignment size for CPU architecture data access
|
Alignment size for CPU architecture data access
|
||||||
|
|
||||||
|
config MEM_EXTERN_SRAM
|
||||||
|
bool "Using extern memory"
|
||||||
|
default n
|
||||||
|
|
||||||
config MM_PAGE_SIZE
|
config MM_PAGE_SIZE
|
||||||
int "Config memory page size"
|
int "Config memory page size"
|
||||||
default 4096
|
default 4096
|
||||||
|
|
|
@ -85,6 +85,9 @@ void FreeBlockMemGather(void *data_block);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void InitBoardMemory(void *begin_addr, void *end_addr);
|
void InitBoardMemory(void *begin_addr, void *end_addr);
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint8 extsram_idx);
|
||||||
|
#endif
|
||||||
void *x_malloc(x_size_t nbytes);
|
void *x_malloc(x_size_t nbytes);
|
||||||
void x_free(void *ptr);
|
void x_free(void *ptr);
|
||||||
void *x_realloc(void *ptr, x_size_t nbytes);
|
void *x_realloc(void *ptr, x_size_t nbytes);
|
||||||
|
|
|
@ -31,6 +31,9 @@ endif
|
||||||
ifeq ($(CONFIG_KERNEL_TEST_MEM),y)
|
ifeq ($(CONFIG_KERNEL_TEST_MEM),y)
|
||||||
SRC_FILES += test_mem.c
|
SRC_FILES += test_mem.c
|
||||||
SRC_FILES += test_gatherblock.c
|
SRC_FILES += test_gatherblock.c
|
||||||
|
ifeq ($(CONFIG_MEM_EXTERN_SRAM),y)
|
||||||
|
SRC_FILES += extsram_test.c
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_KERNEL_TEST_TIMER),y)
|
ifeq ($(CONFIG_KERNEL_TEST_TIMER),y)
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
#include <xiuos.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* parameters for sram peripheral */
|
||||||
|
/* stm32f4 Bank3:0X68000000 */
|
||||||
|
#define SRAM_BANK_ADDR ((uint32_t)0X68000000)
|
||||||
|
/* data width: 8, 16, 32 */
|
||||||
|
#define SRAM_DATA_WIDTH 16
|
||||||
|
/* sram size */
|
||||||
|
#define SRAM_SIZE ((uint32_t)0x00100000)
|
||||||
|
|
||||||
|
int sram_test(void)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
uint32_t start_time = 0, time_cast = 0;
|
||||||
|
#if SRAM_DATA_WIDTH == 8
|
||||||
|
char data_width = 1;
|
||||||
|
uint8_t data = 0;
|
||||||
|
#elif SRAM_DATA_WIDTH == 16
|
||||||
|
char data_width = 2;
|
||||||
|
uint16_t data = 0;
|
||||||
|
#else
|
||||||
|
char data_width = 4;
|
||||||
|
uint32_t data = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* write data */
|
||||||
|
KPrintf("Writing the %ld bytes data, waiting....", SRAM_SIZE);
|
||||||
|
start_time = CurrentTicksGain();
|
||||||
|
for (i = 0; i < SRAM_SIZE / data_width; i++)
|
||||||
|
{
|
||||||
|
#if SRAM_DATA_WIDTH == 8
|
||||||
|
*(volatile uint8_t *)(SRAM_BANK_ADDR + i * data_width) = (uint8_t)0x55;
|
||||||
|
#elif SRAM_DATA_WIDTH == 16
|
||||||
|
*(volatile uint16_t *)(SRAM_BANK_ADDR + i * data_width) = (uint16_t)0x5555;
|
||||||
|
#else
|
||||||
|
*(volatile uint32_t *)(SRAM_BANK_ADDR + i * data_width) = (uint32_t)0x55555555;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
time_cast = CurrentTicksGain() - start_time;
|
||||||
|
KPrintf("Write data success, total time: %d.%03dS.\n", time_cast / TICK_PER_SECOND,
|
||||||
|
time_cast % TICK_PER_SECOND / ((TICK_PER_SECOND * 1 + 999) / 1000));
|
||||||
|
|
||||||
|
/* read data */
|
||||||
|
KPrintf("start Reading and verifying data, waiting....\n");
|
||||||
|
for (i = 0; i < SRAM_SIZE / data_width; i++)
|
||||||
|
{
|
||||||
|
#if SRAM_DATA_WIDTH == 8
|
||||||
|
data = *(volatile uint8_t *)(SRAM_BANK_ADDR + i * data_width);
|
||||||
|
if (data != 0x55)
|
||||||
|
{
|
||||||
|
KPrintf("SRAM test failed!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#elif SRAM_DATA_WIDTH == 16
|
||||||
|
data = *(volatile uint16_t *)(SRAM_BANK_ADDR + i * data_width);
|
||||||
|
if (data != 0x5555)
|
||||||
|
{
|
||||||
|
KPrintf("SRAM test failed! data = 0x%x\n",data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
data = *(volatile uint32_t *)(SRAM_BANK_ADDR + i * data_width);
|
||||||
|
if (data != 0x55555555)
|
||||||
|
{
|
||||||
|
KPrintf("SRAM test failed!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i >= SRAM_SIZE / data_width)
|
||||||
|
{
|
||||||
|
KPrintf("SRAM test success!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),sram_test, sram_test, sram_test );
|
|
@ -140,10 +140,10 @@ int FendGrin()
|
||||||
int tempvalue = 1;
|
int tempvalue = 1;
|
||||||
|
|
||||||
while( i< MEM_GRIN_COUNT) {
|
while( i< MEM_GRIN_COUNT) {
|
||||||
KPrintf("\033[32;1malloc memory [%d]\033[0m\n",tempvalue);
|
|
||||||
ptr[i] = x_malloc(tempvalue);
|
ptr[i] = x_malloc(tempvalue);
|
||||||
|
|
||||||
if (ptr[i]) {
|
if (ptr[i]) {
|
||||||
|
KPrintf("\033[32;1malloc memory [%d] ptr[%d] = 0x%x\033[0m\n",tempvalue,i,ptr[i]);
|
||||||
arr_grin[i] = tempvalue;
|
arr_grin[i] = tempvalue;
|
||||||
i++;
|
i++;
|
||||||
tempvalue++;
|
tempvalue++;
|
||||||
|
|
|
@ -43,6 +43,13 @@
|
||||||
/* These masks are used to get the flags and data field of memory blocks */
|
/* These masks are used to get the flags and data field of memory blocks */
|
||||||
#define STATIC_BLOCK_MASK 0x80000000
|
#define STATIC_BLOCK_MASK 0x80000000
|
||||||
#define DYNAMIC_BLOCK_MASK 0x40000000
|
#define DYNAMIC_BLOCK_MASK 0x40000000
|
||||||
|
#define DYNAMIC_BLOCK_NO_EXTMEM_MASK DYNAMIC_BLOCK_MASK
|
||||||
|
// #define DYNAMIC_BLOCK_EXTMEM1_MASK 0x40010000 ///< dynamic memory block external SRAM 1
|
||||||
|
// #define DYNAMIC_BLOCK_EXTMEM2_MASK 0x40020000 ///< dynamic memory block external SRAM 2
|
||||||
|
// #define DYNAMIC_BLOCK_EXTMEM3_MASK 0x40030000 ///< dynamic memory block external SRAM 3
|
||||||
|
// #define DYNAMIC_BLOCK_EXTMEM4_MASK 0x40040000 ///< dynamic memory block external SRAM 4
|
||||||
|
#define DYNAMIC_BLOCK_EXTMEMn_MASK(n) (DYNAMIC_BLOCK_MASK | (0xFF & n) << 16)
|
||||||
|
|
||||||
#define ALLOC_BLOCK_MASK 0xc0000000
|
#define ALLOC_BLOCK_MASK 0xc0000000
|
||||||
#define DYNAMIC_REMAINING_MASK 0x3fffffff
|
#define DYNAMIC_REMAINING_MASK 0x3fffffff
|
||||||
|
|
||||||
|
@ -59,6 +66,7 @@ struct DynamicAllocNode
|
||||||
{
|
{
|
||||||
x_size_t size; /* the size of dynamicAllocNode */
|
x_size_t size; /* the size of dynamicAllocNode */
|
||||||
uint32 prev_adj_size; /* the size of the previous adjacent node, (dynamic alloc node or dynamic free node */
|
uint32 prev_adj_size; /* the size of the previous adjacent node, (dynamic alloc node or dynamic free node */
|
||||||
|
uint32 flag; /* |static_dynamic[32-24]|ext_sram[23-16]|res[15-8]|res[7-0]| */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,6 +76,7 @@ struct DynamicFreeNode
|
||||||
{
|
{
|
||||||
x_size_t size; /* the size of dynamicAllocNode */
|
x_size_t size; /* the size of dynamicAllocNode */
|
||||||
uint32 prev_adj_size; /* the size of the previous adjacent node, (dynamic alloc node or dynamic free node */
|
uint32 prev_adj_size; /* the size of the previous adjacent node, (dynamic alloc node or dynamic free node */
|
||||||
|
uint32 flag; /* |static_dynamic_region_flag[32-24]|ext_sram_idx[23-16]|res[15-8]|res[7-0]| */
|
||||||
|
|
||||||
struct DynamicFreeNode *next;
|
struct DynamicFreeNode *next;
|
||||||
struct DynamicFreeNode *prev;
|
struct DynamicFreeNode *prev;
|
||||||
|
@ -144,7 +153,7 @@ struct StaticMemoryDone
|
||||||
struct DynamicBuddyMemoryDone
|
struct DynamicBuddyMemoryDone
|
||||||
{
|
{
|
||||||
void (*init)(struct DynamicBuddyMemory *dynamic_buddy, x_ubase dynamic_buddy_start,x_ubase dynamic_buddy_size);
|
void (*init)(struct DynamicBuddyMemory *dynamic_buddy, x_ubase dynamic_buddy_start,x_ubase dynamic_buddy_size);
|
||||||
void* (*malloc)(struct DynamicBuddyMemory *dynamic_buddy, x_size_t size);
|
void* (*malloc)(struct DynamicBuddyMemory *dynamic_buddy, x_size_t size, uint32 extsram_mask);
|
||||||
void (*release)(struct ByteMemory *byte_memory, void *pointer);
|
void (*release)(struct ByteMemory *byte_memory, void *pointer);
|
||||||
int (*JudgeLegal)(struct DynamicBuddyMemory *dynamic_buddy, void *pointer);
|
int (*JudgeLegal)(struct DynamicBuddyMemory *dynamic_buddy, void *pointer);
|
||||||
};
|
};
|
||||||
|
@ -155,6 +164,10 @@ static struct ByteMemory ByteManager;
|
||||||
#ifdef SEPARATE_COMPILE
|
#ifdef SEPARATE_COMPILE
|
||||||
static struct ByteMemory UserByteManager;
|
static struct ByteMemory UserByteManager;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
static struct ByteMemory ExtByteManager[EXTSRAM_MAX_NUM] = {0};
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* This function determines whether the address is valid.
|
* This function determines whether the address is valid.
|
||||||
*
|
*
|
||||||
|
@ -187,7 +200,7 @@ static int SmallMemTypeAlloc(struct DynamicAllocNode *address)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(address);
|
NULL_PARAM_CHECK(address);
|
||||||
|
|
||||||
if(address->prev_adj_size & STATIC_BLOCK_MASK) {
|
if(address->flag & STATIC_BLOCK_MASK) {
|
||||||
return RET_TRUE;
|
return RET_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +218,7 @@ static int MmAllocNode(struct DynamicAllocNode *memory_ptr)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(memory_ptr);
|
NULL_PARAM_CHECK(memory_ptr);
|
||||||
|
|
||||||
if(memory_ptr->prev_adj_size & ALLOC_BLOCK_MASK) {
|
if(memory_ptr->flag & ALLOC_BLOCK_MASK) {
|
||||||
return RET_TRUE;
|
return RET_TRUE;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -233,7 +246,6 @@ static int CaculateBuddyIndex(x_size_t size)
|
||||||
} else {
|
} else {
|
||||||
ndx = MEM_LINKNRS - 1;
|
ndx = MEM_LINKNRS - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndx;
|
return ndx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,18 +301,20 @@ static void InitBuddy(struct DynamicBuddyMemory *dynamic_buddy, x_ubase dynamic_
|
||||||
/* record the start boundary of dynamic buddy memory */
|
/* record the start boundary of dynamic buddy memory */
|
||||||
dynamic_buddy->mm_dynamic_start[0] = PTR2ALLOCNODE(dynamic_buddy_start);
|
dynamic_buddy->mm_dynamic_start[0] = PTR2ALLOCNODE(dynamic_buddy_start);
|
||||||
dynamic_buddy->mm_dynamic_start[0]->size = SIZEOF_DYNAMICALLOCNODE_MEM;
|
dynamic_buddy->mm_dynamic_start[0]->size = SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
dynamic_buddy->mm_dynamic_start[0]->prev_adj_size = DYNAMIC_BLOCK_MASK;
|
dynamic_buddy->mm_dynamic_start[0]->prev_adj_size = 0;
|
||||||
|
dynamic_buddy->mm_dynamic_start[0]->flag = DYNAMIC_BLOCK_MASK;
|
||||||
|
|
||||||
/* the initialized free node */
|
/* the initialized free node */
|
||||||
node =(struct DynamicFreeNode *) ((x_ubase)dynamic_buddy_start + SIZEOF_DYNAMICALLOCNODE_MEM);
|
node =(struct DynamicFreeNode *) ((x_ubase)dynamic_buddy_start + SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
node->size=(uint32)(dynamic_buddy_size - 2* SIZEOF_DYNAMICALLOCNODE_MEM);
|
node->size=(dynamic_buddy_size - 2* SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
node->prev_adj_size= SIZEOF_DYNAMICALLOCNODE_MEM;
|
node->prev_adj_size= SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
|
node->flag= 0;
|
||||||
|
|
||||||
/* record the end boundary of dynamic buddy memory */
|
/* record the end boundary of dynamic buddy memory */
|
||||||
dynamic_buddy->mm_dynamic_end[0] = PTR2ALLOCNODE((x_ubase)dynamic_buddy_start + (x_ubase)dynamic_buddy_size - SIZEOF_DYNAMICALLOCNODE_MEM);
|
dynamic_buddy->mm_dynamic_end[0] = PTR2ALLOCNODE((x_ubase)dynamic_buddy_start + (x_ubase)dynamic_buddy_size - SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
dynamic_buddy->mm_dynamic_end[0]->size = SIZEOF_DYNAMICALLOCNODE_MEM;
|
dynamic_buddy->mm_dynamic_end[0]->size = SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
dynamic_buddy->mm_dynamic_end[0]->prev_adj_size = node->size;
|
dynamic_buddy->mm_dynamic_end[0]->prev_adj_size = node->size;
|
||||||
dynamic_buddy->mm_dynamic_end[0]->prev_adj_size |= DYNAMIC_BLOCK_MASK;
|
dynamic_buddy->mm_dynamic_end[0]->flag = DYNAMIC_BLOCK_MASK;
|
||||||
|
|
||||||
/* insert node into dynamic buddy memory */
|
/* insert node into dynamic buddy memory */
|
||||||
AddNewNodeIntoBuddy(dynamic_buddy,node);
|
AddNewNodeIntoBuddy(dynamic_buddy,node);
|
||||||
|
@ -311,13 +325,14 @@ static void InitBuddy(struct DynamicBuddyMemory *dynamic_buddy, x_ubase dynamic_
|
||||||
*
|
*
|
||||||
* @param dynamic_buddy the heart dynamic buddy structure
|
* @param dynamic_buddy the heart dynamic buddy structure
|
||||||
* @param size the memory size to be allocated
|
* @param size the memory size to be allocated
|
||||||
|
* @param extsram_mask mask the memory region comes from ext sram
|
||||||
*
|
*
|
||||||
* @return pointer address on success; NULL on failure
|
* @return pointer address on success; NULL on failure
|
||||||
*/
|
*/
|
||||||
static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t size)
|
static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t size, uint32 extsram_mask)
|
||||||
{
|
{
|
||||||
int ndx = 0;
|
int ndx = 0;
|
||||||
x_size_t allocsize = 0;
|
uint32 allocsize = 0;
|
||||||
void *result = NONE;
|
void *result = NONE;
|
||||||
struct DynamicFreeNode *node = NONE;
|
struct DynamicFreeNode *node = NONE;
|
||||||
|
|
||||||
|
@ -325,7 +340,6 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
|
||||||
|
|
||||||
/* calculate the real size */
|
/* calculate the real size */
|
||||||
allocsize = size + SIZEOF_DYNAMICALLOCNODE_MEM;
|
allocsize = size + SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
|
|
||||||
/* if the size exceeds the upper limit, return MEM_LINKNRS - 1 */
|
/* if the size exceeds the upper limit, return MEM_LINKNRS - 1 */
|
||||||
if (allocsize >= MEM_HIGH_RANGE) {
|
if (allocsize >= MEM_HIGH_RANGE) {
|
||||||
ndx = MEM_LINKNRS - 1;
|
ndx = MEM_LINKNRS - 1;
|
||||||
|
@ -339,12 +353,11 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
|
||||||
node && (node->size < allocsize);
|
node && (node->size < allocsize);
|
||||||
node = node->next) {
|
node = node->next) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* get the best-fit freeNode */
|
/* get the best-fit freeNode */
|
||||||
if (node && (node->size > allocsize)) {
|
if (node && (node->size > allocsize)) {
|
||||||
struct DynamicFreeNode *remainder;
|
struct DynamicFreeNode *remainder;
|
||||||
struct DynamicFreeNode *next;
|
struct DynamicFreeNode *next;
|
||||||
x_size_t remaining;
|
uint32 remaining;
|
||||||
|
|
||||||
node->prev->next = node->next;
|
node->prev->next = node->next;
|
||||||
if (node->next) {
|
if (node->next) {
|
||||||
|
@ -358,25 +371,29 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
|
||||||
/* create the remainder node */
|
/* create the remainder node */
|
||||||
remainder = PTR2FREENODE(((char *)node) + allocsize);
|
remainder = PTR2FREENODE(((char *)node) + allocsize);
|
||||||
remainder->size = remaining;
|
remainder->size = remaining;
|
||||||
|
|
||||||
remainder->prev_adj_size = allocsize;
|
remainder->prev_adj_size = allocsize;
|
||||||
|
remainder->flag = 0;
|
||||||
|
|
||||||
/* adjust the size of the node */
|
/* adjust the size of the node */
|
||||||
node->size = allocsize;
|
node->size = allocsize;
|
||||||
next->prev_adj_size = (remaining|(next->prev_adj_size & ALLOC_BLOCK_MASK));
|
next->prev_adj_size = remaining;
|
||||||
|
|
||||||
/* insert the remainder freeNode back into the dynamic buddy memory */
|
/* insert the remainder freeNode back into the dynamic buddy memory */
|
||||||
AddNewNodeIntoBuddy(dynamic_buddy, remainder);
|
AddNewNodeIntoBuddy(dynamic_buddy, remainder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle the case of an exact size match */
|
/* handle the case of an exact size match */
|
||||||
node->prev_adj_size &= DYNAMIC_REMAINING_MASK;
|
|
||||||
node->prev_adj_size |= DYNAMIC_BLOCK_MASK;
|
node->flag = extsram_mask;
|
||||||
result = (void *)((char *)node + SIZEOF_DYNAMICALLOCNODE_MEM);
|
result = (void *)((char *)node + SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* failure allocation */
|
/* failure allocation */
|
||||||
if(result == NONE) {
|
if(result == NONE) {
|
||||||
|
#ifndef MEM_EXTERN_SRAM
|
||||||
KPrintf("%s: allocation failed, size %d.\n", __func__,allocsize);
|
KPrintf("%s: allocation failed, size %d.\n", __func__,allocsize);
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +430,7 @@ static void BigMemFree( struct ByteMemory *byte_memory, void *pointer)
|
||||||
/* get the next sibling freeNode */
|
/* get the next sibling freeNode */
|
||||||
next = PTR2FREENODE((char*)node+node->size);
|
next = PTR2FREENODE((char*)node+node->size);
|
||||||
|
|
||||||
if(((next->prev_adj_size & DYNAMIC_BLOCK_MASK) == 0)) {
|
if(((next->flag & DYNAMIC_BLOCK_MASK) == 0)) {
|
||||||
struct DynamicAllocNode *andbeyond;
|
struct DynamicAllocNode *andbeyond;
|
||||||
|
|
||||||
andbeyond = PTR2ALLOCNODE((char*)next + next->size);
|
andbeyond = PTR2ALLOCNODE((char*)next + next->size);
|
||||||
|
@ -423,21 +440,22 @@ static void BigMemFree( struct ByteMemory *byte_memory, void *pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
node->size += next->size;
|
node->size += next->size;
|
||||||
andbeyond->prev_adj_size = (node->size | (andbeyond->prev_adj_size & ALLOC_BLOCK_MASK));
|
andbeyond->prev_adj_size = node->size;
|
||||||
next = (struct DynamicFreeNode*)andbeyond;
|
next = (struct DynamicFreeNode*)andbeyond;
|
||||||
}
|
}
|
||||||
/* get the prev sibling freeNode */
|
/* get the prev sibling freeNode */
|
||||||
prev = (struct DynamicFreeNode*)((char*)node - (node->prev_adj_size & DYNAMIC_REMAINING_MASK));
|
prev = (struct DynamicFreeNode*)((char*)node - node->prev_adj_size );
|
||||||
if((prev->prev_adj_size & DYNAMIC_BLOCK_MASK)==0) {
|
if((prev->flag & DYNAMIC_BLOCK_MASK)==0) {
|
||||||
|
|
||||||
prev->prev->next=prev->next;
|
prev->prev->next=prev->next;
|
||||||
if(prev->next){
|
if(prev->next){
|
||||||
prev->next->prev = prev->prev;
|
prev->next->prev = prev->prev;
|
||||||
}
|
}
|
||||||
prev->size += node->size;
|
prev->size += node->size;
|
||||||
next->prev_adj_size = (prev->size | (next->prev_adj_size & ALLOC_BLOCK_MASK));
|
next->prev_adj_size = prev->size;
|
||||||
node = prev;
|
node = prev;
|
||||||
}
|
}
|
||||||
node->prev_adj_size &= DYNAMIC_REMAINING_MASK;
|
node->flag = 0;
|
||||||
|
|
||||||
/* insert freeNode into dynamic buddy memory */
|
/* insert freeNode into dynamic buddy memory */
|
||||||
AddNewNodeIntoBuddy(&byte_memory->dynamic_buddy_manager,node);
|
AddNewNodeIntoBuddy(&byte_memory->dynamic_buddy_manager,node);
|
||||||
|
@ -466,7 +484,7 @@ static void SmallMemInit(struct ByteMemory *byte_memory)
|
||||||
item = &byte_memory->static_manager[MM_SEGMENT_32B];
|
item = &byte_memory->static_manager[MM_SEGMENT_32B];
|
||||||
|
|
||||||
/* allocate memory zone for [32b] */
|
/* allocate memory zone for [32b] */
|
||||||
item->freelist = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, SMALL_SIZE_32B(SIZEOF_32B));
|
item->freelist = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, SMALL_SIZE_32B(SIZEOF_32B), DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
||||||
if(!item->freelist) {
|
if(!item->freelist) {
|
||||||
KPrintf("%s: no memory for small memory[32B].\n",__func__);
|
KPrintf("%s: no memory for small memory[32B].\n",__func__);
|
||||||
item->block_free_count = 0;
|
item->block_free_count = 0;
|
||||||
|
@ -481,14 +499,14 @@ static void SmallMemInit(struct ByteMemory *byte_memory)
|
||||||
for(offset = 0; offset < item->block_total_count; offset++) {
|
for(offset = 0; offset < item->block_total_count; offset++) {
|
||||||
node = PTR2ALLOCNODE((char*)item->freelist + offset * (SIZEOF_32B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
node = PTR2ALLOCNODE((char*)item->freelist + offset * (SIZEOF_32B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
node->size =(x_size_t) ((char*)item->freelist + (offset + 1) * (SIZEOF_32B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
node->size =(x_size_t) ((char*)item->freelist + (offset + 1) * (SIZEOF_32B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
node->prev_adj_size = STATIC_BLOCK_MASK;
|
node->flag = STATIC_BLOCK_MASK;
|
||||||
}
|
}
|
||||||
node->size = NONE;
|
node->size = NONE;
|
||||||
|
|
||||||
item = &byte_memory->static_manager[MM_SEGMENT_64B];
|
item = &byte_memory->static_manager[MM_SEGMENT_64B];
|
||||||
|
|
||||||
/* allocate memory zone for [64B] */
|
/* allocate memory zone for [64B] */
|
||||||
item->freelist = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, SMALL_SIZE_64B(SIZEOF_64B));
|
item->freelist = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, SMALL_SIZE_64B(SIZEOF_64B),DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
||||||
if(!item->freelist) {
|
if(!item->freelist) {
|
||||||
KPrintf("%s: no memory for small memory[64B].\n",__func__);
|
KPrintf("%s: no memory for small memory[64B].\n",__func__);
|
||||||
return;
|
return;
|
||||||
|
@ -502,7 +520,7 @@ static void SmallMemInit(struct ByteMemory *byte_memory)
|
||||||
for(offset = 0; offset < item->block_total_count; offset++) {
|
for(offset = 0; offset < item->block_total_count; offset++) {
|
||||||
node = PTR2ALLOCNODE((char*)item->freelist + offset * (SIZEOF_64B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
node = PTR2ALLOCNODE((char*)item->freelist + offset * (SIZEOF_64B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
node->size =(x_size_t) ((char*)item->freelist + (offset + 1) * (SIZEOF_64B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
node->size =(x_size_t) ((char*)item->freelist + (offset + 1) * (SIZEOF_64B + SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
node->prev_adj_size = STATIC_BLOCK_MASK;
|
node->flag = STATIC_BLOCK_MASK;
|
||||||
}
|
}
|
||||||
node->size = NONE;
|
node->size = NONE;
|
||||||
|
|
||||||
|
@ -548,6 +566,7 @@ static void SmallMemFree(void *pointer)
|
||||||
*/
|
*/
|
||||||
static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
|
static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
|
||||||
{
|
{
|
||||||
|
uint8 i = 0;
|
||||||
void *result = NONE;
|
void *result = NONE;
|
||||||
struct DynamicAllocNode *node = NONE;
|
struct DynamicAllocNode *node = NONE;
|
||||||
struct segment *static_segment = NONE;
|
struct segment *static_segment = NONE;
|
||||||
|
@ -564,7 +583,7 @@ static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
|
||||||
/* get the head static memory block */
|
/* get the head static memory block */
|
||||||
result = static_segment->freelist;
|
result = static_segment->freelist;
|
||||||
node = PTR2ALLOCNODE(static_segment->freelist);
|
node = PTR2ALLOCNODE(static_segment->freelist);
|
||||||
node->prev_adj_size = STATIC_BLOCK_MASK;
|
node->flag = STATIC_BLOCK_MASK;
|
||||||
|
|
||||||
/* update the statistic information of static segment */
|
/* update the statistic information of static segment */
|
||||||
static_segment->freelist = (uint8 *)(long)(node->size);
|
static_segment->freelist = (uint8 *)(long)(node->size);
|
||||||
|
@ -578,7 +597,20 @@ static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the static memory block is exhausted, now turn to dynamic buddy memory for allocation. */
|
/* the static memory block is exhausted, now turn to dynamic buddy memory for allocation. */
|
||||||
result = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, size);
|
result = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
if(NONE == result) {
|
||||||
|
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
|
if(NONE != ExtByteManager[i].done) {
|
||||||
|
result = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
||||||
|
if (result){
|
||||||
|
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,18 +629,33 @@ static struct StaticMemoryDone StaticDone = {
|
||||||
*/
|
*/
|
||||||
void *x_malloc(x_size_t size)
|
void *x_malloc(x_size_t size)
|
||||||
{
|
{
|
||||||
|
uint8 i = 0;
|
||||||
void *ret = NONE;
|
void *ret = NONE;
|
||||||
register x_base lock = 0;
|
register x_base lock = 0;
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
/* parameter detection */
|
||||||
|
if(size == 0 ){
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
if((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
|
||||||
|
lock = CriticalAreaLock();
|
||||||
|
/* alignment */
|
||||||
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
|
goto try_extmem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* parameter detection */
|
||||||
if((size == 0) || (size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory))
|
if((size == 0) || (size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory))
|
||||||
return NONE;
|
return NONE;
|
||||||
|
#endif
|
||||||
/* hold lock before allocation */
|
/* hold lock before allocation */
|
||||||
lock = CriticalAreaLock();
|
lock = CriticalAreaLock();
|
||||||
/* alignment */
|
/* alignment */
|
||||||
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
|
|
||||||
/* determine allocation operation from static segments or dynamic buddy memory */
|
/* determine allocation operation from static segments or dynamic buddy memory */
|
||||||
#ifdef KERNEL_SMALL_MEM_ALLOC
|
#ifdef KERNEL_SMALL_MEM_ALLOC
|
||||||
if(size <= SIZEOF_32B) {
|
if(size <= SIZEOF_32B) {
|
||||||
|
@ -618,10 +665,26 @@ void *x_malloc(x_size_t size)
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager,size);
|
ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
||||||
}
|
|
||||||
if(ret != NONE)
|
if(ret != NONE)
|
||||||
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
try_extmem:
|
||||||
|
if(NONE == ret) {
|
||||||
|
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
|
if(NONE != ExtByteManager[i].done) {
|
||||||
|
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
||||||
|
if (ret){
|
||||||
|
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
/* release lock */
|
/* release lock */
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -729,17 +792,77 @@ void x_free(void *pointer)
|
||||||
|
|
||||||
/* judge release the memory block ro static_segment or dynamic buddy memory */
|
/* judge release the memory block ro static_segment or dynamic buddy memory */
|
||||||
#ifdef KERNEL_SMALL_MEM_ALLOC
|
#ifdef KERNEL_SMALL_MEM_ALLOC
|
||||||
if(node->prev_adj_size & STATIC_BLOCK_MASK) {
|
if(node->flag & STATIC_BLOCK_MASK) {
|
||||||
ByteManager.static_manager->done->release(pointer);
|
ByteManager.static_manager->done->release(pointer);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
/* judge the pointer is not malloced from extern memory*/
|
||||||
|
if(0 == (node->flag & 0xFF0000)) {
|
||||||
ByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
|
ByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* judge the pointer is malloced from extern memory*/
|
||||||
|
if(0 != (node->flag & 0xFF0000)) {
|
||||||
|
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1],pointer);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
/* release the lock */
|
/* release the lock */
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
/**
|
||||||
|
* This function initializes the dynamic buddy memory of extern sram.
|
||||||
|
*
|
||||||
|
* @param start_phy_address the start physical address for static and dynamic memory
|
||||||
|
* @param end_phy_address the end physical address for static and dynamic memory
|
||||||
|
* @param extsram_idx the idx of extsram chip
|
||||||
|
*/
|
||||||
|
void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint8 extsram_idx)
|
||||||
|
{
|
||||||
|
register x_size_t offset = 0;
|
||||||
|
|
||||||
|
NULL_PARAM_CHECK(start_phy_address);
|
||||||
|
NULL_PARAM_CHECK(end_phy_address);
|
||||||
|
|
||||||
|
KDEBUG_NOT_IN_INTERRUPT;
|
||||||
|
struct DynamicBuddyMemory *uheap = &ExtByteManager[extsram_idx].dynamic_buddy_manager;
|
||||||
|
|
||||||
|
/* align begin and end addr to page */
|
||||||
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
|
||||||
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
|
||||||
|
KPrintf("%s: 0x%x-0x%x extsram_idx = %d\n",__func__,ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start,ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end, extsram_idx);
|
||||||
|
|
||||||
|
/* parameter detection */
|
||||||
|
if (ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start >= ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end) {
|
||||||
|
KPrintf("ExtSramInitBoardMemory, wrong address[0x%x - 0x%x]\n",
|
||||||
|
(x_ubase)start_phy_address, (x_ubase)end_phy_address);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uheap->mm_total_size = 0;
|
||||||
|
memset(uheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
|
||||||
|
|
||||||
|
/* initialize the freeNodeList */
|
||||||
|
for (offset = 1; offset < MEM_LINKNRS; offset++) {
|
||||||
|
uheap->mm_freenode_list[offset - 1].next = &uheap->mm_freenode_list[offset];
|
||||||
|
uheap->mm_freenode_list[offset].prev = &uheap->mm_freenode_list[offset - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.done = &DynamicDone;
|
||||||
|
ExtByteManager[extsram_idx].done = &NodeDone;
|
||||||
|
|
||||||
|
|
||||||
|
/* dynamic buddy memory initialization */
|
||||||
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.done->init(&ExtByteManager[extsram_idx].dynamic_buddy_manager, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end - ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function initializes the static segments and dynamic buddy memory structures.
|
* This function initializes the static segments and dynamic buddy memory structures.
|
||||||
*
|
*
|
||||||
|
@ -803,12 +926,28 @@ void InitBoardMemory(void *start_phy_address, void *end_phy_address)
|
||||||
*/
|
*/
|
||||||
void *x_umalloc(x_size_t size)
|
void *x_umalloc(x_size_t size)
|
||||||
{
|
{
|
||||||
|
uint8 i = 0;
|
||||||
void *ret = NONE;
|
void *ret = NONE;
|
||||||
register x_base lock = 0;
|
register x_base lock = 0;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
/* parameter detection */
|
||||||
|
if(size == 0 ){
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
if((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
|
||||||
|
lock = CriticalAreaLock();
|
||||||
|
/* alignment */
|
||||||
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
|
goto try_extmem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if((size == 0) || (size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory))
|
if((size == 0) || (size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory))
|
||||||
return NONE;
|
return NONE;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* hold lock before allocation */
|
/* hold lock before allocation */
|
||||||
lock = CriticalAreaLock();
|
lock = CriticalAreaLock();
|
||||||
|
@ -817,6 +956,22 @@ void *x_umalloc(x_size_t size)
|
||||||
ret = UserByteManager.dynamic_buddy_manager.done->malloc(&UserByteManager.dynamic_buddy_manager,size);
|
ret = UserByteManager.dynamic_buddy_manager.done->malloc(&UserByteManager.dynamic_buddy_manager,size);
|
||||||
if(ret != NONE)
|
if(ret != NONE)
|
||||||
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
try_extmem:
|
||||||
|
if(NONE == ret) {
|
||||||
|
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
|
if(NONE != ExtByteManager[i].done) {
|
||||||
|
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
||||||
|
if (ret) {
|
||||||
|
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/* release lock */
|
/* release lock */
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -920,8 +1075,21 @@ void x_ufree(void *pointer)
|
||||||
lock = CriticalAreaLock();
|
lock = CriticalAreaLock();
|
||||||
node = PTR2ALLOCNODE((char*)pointer-SIZEOF_DYNAMICALLOCNODE_MEM);
|
node = PTR2ALLOCNODE((char*)pointer-SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
CHECK(UserByteManager.done->JudgeAllocated(node));
|
CHECK(UserByteManager.done->JudgeAllocated(node));
|
||||||
UserByteManager.dynamic_buddy_manager.done->release(&UserByteManager,pointer);
|
|
||||||
|
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
/* judge the pointer is not malloced from extern memory*/
|
||||||
|
if(0 == (node->flag & 0xFF0000)) {
|
||||||
|
UserByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* judge the pointer is malloced from extern memory*/
|
||||||
|
if(0 != (node->flag & 0xFF0000)) {
|
||||||
|
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1],pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
UserByteManager.dynamic_buddy_manager.done->release(&UserByteManager,pointer);
|
||||||
|
#endif
|
||||||
/* release the lock */
|
/* release the lock */
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
}
|
}
|
||||||
|
@ -1005,10 +1173,21 @@ void ShowMemory(void);
|
||||||
*/
|
*/
|
||||||
void ShowMemory(void)
|
void ShowMemory(void)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
KPrintf("total memory: %d\n", ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start);
|
KPrintf("total memory: %d\n", ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start);
|
||||||
KPrintf("used memory : %d\n", ByteManager.dynamic_buddy_manager.active_memory);
|
KPrintf("used memory : %d\n", ByteManager.dynamic_buddy_manager.active_memory);
|
||||||
KPrintf("maximum allocated memory: %d\n", ByteManager.dynamic_buddy_manager.max_ever_usedmem);
|
KPrintf("maximum allocated memory: %d\n", ByteManager.dynamic_buddy_manager.max_ever_usedmem);
|
||||||
KPrintf("total cache szie: %d, %d/%d[32B],%d/%d[64B]\n", ByteManager.dynamic_buddy_manager.static_memory,ByteManager.static_manager[0].block_free_count,SMALL_NUMBER_32B,ByteManager.static_manager[1].block_free_count,SMALL_NUMBER_64B);
|
KPrintf("total cache szie: %d, %d/%d[32B],%d/%d[64B]\n", ByteManager.dynamic_buddy_manager.static_memory,ByteManager.static_manager[0].block_free_count,SMALL_NUMBER_32B,ByteManager.static_manager[1].block_free_count,SMALL_NUMBER_64B);
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
|
if(NONE != ExtByteManager[i].done){
|
||||||
|
KPrintf("\nlist extern sram[%d] memory information\n\n",i);
|
||||||
|
KPrintf("extern sram total memory: %d\n", ExtByteManager[i].dynamic_buddy_manager.dynamic_buddy_end - ExtByteManager[i].dynamic_buddy_manager.dynamic_buddy_start);
|
||||||
|
KPrintf("extern sram used memory : %d\n", ExtByteManager[i].dynamic_buddy_manager.active_memory);
|
||||||
|
KPrintf("extern sram maximum allocated memory: %d\n", ExtByteManager[i].dynamic_buddy_manager.max_ever_usedmem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
ShowBuddy();
|
ShowBuddy();
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
||||||
|
@ -1018,6 +1197,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHE
|
||||||
*/
|
*/
|
||||||
void ShowBuddy(void)
|
void ShowBuddy(void)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
int lock = 0;
|
int lock = 0;
|
||||||
struct DynamicFreeNode *debug = NONE;
|
struct DynamicFreeNode *debug = NONE;
|
||||||
|
|
||||||
|
@ -1025,9 +1205,21 @@ void ShowBuddy(void)
|
||||||
KPrintf("\n\033[41;1mlist memory information\033[0m\n", __func__);
|
KPrintf("\n\033[41;1mlist memory information\033[0m\n", __func__);
|
||||||
for (debug = ByteManager.dynamic_buddy_manager.mm_freenode_list[0].next;
|
for (debug = ByteManager.dynamic_buddy_manager.mm_freenode_list[0].next;
|
||||||
debug;debug = debug->next){
|
debug;debug = debug->next){
|
||||||
KPrintf("%s,current is %x,next is %x, size %u, flag %x\n",__func__, debug, debug->next,debug->size,debug->prev_adj_size & ALLOC_BLOCK_MASK);
|
KPrintf("%s,current is %x,next is %x, size %u, flag %x\n",__func__, debug, debug->next,debug->size,debug->flag);
|
||||||
};
|
};
|
||||||
KPrintf("\nlist memory information\n\n");
|
KPrintf("\nlist memory information\n\n");
|
||||||
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
|
if(NONE != ExtByteManager[i].done){
|
||||||
|
KPrintf("\nlist extern sram[%d] memory information\n\n",i);
|
||||||
|
for (debug = ExtByteManager[i].dynamic_buddy_manager.mm_freenode_list[0].next;
|
||||||
|
debug;debug = debug->next){
|
||||||
|
KPrintf("%s,current is %x,next is %x, size %u, flag %x\n",__func__, debug, debug->next,debug->size,debug->flag);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
||||||
|
|
Loading…
Reference in New Issue