diff --git a/bsp/stm32f7-disco/SConstruct b/bsp/stm32f7-disco/SConstruct index 6ea007ee9..af8f4a90b 100644 --- a/bsp/stm32f7-disco/SConstruct +++ b/bsp/stm32f7-disco/SConstruct @@ -20,6 +20,7 @@ TARGET = 'rtthread-stm32f7xx.' + rtconfig.TARGET_EXT env = Environment(tools = ['mingw'], AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, + CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS, AR = rtconfig.AR, ARFLAGS = '-rc', LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) env.PrependENVPath('PATH', rtconfig.EXEC_PATH) diff --git a/bsp/stm32f7-disco/applications/SConscript b/bsp/stm32f7-disco/applications/SConscript index 7e46cf27f..7a6bbeceb 100644 --- a/bsp/stm32f7-disco/applications/SConscript +++ b/bsp/stm32f7-disco/applications/SConscript @@ -3,7 +3,7 @@ from building import * cwd = GetCurrentDir() src = Glob('*.c') -CPPPATH = [cwd] +CPPPATH = [cwd, str(Dir('#'))] group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/stm32f7-disco/applications/application.c b/bsp/stm32f7-disco/applications/application.c index c8491a53f..e1dafdf5b 100644 --- a/bsp/stm32f7-disco/applications/application.c +++ b/bsp/stm32f7-disco/applications/application.c @@ -26,35 +26,9 @@ #include #include -#include "drv_led.h" - -static void led_thread_entry(void *parameter) -{ - - led_hw_init(); - - while (1) - { - led_on(); - rt_thread_delay(RT_TICK_PER_SECOND); - led_off(); - rt_thread_delay(RT_TICK_PER_SECOND); - } -} - void rt_init_thread_entry(void *parameter) { - - rt_thread_t tid; - rt_components_init(); - - tid = rt_thread_create("led", - led_thread_entry, RT_NULL, - 512, 12, 5); - - if (tid != RT_NULL) - rt_thread_startup(tid); } int rt_application_init() @@ -64,11 +38,7 @@ int rt_application_init() tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX / 3, 20); - - if (tid != RT_NULL) - rt_thread_startup(tid); + if (tid != RT_NULL) rt_thread_startup(tid); return 0; } - -/*@}*/ diff --git a/bsp/stm32f7-disco/applications/startup.c b/bsp/stm32f7-disco/applications/startup.c index 1ac917677..628a80504 100644 --- a/bsp/stm32f7-disco/applications/startup.c +++ b/bsp/stm32f7-disco/applications/startup.c @@ -26,6 +26,7 @@ #include #include #include "board.h" + #ifdef RT_USING_EXT_SDRAM #include "drv_sdram.h" #include "sram.h" @@ -61,8 +62,8 @@ void assert_failed(uint8_t* file, uint32_t line) while (1) {} } - #endif + /** * This function will startup RT-Thread RTOS. */ @@ -113,7 +114,7 @@ void rtthread_startup(void) int main(void) { /* disable interrupt first */ - //rt_hw_interrupt_disable(); + rt_hw_interrupt_disable(); /* startup RT-Thread RTOS */ rtthread_startup(); diff --git a/bsp/stm32f7-disco/drivers/board.c b/bsp/stm32f7-disco/drivers/board.c index 4d5c0d616..734ecf209 100644 --- a/bsp/stm32f7-disco/drivers/board.c +++ b/bsp/stm32f7-disco/drivers/board.c @@ -69,16 +69,18 @@ static void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 400; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - HAL_RCC_OscConfig(&RCC_OscInitStruct); + RCC_OscInitStruct.PLL.PLLQ = 8; + + ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); + if(ret != HAL_OK) + { + while(1) { ; } + } ret = HAL_PWREx_EnableOverDrive(); - if (ret != HAL_OK) { - while (1) - { - ; - } + while (1) { ; } } /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 @@ -88,7 +90,11 @@ static void SystemClock_Config(void) RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6); + ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6); + if (ret != HAL_OK) + { + while (1) { ; } + } } /** @@ -115,18 +121,46 @@ static void CPU_CACHE_Enable(void) */ void SysTick_Handler(void) { - /* tick for HAL Library */ - HAL_IncTick(); - /* enter interrupt */ rt_interrupt_enter(); + /* tick for HAL Library */ + HAL_IncTick(); + rt_tick_increase(); /* leave interrupt */ rt_interrupt_leave(); } +/* re-implementat tick interface for STM32 HAL */ +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) +{ + /*Configure the SysTick to have interrupt in 1ms time basis*/ + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/RT_TICK_PER_SECOND); + + /*Configure the SysTick IRQ priority */ + HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); + + /* Return function status */ + return HAL_OK; +} + +void HAL_Delay(__IO uint32_t Delay) +{ + rt_thread_delay(Delay); +} + +void HAL_SuspendTick(void) +{ + /* we should not suspend tick */ +} + +void HAL_ResumeTick(void) +{ + /* we should not resume tick */ +} + /** * This function will initial STM32 board. */ diff --git a/bsp/stm32f7-disco/drivers/drv_led.c b/bsp/stm32f7-disco/drivers/drv_led.c index a58c5f3b6..be86615b2 100644 --- a/bsp/stm32f7-disco/drivers/drv_led.c +++ b/bsp/stm32f7-disco/drivers/drv_led.c @@ -21,9 +21,22 @@ * Date Author Notes * 2015-08-01 xiaonong the first version */ - +#include #include +#include "drv_led.h" + +static void led_thread_entry(void *parameter) +{ + while (1) + { + led_on(); + rt_thread_delay(RT_TICK_PER_SECOND); + led_off(); + rt_thread_delay(RT_TICK_PER_SECOND); + } +} + int led_hw_init(void) { GPIO_InitTypeDef GPIO_InitStruct; @@ -39,5 +52,19 @@ int led_hw_init(void) HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); return 0; } +INIT_BOARD_EXPORT(led_hw_init); +int led_init(void) +{ + rt_thread_t tid; + tid = rt_thread_create("led", + led_thread_entry, RT_NULL, + 512, 12, 5); + + if (tid != RT_NULL) + rt_thread_startup(tid); + + return 0; +} +INIT_APP_EXPORT(led_init); diff --git a/bsp/stm32f7-disco/drivers/drv_mpu.c b/bsp/stm32f7-disco/drivers/drv_mpu.c index 284887846..4cab4d228 100644 --- a/bsp/stm32f7-disco/drivers/drv_mpu.c +++ b/bsp/stm32f7-disco/drivers/drv_mpu.c @@ -47,6 +47,36 @@ void mpu_init(void) HAL_MPU_ConfigRegion(&MPU_InitStruct); + /* Configure the MPU attributes as WB for SDRAM */ + MPU_InitStruct.Enable = MPU_REGION_ENABLE; + MPU_InitStruct.BaseAddress = 0xC0000000; + MPU_InitStruct.Size = MPU_REGION_SIZE_8MB; + MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; + MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE; + MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; + MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; + MPU_InitStruct.Number = MPU_REGION_NUMBER1; + MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0; + MPU_InitStruct.SubRegionDisable = 0x00; + MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; + + HAL_MPU_ConfigRegion(&MPU_InitStruct); + + /* Configure the MPU attributes as none-cache for 1MB SDRAM */ + MPU_InitStruct.Enable = MPU_REGION_ENABLE; + MPU_InitStruct.BaseAddress = 0xC0100000; + MPU_InitStruct.Size = MPU_REGION_SIZE_1MB; + MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; + MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE; + MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE; + MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; + MPU_InitStruct.Number = MPU_REGION_NUMBER2; + MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0; + MPU_InitStruct.SubRegionDisable = 0x00; + MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; + + HAL_MPU_ConfigRegion(&MPU_InitStruct); + /* Enable the MPU */ HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); } diff --git a/bsp/stm32f7-disco/drivers/drv_sdram.c b/bsp/stm32f7-disco/drivers/drv_sdram.c index fd61b83ae..4b58e21d0 100644 --- a/bsp/stm32f7-disco/drivers/drv_sdram.c +++ b/bsp/stm32f7-disco/drivers/drv_sdram.c @@ -24,12 +24,10 @@ #include "drv_sdram.h" - static SDRAM_HandleTypeDef sdramHandle; static FMC_SDRAM_TimingTypeDef Timing; static FMC_SDRAM_CommandTypeDef Command; - /** * @brief Initializes SDRAM MSP. * @param hsdram: SDRAM handle @@ -162,8 +160,11 @@ static void SDRAM_InitializationSequence(uint32_t RefreshCount) /* Step 2: Insert 100 us minimum delay */ /* Inserted delay is equal to 1 ms due to systick time base unit (ms) */ - HAL_Delay(1); - + // HAL_Delay(1); + /* interrupt is not enable, just to delay some time. */ + for (tmpmrd = 0; tmpmrd < 0xfffff; tmpmrd ++) + ; + /* Step 3: Configure a PALL (precharge all) command */ Command.CommandMode = FMC_SDRAM_CMD_PALL; Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; @@ -361,94 +362,3 @@ void SDRAM_DMA_IRQHandler(void) { HAL_DMA_IRQHandler(sdramHandle.hdma); } - - - -#ifdef RT_USING_FINSH -#include -int sdram_test(void) -{ - uint32_t i; - volatile uint32_t *wr_ptr; - volatile uint8_t *char_wr_ptr; - volatile uint16_t *short_wr_ptr; - - /* initialize memory */ - rt_kprintf("SDRAM初始化...\r\n"); - - wr_ptr = (uint32_t *)SDRAM_DEVICE_ADDR; - char_wr_ptr = (uint8_t *)wr_ptr; - /* 进行8位数据写测试前先清除数据*/ - rt_kprintf("清除SDRAM数据...\r\n"); - for (i = 0; i < SDRAM_DEVICE_SIZE / 4; i++) - { - *wr_ptr++ = 0x00; //写入0x00 - } - - /* 8 bit write */ - rt_kprintf("写入8位数据...\r\n"); - for (i = 0; i < SDRAM_DEVICE_SIZE / 4; i++) - { - *char_wr_ptr++ = 0x11; - *char_wr_ptr++ = 0x22; - *char_wr_ptr++ = 0x33; - *char_wr_ptr++ = 0x44; - } - - /* 校验写入的数据*/ - rt_kprintf("校验数据...\r\n"); - wr_ptr = (uint32_t *)SDRAM_DEVICE_ADDR; - for (i = 0; i < SDRAM_DEVICE_SIZE / 8; i++) - { - if (*wr_ptr != 0x44332211) /* be aware of endianess */ - { - /* byte comparison failure */ - rt_kprintf("校验失败,测试完毕!\r\n"); - return 1; /* fatal error */ - } - wr_ptr++; - } - - /* byte comparison succeed. */ - rt_kprintf("继续测试16位数据写入...\r\n"); - wr_ptr = (uint32_t *)SDRAM_DEVICE_ADDR; - short_wr_ptr = (uint16_t *)wr_ptr; - - /* Clear content before 16 bit access test */ - rt_kprintf("清除SDRAM中的数据...\r\n"); - for (i = 0; i < SDRAM_DEVICE_SIZE / 4; i++) - { - *wr_ptr++ = 0; - } - - /* 16 bit write */ - rt_kprintf("写入16位数据...\r\n"); - for (i = 0; i < (SDRAM_DEVICE_SIZE / 4); i++) - { - *short_wr_ptr++ = 0x5AA5; - *short_wr_ptr++ = 0xAA55; - } - - /* Verifying */ - wr_ptr = (uint32_t *)SDRAM_DEVICE_ADDR; - - //wr_ptr -= SDRAM_BASE_ADDR/4; - for (i = 0; i < SDRAM_DEVICE_SIZE / 4; i++) - { - if (*wr_ptr != 0xAA555AA5) /* be aware of endianess */ - { - /* 16-bit half word failure */ - rt_kprintf("校验失败,测试完毕!\r\n"); - return 1; /* fatal error */ - } - wr_ptr++; - } - - /* 16-bit half word comparison succeed. */ - - rt_kprintf("校验成功,测试完毕!\r\n"); - return 0; -} - -FINSH_FUNCTION_EXPORT(sdram_test, SDRAM read write test) -#endif diff --git a/bsp/stm32f7-disco/drivers/drv_usart.c b/bsp/stm32f7-disco/drivers/drv_usart.c index 58e25ba39..907849c51 100644 --- a/bsp/stm32f7-disco/drivers/drv_usart.c +++ b/bsp/stm32f7-disco/drivers/drv_usart.c @@ -44,8 +44,6 @@ #define USART1_RX_GPIO_PORT GPIOB #define USART1_RX_AF GPIO_AF7_USART1 - - /* STM32 uart driver */ struct stm32_uart { @@ -291,13 +289,11 @@ int stm32_hw_usart_init(void) serial1.config = config; /* register UART1 device */ - rt_hw_serial_register(&serial1, - "uart1", + rt_hw_serial_register(&serial1, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); #endif /* RT_USING_UART1 */ - return 0; } INIT_BOARD_EXPORT(stm32_hw_usart_init); diff --git a/bsp/stm32f7-disco/drivers/stm32f7xx_it.c b/bsp/stm32f7-disco/drivers/stm32f7xx_it.c index aa3baef2f..899d4da11 100644 --- a/bsp/stm32f7-disco/drivers/stm32f7xx_it.c +++ b/bsp/stm32f7-disco/drivers/stm32f7xx_it.c @@ -69,19 +69,6 @@ void NMI_Handler(void) { } -/** - * @brief This function handles Memory Manage exception. - * @param None - * @retval None - */ -void MemManage_Handler(void) -{ - /* Go to infinite loop when Memory Manage exception occurs */ - while (1) - { - } -} - /** * @brief This function handles Bus Fault exception. * @param None diff --git a/bsp/stm32f7-disco/rtconfig.h b/bsp/stm32f7-disco/rtconfig.h index 98c2599d2..bd0aaed39 100644 --- a/bsp/stm32f7-disco/rtconfig.h +++ b/bsp/stm32f7-disco/rtconfig.h @@ -14,7 +14,7 @@ // 256 // #define RT_THREAD_PRIORITY_MAX 32 -// +// #define RT_TICK_PER_SECOND 1000 // #define IDLE_THREAD_STACK_SIZE 512 @@ -141,16 +141,16 @@ // 3 // #define RT_DFS_ELM_USE_LFN 3 -// -#define RT_DFS_ELM_CODE_PAGE 936 +// +#define RT_DFS_ELM_CODE_PAGE 437 // -#define RT_DFS_ELM_CODE_PAGE_FILE +// #define RT_DFS_ELM_CODE_PAGE_FILE // #define RT_DFS_ELM_MAX_LFN 256 // #define RT_DFS_ELM_MAX_SECTOR_SIZE 4096 // -#define RT_DFS_ELM_USE_ERASE +// #define RT_DFS_ELM_USE_ERASE // // #define RT_USING_DFS_YAFFS2 // @@ -160,7 +160,7 @@ // //#define RT_USING_DFS_ROMFS // -#define RT_USING_DFS_NFS +// #define RT_USING_DFS_NFS // #define RT_NFS_HOST_EXPORT "192.168.137.1:/" // @@ -223,6 +223,7 @@ // // + /* enable SDRAM */ #define RT_USING_EXT_SDRAM diff --git a/bsp/stm32f7-disco/rtconfig.py b/bsp/stm32f7-disco/rtconfig.py index 475bdd500..91ef8db8b 100644 --- a/bsp/stm32f7-disco/rtconfig.py +++ b/bsp/stm32f7-disco/rtconfig.py @@ -3,10 +3,12 @@ import os # toolchains options ARCH='arm' CPU='cortex-m7' -CROSS_TOOL='keil' +CROSS_TOOL='gcc' if os.getenv('RTT_CC'): CROSS_TOOL = os.getenv('RTT_CC') +if os.getenv('RTT_ROOT'): + RTT_ROOT = os.getenv('RTT_ROOT') # cross_tool provides the cross compiler # EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR @@ -23,7 +25,7 @@ elif CROSS_TOOL == 'iar': exit(0) if os.getenv('RTT_EXEC_PATH'): - EXEC_PATH = os.getenv('RTT_EXEC_PATH') + EXEC_PATH = os.getenv('RTT_EXEC_PATH') BUILD = 'debug' STM32_TYPE = 'STM32F756xx' @@ -32,6 +34,7 @@ if PLATFORM == 'gcc': # toolchains PREFIX = 'arm-none-eabi-' CC = PREFIX + 'gcc' + CXX = PREFIX + 'g++' AS = PREFIX + 'gcc' AR = PREFIX + 'ar' LINK = PREFIX + 'gcc' @@ -39,6 +42,7 @@ if PLATFORM == 'gcc': SIZE = PREFIX + 'size' OBJDUMP = PREFIX + 'objdump' OBJCPY = PREFIX + 'objcopy' + STRIP = PREFIX + 'strip' DEVICE = ' -mcpu=cortex-m7 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections' CFLAGS = DEVICE + ' -g -Wall -DSTM32F756xx -DUSE_HAL_DRIVER -D__ASSEMBLY__ -D__FPU_USED' @@ -52,13 +56,22 @@ if PLATFORM == 'gcc': CFLAGS += ' -O0 -gdwarf-2' AFLAGS += ' -gdwarf-2' else: - CFLAGS += ' -O2' + CFLAGS += ' -O2 -Os' POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' + # module setting + CXXFLAGS = ' -Woverloaded-virtual -fno-exceptions -fno-rtti ' + M_CFLAGS = CFLAGS + ' -mlong-calls -fPIC ' + M_CXXFLAGS = CXXFLAGS + ' -mlong-calls -fPIC' + M_LFLAGS = DEVICE + CXXFLAGS + ' -Wl,--gc-sections,-z,max-page-size=0x4' +\ + ' -shared -fPIC -nostartfiles -static-libgcc' + M_POST_ACTION = STRIP + ' -R .hash $TARGET\n' + SIZE + ' $TARGET \n' + elif PLATFORM == 'armcc': # toolchains CC = 'armcc' + CXX = 'armcc' AS = 'armasm' AR = 'armar' LINK = 'armlink' @@ -78,8 +91,9 @@ elif PLATFORM == 'armcc': CFLAGS += ' -g -O0' AFLAGS += ' -g' else: - CFLAGS += ' -O2' + CFLAGS += ' -O2 -Otime' + CXXFLAGS = CFLAGS POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET' elif PLATFORM == 'iar': diff --git a/components/dfs/filesystems/lwip/lwip_select.c b/components/dfs/filesystems/lwip/lwip_select.c index 7e97d3741..3477b6f1d 100644 --- a/components/dfs/filesystems/lwip/lwip_select.c +++ b/components/dfs/filesystems/lwip/lwip_select.c @@ -27,6 +27,8 @@ #ifdef RT_USING_LWIP +#include "dfs_lwip.h" + int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) @@ -70,7 +72,7 @@ select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, if (maxfd == 0) return -EBADF; maxfd += 1; - result = lwip_selscan(maxfd, &sock_readset, &sock_writeset, &sock_exceptset, timeout); + result = lwip_select(maxfd, &sock_readset, &sock_writeset, &sock_exceptset, timeout); if (readset) FD_ZERO(readset); if (writeset) FD_ZERO(writeset); diff --git a/libcpu/arm/cortex-m7/context_rvds.S b/libcpu/arm/cortex-m7/context_rvds.S index fa7a1c90f..53a375678 100644 --- a/libcpu/arm/cortex-m7/context_rvds.S +++ b/libcpu/arm/cortex-m7/context_rvds.S @@ -221,7 +221,9 @@ rt_hw_interrupt_thread_switch PROC IMPORT rt_hw_hard_fault_exception EXPORT HardFault_Handler + EXPORT MemManage_Handler HardFault_Handler PROC +MemManage_Handler ; get current context MRS r0, psp ; get fault thread stack pointer