diff --git a/.config b/.config index fd91bd2..f373028 100644 --- a/.config +++ b/.config @@ -20,7 +20,7 @@ CONFIG_RT_USING_HOOK=y CONFIG_RT_HOOK_USING_FUNC_PTR=y CONFIG_RT_USING_IDLE_HOOK=y CONFIG_RT_IDLE_HOOK_LIST_SIZE=4 -CONFIG_IDLE_THREAD_STACK_SIZE=256 +CONFIG_IDLE_THREAD_STACK_SIZE=1024 # CONFIG_RT_USING_TIMER_SOFT is not set # @@ -32,7 +32,8 @@ CONFIG_IDLE_THREAD_STACK_SIZE=256 # CONFIG_RT_KPRINTF_USING_LONGLONG is not set CONFIG_RT_DEBUG=y CONFIG_RT_DEBUG_COLOR=y -# CONFIG_RT_DEBUG_INIT_CONFIG is not set +CONFIG_RT_DEBUG_INIT_CONFIG=y +CONFIG_RT_DEBUG_INIT=1 # CONFIG_RT_DEBUG_THREAD_CONFIG is not set # CONFIG_RT_DEBUG_SCHEDULER_CONFIG is not set # CONFIG_RT_DEBUG_IPC_CONFIG is not set @@ -90,7 +91,7 @@ CONFIG_ARCH_ARM_CORTEX_M4=y # CONFIG_RT_USING_COMPONENTS_INIT=y CONFIG_RT_USING_USER_MAIN=y -CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048 +CONFIG_RT_MAIN_THREAD_STACK_SIZE=4096 CONFIG_RT_MAIN_THREAD_PRIORITY=10 # CONFIG_RT_USING_LEGACY is not set CONFIG_RT_USING_MSH=y @@ -109,7 +110,11 @@ CONFIG_FINSH_USING_DESCRIPTION=y # CONFIG_FINSH_USING_AUTH is not set CONFIG_FINSH_ARG_MAX=10 # CONFIG_RT_USING_DFS is not set -# CONFIG_RT_USING_FAL is not set +CONFIG_RT_USING_FAL=y +CONFIG_FAL_DEBUG_CONFIG=y +CONFIG_FAL_DEBUG=1 +CONFIG_FAL_PART_HAS_TABLE_CFG=y +# CONFIG_FAL_USING_SFUD_PORT is not set # CONFIG_RT_USING_LWP is not set # @@ -192,7 +197,8 @@ CONFIG_RT_USING_CPLUSPLUS=y # # Utilities # -# CONFIG_RT_USING_RYM is not set +CONFIG_RT_USING_RYM=y +# CONFIG_YMODEM_USING_CRC_TABLE is not set # CONFIG_RT_USING_ULOG is not set # CONFIG_RT_USING_UTEST is not set # CONFIG_RT_USING_VAR_EXPORT is not set @@ -719,7 +725,7 @@ CONFIG_BSP_UART2_TX_USING_DMA=y # CONFIG_BSP_USING_ADC is not set # CONFIG_BSP_USING_ONCHIP_RTC is not set # CONFIG_BSP_USING_WDT is not set -# CONFIG_BSP_USING_ON_CHIP_FLASH is not set +CONFIG_BSP_USING_ON_CHIP_FLASH=y # CONFIG_BSP_USING_USBD is not set # CONFIG_BSP_USING_RNG is not set # CONFIG_BSP_USING_UDID is not set diff --git a/board/Kconfig b/board/Kconfig index a1608df..3f66c2a 100644 --- a/board/Kconfig +++ b/board/Kconfig @@ -165,6 +165,7 @@ menu "On-chip Peripheral Drivers" config BSP_USING_ON_CHIP_FLASH bool "Enable on-chip FLASH" + select RT_USING_FAL default n config BSP_USING_USBD diff --git a/board/board.c b/board/board.c index c14a42b..0e5d30a 100644 --- a/board/board.c +++ b/board/board.c @@ -59,3 +59,16 @@ void SystemClock_Config(void) */ HAL_RCC_EnableCSS(); } + +// init ports +extern int cplusplus_system_init(void); +INIT_COMPONENT_EXPORT(cplusplus_system_init); + +extern void fal(uint8_t argc, char **argv); +MSH_CMD_EXPORT(fal, FAL (Flash Abstraction Layer) operate.); + +extern int fal_init(void); +INIT_ENV_EXPORT(fal_init); + +extern int iap_main_entry(void); +INIT_ENV_EXPORT(iap_main_entry); diff --git a/board/fal_cfg.h b/board/fal_cfg.h new file mode 100644 index 0000000..14d751e --- /dev/null +++ b/board/fal_cfg.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-12-5 SummerGift first version + */ + +#ifndef _FAL_CFG_H_ +#define _FAL_CFG_H_ + +#include +#include + +#define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024) +#define FLASH_SIZE_GRANULARITY_64K (64 * 1024) +#define FLASH_SIZE_GRANULARITY_128K (7 * 128 * 1024) + +#define STM32_FLASH_START_ADRESS_16K STM32_FLASH_START_ADRESS +#define STM32_FLASH_START_ADRESS_64K (STM32_FLASH_START_ADRESS_16K + FLASH_SIZE_GRANULARITY_16K) +#define STM32_FLASH_START_ADRESS_128K (STM32_FLASH_START_ADRESS_64K + FLASH_SIZE_GRANULARITY_64K) + +#define FLASH_SIZE_APP (5 * 128 * 1024) +#define FLASH_SIZE_LOG (2 * 128 * 1024) + +#define FLASH_OFFSET_LOG (FLASH_SIZE_APP) + +extern const struct fal_flash_dev stm32_onchip_flash_16k; +extern const struct fal_flash_dev stm32_onchip_flash_64k; +extern const struct fal_flash_dev stm32_onchip_flash_128k; + +/* flash device table */ +#define FAL_FLASH_DEV_TABLE \ +{ \ + &stm32_onchip_flash_16k, \ + &stm32_onchip_flash_64k, \ + &stm32_onchip_flash_128k, \ +} +/* ====================== Partition Configuration ========================== */ +#ifdef FAL_PART_HAS_TABLE_CFG + + +/* partition table */ +/** + * @brief flash 分配: + * section addr size + * 0 - 4 0x08000000 128kb bootloader + * 5 - 9 0x08020000 640kb app + * 10 - 11 0x080C0000 256kb ulog + * + */ +#define FAL_PART_TABLE \ +{ \ + {FAL_PART_MAGIC_WROD, "boot_0", "onchip_flash_16k", 0 , FLASH_SIZE_GRANULARITY_16K , 0}, \ + {FAL_PART_MAGIC_WROD, "boot_1", "onchip_flash_64k", 0 , FLASH_SIZE_GRANULARITY_64K , 0}, \ + {FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0 , FLASH_SIZE_APP, 0}, \ + {FAL_PART_MAGIC_WROD, "ulog", "onchip_flash_128k", FLASH_OFFSET_LOG , FLASH_SIZE_LOG, 0}, \ +} + +#endif /* FAL_PART_HAS_TABLE_CFG */ +#endif /* _FAL_CFG_H_ */ diff --git a/iap/iap.c b/iap/iap.c new file mode 100644 index 0000000..8fc2e1d --- /dev/null +++ b/iap/iap.c @@ -0,0 +1,399 @@ +#include "rtthread.h" +#include "ipc/completion.h" +#include "ymodem.h" + +#include "fal.h" +#define IAP_FLASH_SEC "app" + +static rt_device_t console_dev; +struct rt_completion _wait; + +#define IS_AF(c) ((c >= 'A') && (c <= 'F')) +#define IS_af(c) ((c >= 'a') && (c <= 'f')) +#define IS_09(c) ((c >= '0') && (c <= '9')) +#define ISVALIDHEX(c) IS_AF(c) || IS_af(c) || IS_09(c) +#define ISVALIDDEC(c) IS_09(c) +#define CONVERTDEC(c) (c - '0') + +#define CONVERTHEX_alpha(c) (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10)) +#define CONVERTHEX(c) (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c)) + +/** + * @brief Convert a string to an integer + * @param inputstr: The string to be converted + * @param intnum: The intger value + * @retval 1: Correct + * 0: Error + */ +rt_inline rt_uint32_t Str2Int(uint8_t *inputstr, int32_t *intnum) +{ + rt_uint32_t i = 0, res = 0; + rt_uint32_t val = 0; + + if (inputstr[0] == '0' && (inputstr[1] == 'x' || inputstr[1] == 'X')) + { + if (inputstr[2] == '\0') + { + return 0; + } + for (i = 2; i < 11; i++) + { + if (inputstr[i] == '\0') + { + *intnum = val; + /* return 1; */ + res = 1; + break; + } + if (ISVALIDHEX(inputstr[i])) + { + val = (val << 4) + CONVERTHEX(inputstr[i]); + } + else + { + /* return 0, Invalid input */ + res = 0; + break; + } + } + /* over 8 digit hex --invalid */ + if (i >= 11) + { + res = 0; + } + } + else /* max 10-digit decimal input */ + { + for (i = 0;i < 11;i++) + { + if (inputstr[i] == '\0') + { + *intnum = val; + /* return 1 */ + res = 1; + break; + } + else if ((inputstr[i] == 'k' || inputstr[i] == 'K') && (i > 0)) + { + val = val << 10; + *intnum = val; + res = 1; + break; + } + else if ((inputstr[i] == 'm' || inputstr[i] == 'M') && (i > 0)) + { + val = val << 20; + *intnum = val; + res = 1; + break; + } + else if (ISVALIDDEC(inputstr[i])) + { + val = val * 10 + CONVERTDEC(inputstr[i]); + } + else + { + /* return 0, Invalid input */ + res = 0; + break; + } + } + /* Over 10 digit decimal --invalid */ + if (i >= 11) + { + res = 0; + } + } + + return res; +} + +rt_err_t port_rx_ind(rt_device_t dev, rt_size_t size) +{ + rt_completion_done(&_wait); + return RT_EOK; +} + +#define RT_BUF_SIZE (1024) + +struct custom_ctx { + struct rym_ctx parent; + int32_t file_size; + int32_t w_index; + const struct fal_partition *flash; + rt_uint8_t ck_buffer[RT_BUF_SIZE]; +}; + +static enum rym_code _rym_recv_begin( + struct rym_ctx *ctx, + rt_uint8_t *buf, + rt_size_t len) +{ + // return RYM_ERR_ACK; + // return RYM_CODE_CAN; + struct custom_ctx *cctx = (struct custom_ctx *) ctx; + RT_ASSERT(cctx); + + rt_uint8_t tmp_size[16] = {0}; + while (*buf != 0) + { + buf ++; + } + buf ++; + + rt_bool_t end = RT_FALSE; + for (rt_uint8_t i = 0; i < 16; i++) + { + if (*buf == 0) + { + tmp_size[i] = 0; + end = RT_TRUE; + break; + } + + tmp_size[i] = *buf++; + } + if (!end) + { + return RYM_CODE_CAN; + } + if (!Str2Int(tmp_size, &cctx->file_size)) + { + return RYM_CODE_CAN; + } + + if (cctx->file_size >= cctx->flash->len) + { + return RYM_CODE_CAN; + } + + if (fal_partition_erase(cctx->flash, 0, cctx->file_size) < 0) + { + return RYM_CODE_CAN; + } + cctx->w_index = 0; + + return RYM_CODE_ACK; +} + +static enum rym_code _rym_recv_data( + struct rym_ctx *ctx, + rt_uint8_t *buf, + rt_size_t len) +{ + struct custom_ctx *cctx = (struct custom_ctx *) ctx; + RT_ASSERT(cctx); + RT_ASSERT(len <= RT_BUF_SIZE); + + if (cctx->w_index >= cctx->file_size) + { + return RYM_CODE_ACK; + } + + if (cctx->w_index + len > cctx->file_size) + { + len = cctx->file_size - cctx->w_index; + } + + if (fal_partition_write(cctx->flash, cctx->w_index, buf, len) <= 0) + { + return RYM_CODE_CAN; + } + + if (fal_partition_read(cctx->flash, cctx->w_index, cctx->ck_buffer, len) <= 0) + { + return RYM_CODE_CAN; + } + + for (int i = 0; i < len; i++) + { + if (cctx->ck_buffer[i] != buf[i]) + return RYM_CODE_CAN; + } + cctx->w_index += len; + + return RYM_CODE_ACK; +} + +static enum rym_code _rym_recv_end( + struct rym_ctx *ctx, + rt_uint8_t *buf, + rt_size_t len) +{ + return RYM_CODE_ACK; +} + +enum iap_v5_cmd +{ + IAP_V5_CMD_ONE_REPLY = 1, + IAP_V5_CMD_C_REPLY, + IAP_V5_CMD_UPDATE_SUCCEED, + IAP_V5_CMD_UPDATE_FAILED, + IAP_V5_CMD_BIN_OVERSIZE, + IAP_V5_CMD_CHECK_FAILED, + IAP_V5_CMD_USER_CANCEL, + IAP_V5_CMD_RECEIVE_FAILED, + IAP_V5_CMD_POWER_ON_AGAIN, +}; + +/** + * @brief 响应协议 + * + * 0xB5,0x5B,{cmd},0xBB, 0x00 + */ +#define IAP_V5_CMD_SIZE (5) + +static const rt_uint8_t *_pack_cmd(enum iap_v5_cmd cmd) +{ + static rt_uint8_t _cmd_line[IAP_V5_CMD_SIZE] + = { 0xB5, 0x5B, 0x00, 0xBB, 0x00 }; + + _cmd_line[2] = cmd; + return _cmd_line; +} + +#define _response_cmd(cmd) \ + rt_device_write(console_dev, 0, _pack_cmd(cmd), IAP_V5_CMD_SIZE) + +static rt_bool_t iap_v5_req_char(rt_device_t console_dev, + struct rt_completion *_wait, + rt_uint8_t want, + rt_tick_t wait) +{ + rt_uint8_t ch; + rt_tick_t start = rt_tick_get(); + rt_bool_t rt = RT_FALSE; + + while (rt_tick_get() - start < wait) + { + if (rt_device_read(console_dev, 0, &ch, 1) == 1) + { + if (ch == want) + { + rt = RT_TRUE; + break; + } + + continue; + } + + if (rt_completion_wait(_wait, wait - (rt_tick_get() - start)) + != RT_EOK) + { + break; + } + } + + return rt; +} + +static void jump_to_app(void); +extern const uint32_t IapAppAddr; + +int iap_main_entry(void) +{ + if (IapAppAddr) + { + return 0; + } + + rt_err_t (*odev_rx_ind)(rt_device_t dev, rt_size_t size); + rt_err_t err = RT_EOK; + struct custom_ctx *ctx = RT_NULL; + + console_dev = rt_console_get_device(); + RT_ASSERT(console_dev); + + rt_completion_init(&_wait); + odev_rx_ind = console_dev->rx_indicate; + rt_device_set_rx_indicate(console_dev, port_rx_ind); + + if (!iap_v5_req_char(console_dev, &_wait, '1', 1000)) + { + goto _exit; + } + _response_cmd(IAP_V5_CMD_ONE_REPLY); + + rt_thread_mdelay(200); + if (!iap_v5_req_char(console_dev, &_wait, 'c', 1000)) + { + err = RT_ENOSYS; + goto _exit; + } + + _response_cmd(IAP_V5_CMD_C_REPLY); + + ctx = rt_calloc(1, sizeof(*ctx)); + if (!ctx) + { + err = RT_ENOMEM; + rt_kprintf("rt_malloc failed\n"); + goto _exit; + } + + ctx->flash = fal_partition_find(IAP_FLASH_SEC); + if (ctx->flash == RT_NULL) + { + err = RT_ENOSYS; + rt_kprintf("fal_partition_find %s failed: %d\n", IAP_FLASH_SEC, rt_get_errno()); + rt_free(ctx); + goto _exit; + } + + err = rym_recv_on_device(&ctx->parent, console_dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX, + _rym_recv_begin, _rym_recv_data, _rym_recv_end, 1000); + rt_free(ctx); + + rt_thread_mdelay(200); + + if (err == RT_EOK) + { + _response_cmd(IAP_V5_CMD_UPDATE_SUCCEED); + return 0; + } + +_exit: + if (err == RT_EOK) + { + rt_kprintf("jump to app ...\n"); + jump_to_app(); + return 0; + } + + _response_cmd(IAP_V5_CMD_UPDATE_FAILED); + _response_cmd(IAP_V5_CMD_POWER_ON_AGAIN); + + rt_device_set_rx_indicate(console_dev, odev_rx_ind); + return 0; +} + +#include +#include + +#define FLASH_RUN_BASEADDR 0x08020000 + +//定义函数指针,用于跳转到APP +typedef void (*pFunction)(void); +static pFunction JumpToApplication; +static uint32_t JumpAddress; + +static void jump_to_app(void) +{ + SysTick->CTRL = 0; //关键代码 + + HAL_DeInit(); //可选 + HAL_NVIC_DisableIRQ(SysTick_IRQn); //可选 + HAL_NVIC_ClearPendingIRQ(SysTick_IRQn); //可选 + + /* Jump to user application */ + __disable_irq(); + + JumpAddress = *(__IO uint32_t*) (FLASH_RUN_BASEADDR + 4); + + JumpToApplication = (pFunction) JumpAddress; + /* Initialize user application's Stack Pointer */ + __set_MSP(*(__IO uint32_t*) FLASH_RUN_BASEADDR); + + JumpToApplication(); +} +MSH_CMD_EXPORT(jump_to_app, jump_to_app); diff --git a/libraries/STM32F4xx_HAL/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c b/libraries/STM32F4xx_HAL/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c index 3bd40f7..80b8acd 100644 --- a/libraries/STM32F4xx_HAL/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c +++ b/libraries/STM32F4xx_HAL/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c @@ -91,7 +91,7 @@ /*!< Uncomment the following line if you need to relocate the vector table anywhere in Flash or Sram, else the vector table is kept at the automatic remap of boot address selected */ -/* #define USER_VECT_TAB_ADDRESS */ +#define USER_VECT_TAB_ADDRESS #if defined(USER_VECT_TAB_ADDRESS) /*!< Uncomment the following line if you need to relocate your vector Table @@ -105,7 +105,9 @@ #else #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. This value must be a multiple of 0x200. */ -#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. +extern const uint32_t IapAppAddr; + +#define VECT_TAB_OFFSET IapAppAddr /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ #endif /* VECT_TAB_SRAM */ #endif /* USER_VECT_TAB_ADDRESS */ diff --git a/project.uvoptx b/project.uvoptx index a46275d..33c281d 100644 --- a/project.uvoptx +++ b/project.uvoptx @@ -292,49 +292,13 @@ CPlusPlus - 1 + 0 0 0 0 2 9 - 1 - 0 - 0 - 0 - rt-thread\components\libc\cplusplus\cxx_crt_init.c - cxx_crt_init.c - 0 - 0 - - - 2 - 10 - 8 - 0 - 0 - 0 - rt-thread\components\libc\cplusplus\cxx_Semaphore.cpp - cxx_Semaphore.cpp - 0 - 0 - - - 2 - 11 - 8 - 0 - 0 - 0 - rt-thread\components\libc\cplusplus\cxx_Thread.cpp - cxx_Thread.cpp - 0 - 0 - - - 2 - 12 8 0 0 @@ -346,7 +310,31 @@ 2 - 13 + 10 + 1 + 0 + 0 + 0 + rt-thread\components\libc\cplusplus\cxx_crt_init.c + cxx_crt_init.c + 0 + 0 + + + 2 + 11 + 8 + 0 + 0 + 0 + rt-thread\components\libc\cplusplus\cxx_Semaphore.cpp + cxx_Semaphore.cpp + 0 + 0 + + + 2 + 12 8 0 0 @@ -356,6 +344,18 @@ 0 0 + + 2 + 13 + 8 + 0 + 0 + 0 + rt-thread\components\libc\cplusplus\cxx_Thread.cpp + cxx_Thread.cpp + 0 + 0 + @@ -556,7 +556,7 @@ Drivers - 0 + 1 0 0 0 @@ -615,6 +615,18 @@ 0 0 0 + libraries\HAL_Drivers\drv_flash\drv_flash_f4.c + drv_flash_f4.c + 0 + 0 + + + 5 + 34 + 1 + 0 + 0 + 0 libraries\HAL_Drivers\drv_gpio.c drv_gpio.c 0 @@ -622,7 +634,7 @@ 5 - 34 + 35 1 0 0 @@ -635,23 +647,11 @@ - Finsh - 0 + Fal + 1 0 0 0 - - 6 - 35 - 1 - 0 - 0 - 0 - rt-thread\components\finsh\shell.c - shell.c - 0 - 0 - 6 36 @@ -659,8 +659,8 @@ 0 0 0 - rt-thread\components\finsh\msh.c - msh.c + rt-thread\components\fal\src\fal_flash.c + fal_flash.c 0 0 @@ -671,8 +671,8 @@ 0 0 0 - rt-thread\components\finsh\msh_parse.c - msh_parse.c + rt-thread\components\fal\src\fal_partition.c + fal_partition.c 0 0 @@ -683,6 +683,74 @@ 0 0 0 + rt-thread\components\fal\src\fal_rtt.c + fal_rtt.c + 0 + 0 + + + 6 + 39 + 1 + 0 + 0 + 0 + rt-thread\components\fal\src\fal.c + fal.c + 0 + 0 + + + + + Finsh + 1 + 0 + 0 + 0 + + 7 + 40 + 1 + 0 + 0 + 0 + rt-thread\components\finsh\shell.c + shell.c + 0 + 0 + + + 7 + 41 + 1 + 0 + 0 + 0 + rt-thread\components\finsh\msh.c + msh.c + 0 + 0 + + + 7 + 42 + 1 + 0 + 0 + 0 + rt-thread\components\finsh\msh_parse.c + msh_parse.c + 0 + 0 + + + 7 + 43 + 1 + 0 + 0 + 0 rt-thread\components\finsh\cmd.c cmd.c 0 @@ -697,8 +765,8 @@ 0 0 - 7 - 39 + 8 + 44 1 0 0 @@ -709,8 +777,8 @@ 0 - 7 - 40 + 8 + 45 1 0 0 @@ -721,8 +789,8 @@ 0 - 7 - 41 + 8 + 46 1 0 0 @@ -733,8 +801,8 @@ 0 - 7 - 42 + 8 + 47 1 0 0 @@ -745,8 +813,8 @@ 0 - 7 - 43 + 8 + 48 1 0 0 @@ -757,8 +825,8 @@ 0 - 7 - 44 + 8 + 49 1 0 0 @@ -769,8 +837,8 @@ 0 - 7 - 45 + 8 + 50 1 0 0 @@ -781,8 +849,8 @@ 0 - 7 - 46 + 8 + 51 1 0 0 @@ -793,8 +861,8 @@ 0 - 7 - 47 + 8 + 52 1 0 0 @@ -805,8 +873,8 @@ 0 - 7 - 48 + 8 + 53 1 0 0 @@ -817,8 +885,8 @@ 0 - 7 - 49 + 8 + 54 1 0 0 @@ -829,8 +897,8 @@ 0 - 7 - 50 + 8 + 55 1 0 0 @@ -841,8 +909,8 @@ 0 - 7 - 51 + 8 + 56 1 0 0 @@ -861,8 +929,20 @@ 0 0 - 8 - 52 + 9 + 57 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c + stm32f4xx_hal_flash_ex.c + 0 + 0 + + + 9 + 58 1 0 0 @@ -873,79 +953,7 @@ 0 - 8 - 53 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cryp_ex.c - stm32f4xx_hal_cryp_ex.c - 0 - 0 - - - 8 - 54 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c - stm32f4xx_hal_pwr_ex.c - 0 - 0 - - - 8 - 55 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rng.c - stm32f4xx_hal_rng.c - 0 - 0 - - - 8 - 56 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c - stm32f4xx_hal_dma.c - 0 - 0 - - - 8 - 57 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c - stm32f4xx_hal.c - 0 - 0 - - - 8 - 58 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_wwdg.c - stm32f4xx_hal_wwdg.c - 0 - 0 - - - 8 + 9 59 1 0 @@ -957,67 +965,67 @@ 0 - 8 + 9 60 1 0 0 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c + stm32f4xx_hal_crc.c + 0 + 0 + + + 9 + 61 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cryp_ex.c + stm32f4xx_hal_cryp_ex.c + 0 + 0 + + + 9 + 62 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c + stm32f4xx_hal_pwr_ex.c + 0 + 0 + + + 9 + 63 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c + stm32f4xx_hal_dma.c + 0 + 0 + + + 9 + 64 + 1 + 0 + 0 + 0 libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c stm32f4xx_hal_usart.c 0 0 - 8 - 61 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cec.c - stm32f4xx_hal_cec.c - 0 - 0 - - - 8 - 62 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_iwdg.c - stm32f4xx_hal_iwdg.c - 0 - 0 - - - 8 - 63 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c - stm32f4xx_hal_rcc.c - 0 - 0 - - - 8 - 64 - 1 - 0 - 0 - 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c - stm32f4xx_hal_dma_ex.c - 0 - 0 - - - 8 + 9 65 1 0 @@ -1029,44 +1037,80 @@ 0 - 8 + 9 66 1 0 0 0 - libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c - system_stm32f4xx.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_iwdg.c + stm32f4xx_hal_iwdg.c 0 0 - 8 + 9 67 1 0 0 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c - stm32f4xx_hal_crc.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c + stm32f4xx_hal_rcc.c 0 0 - 8 + 9 68 1 0 0 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c + stm32f4xx_hal_dma_ex.c + 0 + 0 + + + 9 + 69 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c + stm32f4xx_hal_gpio.c + 0 + 0 + + + 9 + 70 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rng.c + stm32f4xx_hal_rng.c + 0 + 0 + + + 9 + 71 + 1 + 0 + 0 + 0 libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c stm32f4xx_hal_cortex.c 0 0 - 8 - 69 + 9 + 72 1 0 0 @@ -1077,14 +1121,114 @@ 0 - 8 - 70 + 9 + 73 1 0 0 0 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c - stm32f4xx_hal_gpio.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c + stm32f4xx_hal_flash_ramfunc.c + 0 + 0 + + + 9 + 74 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c + stm32f4xx_hal.c + 0 + 0 + + + 9 + 75 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_wwdg.c + stm32f4xx_hal_wwdg.c + 0 + 0 + + + 9 + 76 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cec.c + stm32f4xx_hal_cec.c + 0 + 0 + + + 9 + 77 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c + stm32f4xx_hal_flash.c + 0 + 0 + + + 9 + 78 + 1 + 0 + 0 + 0 + libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c + system_stm32f4xx.c + 0 + 0 + + + + + Utilities + 1 + 0 + 0 + 0 + + 10 + 79 + 1 + 0 + 0 + 0 + rt-thread\components\utilities\ymodem\ymodem.c + ymodem.c + 0 + 0 + + + + + iap + 1 + 0 + 0 + 0 + + 11 + 80 + 1 + 0 + 0 + 0 + .\iap\iap.c + iap.c 0 0 diff --git a/project.uvprojx b/project.uvprojx index 13a2eeb..e49e7ed 100644 --- a/project.uvprojx +++ b/project.uvprojx @@ -339,7 +339,7 @@ __STDC_LIMIT_MACROS, STM32F413xx, USE_HAL_DRIVER, RT_USING_LIBC, __CLK_TCK=RT_TICK_PER_SECOND, __RTTHREAD__, RT_USING_ARM_LIBC - rt-thread\components\drivers\include;rt-thread\components\libc\posix\io\poll;libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;.;board\CubeMX_Config\Inc;rt-thread\components\libc\posix\ipc;libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;rt-thread\components\libc\compilers\common\include;libraries\HAL_Drivers;rt-thread\components\drivers\include;rt-thread\components\libc\compilers\common\extension\fcntl\octal;board;rt-thread\components\libc\posix\io\stdio;rt-thread\libcpu\arm\common;rt-thread\components\drivers\include;rt-thread\include;rt-thread\components\libc\compilers\common\extension;libraries\HAL_Drivers\config;rt-thread\components\finsh;rt-thread\libcpu\arm\cortex-m4;rt-thread\components\drivers\include;libraries\HAL_Drivers\CMSIS\Include;rt-thread\components\libc\cplusplus + rt-thread\components\drivers\include;rt-thread\components\libc\posix\io\poll;libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;.;board\CubeMX_Config\Inc;rt-thread\components\libc\posix\ipc;libraries\HAL_Drivers\drv_flash;libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;rt-thread\components\libc\compilers\common\include;libraries\HAL_Drivers;rt-thread\components\drivers\include;rt-thread\components\libc\compilers\common\extension\fcntl\octal;board;rt-thread\components\libc\posix\io\stdio;rt-thread\libcpu\arm\common;rt-thread\components\drivers\include;rt-thread\include;rt-thread\components\fal\inc;rt-thread\components\utilities\ymodem;rt-thread\components\libc\compilers\common\extension;libraries\HAL_Drivers\config;rt-thread\components\finsh;rt-thread\libcpu\arm\cortex-m4;rt-thread\components\drivers\include;libraries\HAL_Drivers\CMSIS\Include;rt-thread\components\libc\cplusplus @@ -428,6 +428,11 @@ CPlusPlus + + cxx_Mutex.cpp + 8 + rt-thread\components\libc\cplusplus\cxx_Mutex.cpp + cxx_crt_init.c 1 @@ -438,21 +443,16 @@ 8 rt-thread\components\libc\cplusplus\cxx_Semaphore.cpp - - cxx_Thread.cpp - 8 - rt-thread\components\libc\cplusplus\cxx_Thread.cpp - - - cxx_Mutex.cpp - 8 - rt-thread\components\libc\cplusplus\cxx_Mutex.cpp - cxx_crt.cpp 8 rt-thread\components\libc\cplusplus\cxx_crt.cpp + + cxx_Thread.cpp + 8 + rt-thread\components\libc\cplusplus\cxx_Thread.cpp + @@ -563,6 +563,11 @@ 1 libraries\HAL_Drivers\drv_common.c + + drv_flash_f4.c + 1 + libraries\HAL_Drivers\drv_flash\drv_flash_f4.c + drv_gpio.c 1 @@ -575,6 +580,31 @@ + + Fal + + + fal_flash.c + 1 + rt-thread\components\fal\src\fal_flash.c + + + fal_partition.c + 1 + rt-thread\components\fal\src\fal_partition.c + + + fal_rtt.c + 1 + rt-thread\components\fal\src\fal_rtt.c + + + fal.c + 1 + rt-thread\components\fal\src\fal.c + + + Finsh @@ -673,11 +703,26 @@ Libraries + + stm32f4xx_hal_flash_ex.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c + stm32f4xx_hal_uart.c 1 libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c + + stm32f4xx_hal_rcc_ex.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c + + + stm32f4xx_hal_crc.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c + stm32f4xx_hal_cryp_ex.c 1 @@ -688,40 +733,20 @@ 1 libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c - - stm32f4xx_hal_rng.c - 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rng.c - stm32f4xx_hal_dma.c 1 libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c - - stm32f4xx_hal.c - 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c - - - stm32f4xx_hal_wwdg.c - 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_wwdg.c - - - stm32f4xx_hal_rcc_ex.c - 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c - stm32f4xx_hal_usart.c 1 libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c - stm32f4xx_hal_cec.c + stm32f4xx_hal_pwr.c 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cec.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c stm32f4xx_hal_iwdg.c @@ -739,19 +764,14 @@ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c - stm32f4xx_hal_pwr.c + stm32f4xx_hal_gpio.c 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c - system_stm32f4xx.c + stm32f4xx_hal_rng.c 1 - libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c - - - stm32f4xx_hal_crc.c - 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rng.c stm32f4xx_hal_cortex.c @@ -764,9 +784,54 @@ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cryp.c - stm32f4xx_hal_gpio.c + stm32f4xx_hal_flash_ramfunc.c 1 - libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c + + + stm32f4xx_hal.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c + + + stm32f4xx_hal_wwdg.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_wwdg.c + + + stm32f4xx_hal_cec.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cec.c + + + stm32f4xx_hal_flash.c + 1 + libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c + + + system_stm32f4xx.c + 1 + libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c + + + + + Utilities + + + ymodem.c + 1 + rt-thread\components\utilities\ymodem\ymodem.c + + + + + iap + + + iap.c + 1 + .\iap\iap.c @@ -783,7 +848,7 @@ - <Project Info> + project 0 1 diff --git a/rt-thread/components/fal/src/fal_rtt.c b/rt-thread/components/fal/src/fal_rtt.c index 52d276d..d073816 100644 --- a/rt-thread/components/fal/src/fal_rtt.c +++ b/rt-thread/components/fal/src/fal_rtt.c @@ -10,6 +10,7 @@ */ #include +#include #ifdef RT_VER_NUM #include @@ -546,7 +547,7 @@ struct rt_device *fal_char_device_create(const char *parition_name) #include extern int fal_init_check(void); -static void fal(uint8_t argc, char **argv) { +void fal(uint8_t argc, char **argv) { #define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ') #define HEXDUMP_WIDTH 16 @@ -928,7 +929,7 @@ static void fal(uint8_t argc, char **argv) { } } } -MSH_CMD_EXPORT(fal, FAL (Flash Abstraction Layer) operate.); +//MSH_CMD_EXPORT(fal, FAL (Flash Abstraction Layer) operate.); #endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */ #endif /* RT_VER_NUM */ diff --git a/rtconfig.h b/rtconfig.h index 935eab2..40ccfd1 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -16,12 +16,14 @@ #define RT_HOOK_USING_FUNC_PTR #define RT_USING_IDLE_HOOK #define RT_IDLE_HOOK_LIST_SIZE 4 -#define IDLE_THREAD_STACK_SIZE 256 +#define IDLE_THREAD_STACK_SIZE 1024 /* kservice optimization */ #define RT_DEBUG #define RT_DEBUG_COLOR +#define RT_DEBUG_INIT_CONFIG +#define RT_DEBUG_INIT 1 /* Inter-Thread communication */ @@ -54,7 +56,7 @@ #define RT_USING_COMPONENTS_INIT #define RT_USING_USER_MAIN -#define RT_MAIN_THREAD_STACK_SIZE 2048 +#define RT_MAIN_THREAD_STACK_SIZE 4096 #define RT_MAIN_THREAD_PRIORITY 10 #define RT_USING_MSH #define RT_USING_FINSH @@ -69,6 +71,10 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 +#define RT_USING_FAL +#define FAL_DEBUG_CONFIG +#define FAL_DEBUG 1 +#define FAL_PART_HAS_TABLE_CFG /* Device Drivers */ @@ -102,6 +108,7 @@ /* Utilities */ +#define RT_USING_RYM /* RT-Thread online packages */ @@ -209,6 +216,7 @@ #define BSP_USING_UART2 #define BSP_UART2_RX_USING_DMA #define BSP_UART2_TX_USING_DMA +#define BSP_USING_ON_CHIP_FLASH /* Board extended module Drivers */