From 829f05296aa9686182d5cd88201e235cb6fbab5a Mon Sep 17 00:00:00 2001 From: Huang_Yuqing Date: Tue, 18 May 2021 09:59:15 +0800 Subject: [PATCH 1/2] fix some bugs --- board/k210-emulator/board.c | 23 ----------------------- kernel/kernel_service/xs_service.c | 4 ++-- kernel/kernel_test/test_gatherblock.c | 12 ++++++------ kernel/kernel_test/test_main.c | 5 +++++ kernel/memory/byte_manage.c | 4 ++-- 5 files changed, 15 insertions(+), 33 deletions(-) diff --git a/board/k210-emulator/board.c b/board/k210-emulator/board.c index 0b9f6fa62..20a5441c2 100644 --- a/board/k210-emulator/board.c +++ b/board/k210-emulator/board.c @@ -54,7 +54,6 @@ Modification: extern x_base cpu2_boot_flag; extern void entry(void); extern void SecondaryCpuCStart(void); -extern void ShutdownCpu(void); extern int IoConfigInit(void); extern int HwSpiInit(void); extern int HwI2cInit(void); @@ -183,25 +182,3 @@ void HwCpuReset(void) SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), reboot, HwCpuReset, reset machine ); -static void (*pre_shutdown_action)(void *); -static void *pre_shutdown_action_arg; - -void SetPreShutdownAction(void (*func)(void *), void *arg) -{ - pre_shutdown_action = func; - pre_shutdown_action_arg = arg; -} - -void CmdShutdown() -{ -#ifdef FS_VFS - SyncOpenedFiles(); -#endif - if (pre_shutdown_action != NULL) - pre_shutdown_action(pre_shutdown_action_arg); - - ShutdownCpu(); -} - -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), - shutdown,CmdShutdown,shutdown machine); diff --git a/kernel/kernel_service/xs_service.c b/kernel/kernel_service/xs_service.c index 7183f28c0..f6acd21d8 100644 --- a/kernel/kernel_service/xs_service.c +++ b/kernel/kernel_service/xs_service.c @@ -39,7 +39,7 @@ extern void ShowMemory(void); extern long ShowSem(void); extern long ShowEvent(void); extern long ShowMutex(void); -//extern long ShowMemPool(void); +//extern long ShowGatherMem(void); extern long ShowMsgQueue(void); //extern long showdevice(void); extern long ShowTimer(void); @@ -75,7 +75,7 @@ uintptr_t KsPrintInfo(uint32_t knum,uintptr_t *param, uint8_t num ) #endif break; case 6: - //ShowMemPool(); + //ShowGatherMem(); break; case 7: #ifdef KERNEL_MESSAGEQUEUE diff --git a/kernel/kernel_test/test_gatherblock.c b/kernel/kernel_test/test_gatherblock.c index c05ed42e7..a6e17abfe 100644 --- a/kernel/kernel_test/test_gatherblock.c +++ b/kernel/kernel_test/test_gatherblock.c @@ -21,7 +21,7 @@ #include #include -extern long ShowMemPool(void); +extern long ShowGatherMem(void); extern void ShowMemory(void); extern void ShowBuddy(void); /**************************single gatherblock test sample***********************************/ @@ -93,7 +93,7 @@ int SingleGatherblockTest(char * parameter) if(0 == strncmp("static", parameter, strlen("static"))){ KPrintf("test static create gatherblock.\n"); InitMemGather(&gm, "mp_s", &mempool[0], sizeof(mempool), 80); - ShowMemPool(); + ShowGatherMem(); } if(0 == strncmp("dynamic", parameter, strlen("dynamic"))){ @@ -105,7 +105,7 @@ int SingleGatherblockTest(char * parameter) return -1; } - ShowMemPool(); + ShowGatherMem(); } /* create task1, alloc memory blocks */ tid1 = KTaskCreate("task1", Task1GmAlloc, parameter, @@ -204,7 +204,7 @@ int MultipleGatherblockTest(void) KPrintf("create m_gm_d2 failed."); CHECK(0); } - ShowMemPool(); + ShowGatherMem(); /* create task1, alloc memory blocks */ m_tid1 = KTaskCreate("task1_m", Task1AllocEntry, NONE, @@ -443,7 +443,7 @@ int RandomAllocFreeTest(void *parameter) if(0 == strncmp("static", parameter, strlen("static"))){ KPrintf("test static create gatherblock-%s.\n",parameter); InitMemGather(&random_static_gm, "ran_mp_s", &dynamic_mempool[0], sizeof(dynamic_mempool), 80); - ShowMemPool(); + ShowGatherMem(); }else{ KPrintf("test dynamic create gatherblock.\n"); random_dynamic_gm = CreateMemGather("ran_mp_d",40,80); @@ -451,7 +451,7 @@ int RandomAllocFreeTest(void *parameter) KPrintf("%s: allocate failure.\n",__func__); return -1; } - ShowMemPool(); + ShowGatherMem(); } /* create task1, alloc memory blocks */ random_tid1 = KTaskCreate("r_task1", RandomTask1GmAlloc, parameter, diff --git a/kernel/kernel_test/test_main.c b/kernel/kernel_test/test_main.c index ecd6db657..74703a5bc 100644 --- a/kernel/kernel_test/test_main.c +++ b/kernel/kernel_test/test_main.c @@ -88,21 +88,25 @@ int TestMain(int argc, char*argv[]) break; case MEM: #ifdef KERNEL_TEST_MEM + if (argc > 2) TestMem(argc-2,&argv[2]); #endif break; case TIMER: #ifdef KERNEL_TEST_TIMER + if (argc > 2) TestTmr(argc-2,&argv[2]); #endif break; case GATHERBLOCK: #ifdef KERNEL_TEST_MEM + if (argc > 2) TestGatherblock(&argv[2]); #endif break; case SCHED: #ifdef KERNEL_TEST_SCHED + if (argc > 2) TestTaskReadyAndSched(argc-2, &argv[2]); #endif break; @@ -112,6 +116,7 @@ int TestMain(int argc, char*argv[]) #endif case REALTIME: #ifdef KERNEL_TEST_REALTIME + if (argc > 2) TestRealtime(argc-2, &argv[2]); #endif default: diff --git a/kernel/memory/byte_manage.c b/kernel/memory/byte_manage.c index a92980cc8..fdebc105f 100644 --- a/kernel/memory/byte_manage.c +++ b/kernel/memory/byte_manage.c @@ -66,7 +66,7 @@ struct DynamicAllocNode */ struct DynamicFreeNode { - uint32 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 */ struct DynamicFreeNode *next; @@ -341,7 +341,7 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz }; /* get the best-fit freeNode */ - if (node) { + if (node && (node->size > allocsize)) { struct DynamicFreeNode *remainder; struct DynamicFreeNode *next; x_size_t remaining; From f48da2b6f9b38c9227a7a0ce5ccb47c1c053a8bc Mon Sep 17 00:00:00 2001 From: Liu_Weichao Date: Wed, 19 May 2021 16:15:42 +0800 Subject: [PATCH 2/2] add spi flash test function for arm --- applications/app_test/Kconfig | 8 + applications/app_test/Makefile | 8 + applications/app_test/test_spi_flash.c | 175 ++++++++++++++++++ .../third_party_driver/i2c/connect_i2c.c | 8 +- .../spi/connect_flash_spi.c | 2 +- .../third_party_driver/spi/connect_spi.c | 8 +- .../third_party_driver/i2c/connect_i2c.c | 8 +- .../third_party_driver/spi/connect_spi.c | 8 +- .../third_party_driver/i2c/connect_i2c.c | 8 +- .../third_party_driver/spi/connect_spi.c | 8 +- .../third_party_driver/i2c/connect_i2c.c | 8 +- .../third_party_driver/spi/connect_spi.c | 8 +- .../third_party_driver/i2c/connect_i2c.c | 8 +- .../spi/connect_flash_spi.c | 2 +- .../third_party_driver/spi/connect_spi.c | 8 +- resources/i2c/dev_i2c.c | 4 +- resources/include/dev_i2c.h | 8 +- resources/include/dev_spi.h | 8 +- resources/spi/dev_spi.c | 6 +- resources/spi/flash_spi.c | 32 +++- 20 files changed, 272 insertions(+), 61 deletions(-) create mode 100644 applications/app_test/test_spi_flash.c diff --git a/applications/app_test/Kconfig b/applications/app_test/Kconfig index c63502ac6..09b464f25 100644 --- a/applications/app_test/Kconfig +++ b/applications/app_test/Kconfig @@ -7,4 +7,12 @@ menuconfig USER_TEST bool "Config test lora adhoc" default n + config USER_TEST_SPI_LORA + bool "Config test spi lora" + default n + + config USER_TEST_SPI_FLASH + bool "Config test spi flash" + default n + endif diff --git a/applications/app_test/Makefile b/applications/app_test/Makefile index 7bc0a08fd..f5cdb66e4 100644 --- a/applications/app_test/Makefile +++ b/applications/app_test/Makefile @@ -4,4 +4,12 @@ ifeq ($(CONFIG_USER_TEST_LORA_ADHOC),y) SRC_FILES += test_adhoc_lora.c endif +ifeq ($(CONFIG_USER_TEST_SPI_LORA),y) + SRC_FILES += test_spi_lora.c +endif + +ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y) + SRC_FILES += test_spi_flash.c +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/applications/app_test/test_spi_flash.c b/applications/app_test/test_spi_flash.c new file mode 100644 index 000000000..5e37261aa --- /dev/null +++ b/applications/app_test/test_spi_flash.c @@ -0,0 +1,175 @@ +/* + * File : spi_flash_sfud.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2016-09-28 armink first version. + */ + +/** +* @file test_spi_flash.c +* @brief support to test spi flash function +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2021-05-17 +*/ + +/************************************************* +File name: test_spi_flash.c +Description: support spi flash function test +Others: add spi flash test cmd from SFUD/blob/master/demo/stm32f2xx_rtt/RT-Thread-2.1.0/components/drivers/spi/spi_flash_sfud.c + https://github.com/armink/SFUD/ +History: +1. Date: 2021-05-17 +Author: AIIT XUOS Lab +Modification: +1. support spi flash open, read and write function +*************************************************/ + +#include +#include +#include +#include + +#define SPI_FLASH_PATH "/dev/spi1_W25Q64" +#define FlashDataPrint(ch) ((unsigned int)((ch) - ' ') < 127u - ' ') + +static int spi_flash_fd; + +void FlashOpen(void) +{ + x_err_t ret = EOK; + + spi_flash_fd = open(SPI_FLASH_PATH, O_RDWR); + if (spi_flash_fd < 0) { + KPrintf("open spi flash fd error %d\n", spi_flash_fd); + } + + KPrintf("Spi Flash init succeed\n"); + + return; +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + FlashOpen, FlashOpen, open spi flash device); + +void FlashRead(int argc, char *argv[]) +{ + x_size_t i, j = 0; + uint32 addr; + uint32 size; + uint8 data[16]; + + struct BusBlockReadParam read_param; + memset(&read_param, 0, sizeof(struct BusBlockReadParam)); + + memset(data, 0, 16); + + if (3 != argc) { + KPrintf("FlashRead cmd format: FlashRead addr size.\n"); + return; + } else { + addr = strtol(argv[1], NULL, 0); + size = strtol(argv[2], NULL, 0); + + read_param.buffer = data; + read_param.pos = addr; + read_param.size = size; + + if (read_param.buffer) { + read(spi_flash_fd, &read_param, size); + if (size == read_param.read_length) { + KPrintf("Read the %s flash data success. Start from 0x%08X, size is %ld. The data is:\n", + SPI_FLASH_PATH, addr, size); + KPrintf("Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"); + for (i = 0; i < size; i += 16) { + KPrintf("[%08X] ", addr + i); + /* dump hex */ + for (j = 0; j < 16; j++) { + if (i + j < size) { + KPrintf("%02X ", data[i + j]); + } else { + KPrintf(" "); + } + } + /* dump char for hex */ + for (j = 0; j < 16; j++) { + if (i + j < size) { + KPrintf("%c", FlashDataPrint(data[i + j]) ? data[i + j] : '.'); + } + } + KPrintf("\n"); + } + KPrintf("\n"); + } + } else { + KPrintf("SpiFlashRead alloc read buffer failed!\n"); + } + } + + return; +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + FlashRead, FlashRead, read data from spi flash device); + +void FlashWrite(int argc, char *argv[]) +{ + x_err_t ret = EOK; + x_size_t i, j = 0; + uint32 addr; + uint32 size; + uint8 data[16]; + + struct BusBlockWriteParam write_param; + memset(&write_param, 0, sizeof(struct BusBlockWriteParam)); + + memset(data, 0, 16); + + if (argc < 3) { + KPrintf("FlashWrite cmd format: FlashWrite addr data.\n"); + return; + } else { + addr = strtol(argv[1], NULL, 0); + size = argc - 2; + + write_param.buffer = data; + write_param.pos = addr; + write_param.size = size; + + if (data) { + for (i = 0; i < size; i++) { + data[i] = strtol(argv[2 + i], NULL, 0); + } + + ret = write(spi_flash_fd, &write_param, size); + if (EOK == ret) { + KPrintf("Write the %s flash data success. Start from 0x%08X, size is %ld.\n", + SPI_FLASH_PATH, addr, size); + KPrintf("Write data: "); + for (i = 0; i < size; i++) { + KPrintf("%d ", data[i]); + } + KPrintf(".\n"); + } + } else { + KPrintf("SpiFlashWrite alloc write buffer failed!\n"); + } + } +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + FlashWrite, FlashWrite, write data to spi flash device); diff --git a/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c b/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c index e9726dc29..289789bb2 100644 --- a/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c +++ b/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c @@ -607,10 +607,10 @@ out: /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { - .open = NONE, - .close = NONE, - .write = I2cWriteData, - .read = I2cReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = I2cWriteData, + .dev_read = I2cReadData, }; /*Init i2c bus*/ diff --git a/board/aiit-arm32-board/third_party_driver/spi/connect_flash_spi.c b/board/aiit-arm32-board/third_party_driver/spi/connect_flash_spi.c index 02437e2e4..ca67e28e2 100644 --- a/board/aiit-arm32-board/third_party_driver/spi/connect_flash_spi.c +++ b/board/aiit-arm32-board/third_party_driver/spi/connect_flash_spi.c @@ -46,7 +46,7 @@ int FlashW25qxxSpiDeviceInit(void) return ERROR; } - if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "W25Q64")) { + if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "spi1_W25Q64")) { return ERROR; } diff --git a/board/aiit-arm32-board/third_party_driver/spi/connect_spi.c b/board/aiit-arm32-board/third_party_driver/spi/connect_spi.c index 978ef66dc..c971521c6 100644 --- a/board/aiit-arm32-board/third_party_driver/spi/connect_spi.c +++ b/board/aiit-arm32-board/third_party_driver/spi/connect_spi.c @@ -1347,10 +1347,10 @@ static uint32 Stm32SpiDrvConfigure(void *drv, struct BusConfigureInfo *configure /*manage the spi device operations*/ static const struct SpiDevDone spi_dev_done = { - .open = NONE, - .close = NONE, - .write = Stm32SpiWriteData, - .read = Stm32SpiReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = Stm32SpiWriteData, + .dev_read = Stm32SpiReadData, }; #if defined(BSP_USING_SPI1) diff --git a/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c b/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c index f9200d830..81ade2171 100644 --- a/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c +++ b/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c @@ -515,10 +515,10 @@ out: /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { - .open = NONE, - .close = NONE, - .write = I2cWriteData, - .read = I2cReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = I2cWriteData, + .dev_read = I2cReadData, }; /*Init i2c bus*/ diff --git a/board/aiit-riscv64-board/third_party_driver/spi/connect_spi.c b/board/aiit-riscv64-board/third_party_driver/spi/connect_spi.c index e90655989..7445b0660 100644 --- a/board/aiit-riscv64-board/third_party_driver/spi/connect_spi.c +++ b/board/aiit-riscv64-board/third_party_driver/spi/connect_spi.c @@ -291,10 +291,10 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand /*manage the spi device operations*/ static const struct SpiDevDone spi_dev_done = { - .open = NONE, - .close = NONE, - .write = SpiWriteData, - .read = SpiReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = SpiWriteData, + .dev_read = SpiReadData, }; static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) diff --git a/board/k210-emulator/third_party_driver/i2c/connect_i2c.c b/board/k210-emulator/third_party_driver/i2c/connect_i2c.c index 65fb2088e..edede3cdb 100644 --- a/board/k210-emulator/third_party_driver/i2c/connect_i2c.c +++ b/board/k210-emulator/third_party_driver/i2c/connect_i2c.c @@ -503,10 +503,10 @@ out: /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { - .open = NONE, - .close = NONE, - .write = I2cWriteData, - .read = I2cReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = I2cWriteData, + .dev_read = I2cReadData, }; /*Init i2c bus*/ diff --git a/board/k210-emulator/third_party_driver/spi/connect_spi.c b/board/k210-emulator/third_party_driver/spi/connect_spi.c index 05dfabe05..1ddbda670 100644 --- a/board/k210-emulator/third_party_driver/spi/connect_spi.c +++ b/board/k210-emulator/third_party_driver/spi/connect_spi.c @@ -290,10 +290,10 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand /*manage the spi device operations*/ static const struct SpiDevDone spi_dev_done = { - .open = NONE, - .close = NONE, - .write = SpiWriteData, - .read = SpiReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = SpiWriteData, + .dev_read = SpiReadData, }; static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) diff --git a/board/kd233/third_party_driver/i2c/connect_i2c.c b/board/kd233/third_party_driver/i2c/connect_i2c.c index 65fb2088e..edede3cdb 100644 --- a/board/kd233/third_party_driver/i2c/connect_i2c.c +++ b/board/kd233/third_party_driver/i2c/connect_i2c.c @@ -503,10 +503,10 @@ out: /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { - .open = NONE, - .close = NONE, - .write = I2cWriteData, - .read = I2cReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = I2cWriteData, + .dev_read = I2cReadData, }; /*Init i2c bus*/ diff --git a/board/kd233/third_party_driver/spi/connect_spi.c b/board/kd233/third_party_driver/spi/connect_spi.c index 05dfabe05..1ddbda670 100644 --- a/board/kd233/third_party_driver/spi/connect_spi.c +++ b/board/kd233/third_party_driver/spi/connect_spi.c @@ -290,10 +290,10 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand /*manage the spi device operations*/ static const struct SpiDevDone spi_dev_done = { - .open = NONE, - .close = NONE, - .write = SpiWriteData, - .read = SpiReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = SpiWriteData, + .dev_read = SpiReadData, }; static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) diff --git a/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c b/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c index d5d632b4a..1bb39194f 100644 --- a/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c +++ b/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c @@ -603,10 +603,10 @@ out: /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { - .open = NONE, - .close = NONE, - .write = I2cWriteData, - .read = I2cReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = I2cWriteData, + .dev_read = I2cReadData, }; /*Init i2c bus*/ diff --git a/board/stm32f407-st-discovery/third_party_driver/spi/connect_flash_spi.c b/board/stm32f407-st-discovery/third_party_driver/spi/connect_flash_spi.c index e7ad6e4f3..26dc2ddd9 100644 --- a/board/stm32f407-st-discovery/third_party_driver/spi/connect_flash_spi.c +++ b/board/stm32f407-st-discovery/third_party_driver/spi/connect_flash_spi.c @@ -46,7 +46,7 @@ int FlashW25qxxSpiDeviceInit(void) return ERROR; } - if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "W25Q64")) { + if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "spi1_W25Q64")) { return ERROR; } diff --git a/board/stm32f407-st-discovery/third_party_driver/spi/connect_spi.c b/board/stm32f407-st-discovery/third_party_driver/spi/connect_spi.c index 42cbdf25c..9e68aac22 100644 --- a/board/stm32f407-st-discovery/third_party_driver/spi/connect_spi.c +++ b/board/stm32f407-st-discovery/third_party_driver/spi/connect_spi.c @@ -1251,10 +1251,10 @@ static uint32 Stm32SpiDrvConfigure(void *drv, struct BusConfigureInfo *configure /*manage the spi device operations*/ static const struct SpiDevDone spi_dev_done = { - .open = NONE, - .close = NONE, - .write = Stm32SpiWriteData, - .read = Stm32SpiReadData, + .dev_open = NONE, + .dev_close = NONE, + .dev_write = Stm32SpiWriteData, + .dev_read = Stm32SpiReadData, }; #if defined(BSP_USING_SPI1) diff --git a/resources/i2c/dev_i2c.c b/resources/i2c/dev_i2c.c index 18f09bee9..ca0e9af6f 100644 --- a/resources/i2c/dev_i2c.c +++ b/resources/i2c/dev_i2c.c @@ -44,7 +44,7 @@ static uint32 I2cDeviceWrite(void *dev, struct BusBlockWriteParam *write_param) i2c_msg.retries = 1; i2c_msg.next = NONE; - return i2c_dev->i2c_dev_done->write(i2c_dev, &i2c_msg); + return i2c_dev->i2c_dev_done->dev_write(i2c_dev, &i2c_msg); } static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param) @@ -62,7 +62,7 @@ static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param) i2c_msg.retries = 1; i2c_msg.next = NONE; - return i2c_dev->i2c_dev_done->read(i2c_dev, &i2c_msg); + return i2c_dev->i2c_dev_done->dev_read(i2c_dev, &i2c_msg); } static const struct HalDevDone dev_done = diff --git a/resources/include/dev_i2c.h b/resources/include/dev_i2c.h index 13358bdd2..ad437bc4d 100644 --- a/resources/include/dev_i2c.h +++ b/resources/include/dev_i2c.h @@ -50,10 +50,10 @@ struct I2cHardwareDevice; struct I2cDevDone { - uint32 (*open) (struct I2cHardwareDevice *i2c_device); - uint32 (*close) (struct I2cHardwareDevice *i2c_device); - uint32 (*write) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg); - uint32 (*read) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg); + uint32 (*dev_open) (struct I2cHardwareDevice *i2c_device); + uint32 (*dev_close) (struct I2cHardwareDevice *i2c_device); + uint32 (*dev_write) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg); + uint32 (*dev_read) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg); }; struct I2cHardwareDevice diff --git a/resources/include/dev_spi.h b/resources/include/dev_spi.h index dfb4c5449..9984427f9 100644 --- a/resources/include/dev_spi.h +++ b/resources/include/dev_spi.h @@ -102,10 +102,10 @@ struct SpiHardwareDevice; struct SpiDevDone { - uint32 (*open) (struct SpiHardwareDevice *dev); - uint32 (*close) (struct SpiHardwareDevice *dev); - uint32 (*write) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg); - uint32 (*read) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg); + uint32 (*dev_open) (struct SpiHardwareDevice *dev); + uint32 (*dev_close) (struct SpiHardwareDevice *dev); + uint32 (*dev_write) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg); + uint32 (*dev_read) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg); }; struct SpiHardwareDevice diff --git a/resources/spi/dev_spi.c b/resources/spi/dev_spi.c index 94b6be6a3..22798e509 100644 --- a/resources/spi/dev_spi.c +++ b/resources/spi/dev_spi.c @@ -62,7 +62,7 @@ static uint32 SpiDeviceWrite(void *dev, struct BusBlockWriteParam *write_param) spi_msg.spi_cs_release = 0; spi_msg.next = NONE; - return spi_dev->spi_dev_done->write(spi_dev, &spi_msg); + return spi_dev->spi_dev_done->dev_write(spi_dev, &spi_msg); } static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param) @@ -80,7 +80,7 @@ static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param) spi_msg.spi_cs_release = 0; spi_msg.next = NONE; - return spi_dev->spi_dev_done->read(spi_dev, &spi_msg); + return spi_dev->spi_dev_done->dev_read(spi_dev, &spi_msg); } static const struct HalDevDone dev_done = @@ -190,5 +190,5 @@ int SpiDevConfigureCs(struct HardwareDev *dev, uint8 spi_chip_select, uint8 spi_ msg.spi_chip_select = spi_chip_select; msg.spi_cs_release = spi_cs_release; - return spi_dev->spi_dev_done->write(spi_dev, &msg); + return spi_dev->spi_dev_done->dev_write(spi_dev, &msg); } diff --git a/resources/spi/flash_spi.c b/resources/spi/flash_spi.c index ab5b92ce8..c9a5b918b 100644 --- a/resources/spi/flash_spi.c +++ b/resources/spi/flash_spi.c @@ -18,6 +18,8 @@ * @date 2021-04-24 */ +#include +#include #include /** @@ -43,13 +45,20 @@ static uint32 SpiFlashWrite(void *dev, struct BusBlockWriteParam *write_param) HardwareDevType haldev = (struct HardwareDev *)dev; struct SpiHardwareDevice *flash_dev; + struct BusBlockWriteParam *flash_write_param = (struct BusBlockWriteParam *)write_param->buffer; + flash_dev = CONTAINER_OF(haldev, struct SpiHardwareDevice, haldev); spi_flash_dev = CONTAINER_OF(flash_dev, struct SpiFlashDevice, flash_dev); sfud_flash_dev = (sfud_flash *)spi_flash_dev->flash_param.flash_private_data; - pos = write_param->pos * spi_flash_dev->flash_param.flash_block_param.sector_bytes; - size = write_param->size * spi_flash_dev->flash_param.flash_block_param.sector_bytes; - write_buffer = (uint8 *)write_param->buffer; + pos = flash_write_param->pos;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes; + size = flash_write_param->size;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes; + write_buffer = (uint8 *)flash_write_param->buffer; + + KPrintf("flash write pos %u sector_bytes %u size %u\n", + flash_write_param->pos, + spi_flash_dev->flash_param.flash_block_param.sector_bytes, + flash_write_param->size); ret = sfud_erase_write(sfud_flash_dev, pos, size, write_buffer); if (SFUD_SUCCESS != ret) { @@ -57,6 +66,8 @@ static uint32 SpiFlashWrite(void *dev, struct BusBlockWriteParam *write_param) return ERROR; } + haldev->owner_bus->owner_haldev = haldev; + return ret; } @@ -82,13 +93,15 @@ static uint32 SpiFlashRead(void *dev, struct BusBlockReadParam *read_param) HardwareDevType haldev = (struct HardwareDev *)dev; struct SpiHardwareDevice *flash_dev; + struct BusBlockReadParam *flash_read_param = (struct BusBlockReadParam *)read_param->buffer; + flash_dev = CONTAINER_OF(haldev, struct SpiHardwareDevice, haldev); spi_flash_dev = CONTAINER_OF(flash_dev, struct SpiFlashDevice, flash_dev); sfud_flash_dev = (sfud_flash *)spi_flash_dev->flash_param.flash_private_data; - pos = read_param->pos * spi_flash_dev->flash_param.flash_block_param.sector_bytes; - size = read_param->size * spi_flash_dev->flash_param.flash_block_param.sector_bytes; - read_buffer = (uint8 *)read_param->buffer; + pos = flash_read_param->pos;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes; + size = flash_read_param->size;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes; + read_buffer = (uint8 *)flash_read_param->buffer; ret = sfud_read(sfud_flash_dev, pos, size, read_buffer); if (SFUD_SUCCESS != ret) { @@ -96,6 +109,13 @@ static uint32 SpiFlashRead(void *dev, struct BusBlockReadParam *read_param) return ERROR; } + flash_read_param->read_length = flash_read_param->size; + read_param->read_length = flash_read_param->size; + + haldev->owner_bus->owner_haldev = haldev; + + KPrintf("SpiFlashRead read buffer done\n"); + return ret; }