diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 7202322739e57444e765a66238e8f7943f192a0b..ccaf3321528e477302371fdf51bc55f17e20d06a 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -1,3 +1,52 @@ +# Phytium FreeRTOS SDK 2023-3-2 ChangeLog + +Change Log sinc 2023-2-27 + +## driver + +- eth/xmac delete conditional compilation statements about NO_SYS + +## example + +- modify network/lwip_startup configs and sdkconfig + +## third-party + +- lwip-2.1.2/ports/* delete conditional compilation statements about NO_SYS +- lwip-2.1.2/ports/fgmac ethernetif_init function name modified +- update lwip-2.1.2/kconfig + +# Phytium FreeRTOS SDK 2023-3-1 ChangeLog + +Change Log sinc 2023-2-23 + +## example + +- add nested_interrupt example + +## third-party + +- modify freertos aarch32 and aarch64 port function + +# Phytium FreeRTOS SDK 2023-2-20 ChangeLog + +Change Log sinc 2023-2-16 +## example +- add spim_spiffs example +## third-party +- modify sfud and delete repetitive code + +# Phytium FreeRTOS SDK 2023-2-10 ChangeLog + +Change Log sinc 2023-2-8 + +## example +- modify configs of cherryusb_host + +## third-party +- update cherryusb from v0.6.0 to v0.7.0 +- modify Kconfig and makefile files + # Phytium FreeRTOS SDK 2023-2-9 0.4.0 ChangeLog Change Log sinc 2023-2-6 diff --git a/drivers/eth/gmac/fgmac_os.c b/drivers/eth/gmac/fgmac_os.c index baa24fa4b847382b8284d035967fc786e48b0fc5..9a512e07df468d5b8da20232a0e8fe8143041bda 100644 --- a/drivers/eth/gmac/fgmac_os.c +++ b/drivers/eth/gmac/fgmac_os.c @@ -206,7 +206,6 @@ static int FGmacSetupIsr(FGmac *gmac_p) u32 irq_num = config_p->irq_num; u32 cpu_id; - u32 irq_priority = IRQ_PRIORITY_VALUE_12 ; /* gic initialize */ GetCpuId(&cpu_id); @@ -216,7 +215,7 @@ static int FGmacSetupIsr(FGmac *gmac_p) FGmacSetInterruptMask(gmac_p, FGMAC_CTRL_INTR, FGMAC_ISR_MASK_ALL_BITS); FGmacSetInterruptMask(gmac_p, FGMAC_DMA_INTR, FGMAC_DMA_INTR_ENA_ALL_MASK); - InterruptSetPriority(irq_num, irq_priority); + InterruptSetPriority(irq_num, GMAC_OS_IRQ_PRIORITY_VALUE); InterruptInstall(irq_num, FGmacInterruptHandler, gmac_p, "GMAC-IRQ"); /* register intr callback */ diff --git a/drivers/eth/gmac/fgmac_os.h b/drivers/eth/gmac/fgmac_os.h index 120e7a3894306acfaadb2af17faa5bd0e68f0450..173a76ef624fcd0d7b6f60c40b0a3e4366bf7ccd 100644 --- a/drivers/eth/gmac/fgmac_os.h +++ b/drivers/eth/gmac/fgmac_os.h @@ -81,6 +81,10 @@ extern "C" #define GMAC_RX_DESCNUM 128 #define GMAC_TX_DESCNUM 128 +/*irq priority value*/ +#define GMAC_OS_IRQ_PRIORITY_VALUE (configMAX_API_CALL_INTERRUPT_PRIORITY+1) +FASSERT_STATIC((GMAC_OS_IRQ_PRIORITY_VALUE <= IRQ_PRIORITY_VALUE_15) && (GMAC_OS_IRQ_PRIORITY_VALUE >= configMAX_API_CALL_INTERRUPT_PRIORITY)); + typedef struct { u32 instance_id; diff --git a/drivers/eth/xmac/fxmac_os.c b/drivers/eth/xmac/fxmac_os.c index 817a0fe753f0e1df31037146a38a46e47c3220a5..7e9ca1e13d46db11f75bd76506f9bc537b995afb 100644 --- a/drivers/eth/xmac/fxmac_os.c +++ b/drivers/eth/xmac/fxmac_os.c @@ -480,9 +480,9 @@ void FXmacRecvHandler(void *arg) /* free up the BD's */ FXmacBdRingFree(rxring, bd_processed, rxbdset); SetupRxBds(instance_p, rxring); -#if !NO_SYS + sys_sem_signal(&xmac_netif_p->sem_rx_data_available); -#endif + } return; @@ -1096,8 +1096,7 @@ static void FXmacSetupIsr(FXmacOs *instance_p) FXmacSetHandler(&instance_p->instance, FXMAC_HANDLER_DMARECV, FXmacRecvHandler, instance_p); FXmacSetHandler(&instance_p->instance, FXMAC_HANDLER_ERROR, FXmacErrorHandler, instance_p); FXmacSetHandler(&instance_p->instance, FXMAC_HANDLER_LINKCHANGE, FXmacLinkChange, instance_p); - - InterruptSetPriority(instance_p->instance.config.queue_irq_num[0], IRQ_PRIORITY_VALUE_12); + InterruptSetPriority(instance_p->instance.config.queue_irq_num[0], XMAC_OS_IRQ_PRIORITY_VALUE); InterruptInstall(instance_p->instance.config.queue_irq_num[0], FxmacOsIntrHandler, &instance_p->instance, "fxmac"); InterruptUmask(instance_p->instance.config.queue_irq_num[0]); } @@ -1248,8 +1247,8 @@ FError FXmacOsInit(FXmacOs *instance_p) /* initialize dma */ dmacrreg = FXMAC_READREG32(xmac_p->config.base_address, FXMAC_DMACR_OFFSET); - dmacrreg & ~(FXMAC_DMACR_BLENGTH_MASK); - dmacrreg = dmacrreg | FXMAC_DMACR_INCR16_AHB_AXI_BURST; /* Attempt to use bursts of up to 16. */ + dmacrreg &= (~(FXMAC_DMACR_BLENGTH_MASK)); + dmacrreg |= (FXMAC_DMACR_INCR16_AHB_AXI_BURST); /* Attempt to use bursts of up to 16. */ FXMAC_WRITEREG32(xmac_p->config.base_address, FXMAC_DMACR_OFFSET, dmacrreg); FXmacInitDma(instance_p); diff --git a/drivers/eth/xmac/fxmac_os.h b/drivers/eth/xmac/fxmac_os.h index 82fda05596c9ad36786ce6edf88a2beda4dd5e94..4b3f26b1b88122b40c4e5e95090bf456ce366cfd 100644 --- a/drivers/eth/xmac/fxmac_os.h +++ b/drivers/eth/xmac/fxmac_os.h @@ -40,8 +40,8 @@ extern "C" { #define FREERTOS_XMAC_PARAM_ERROR FT_CODE_ERR(ErrModPort, 0, 0x2) #define FREERTOS_XMAC_NO_VALID_SPACE FT_CODE_ERR(ErrModPort, 0, 0x3) -#define FXMAX_RX_BDSPACE_LENGTH 0x20000 /* default set 64KB*/ -#define FXMAX_TX_BDSPACE_LENGTH 0x20000 /* default set 64KB*/ +#define FXMAX_RX_BDSPACE_LENGTH 0x20000 /* default set 128KB*/ +#define FXMAX_TX_BDSPACE_LENGTH 0x20000 /* default set 128KB*/ #define FXMAX_RX_PBUFS_LENGTH 128 #define FXMAX_TX_PBUFS_LENGTH 128 @@ -70,7 +70,11 @@ extern "C" { /* frame queue */ #define PQ_QUEUE_SIZE 4096 -typedef struct +/*irq priority value*/ +#define XMAC_OS_IRQ_PRIORITY_VALUE (configMAX_API_CALL_INTERRUPT_PRIORITY+1) +FASSERT_STATIC((XMAC_OS_IRQ_PRIORITY_VALUE <= IRQ_PRIORITY_VALUE_15)&&(XMAC_OS_IRQ_PRIORITY_VALUE >= configMAX_API_CALL_INTERRUPT_PRIORITY)); + +typedef struct { uintptr data[PQ_QUEUE_SIZE]; int head, tail, len; diff --git a/example/freertos_feature/interrupt/README.md b/example/freertos_feature/interrupt/README.md index 16fccfb221358c0634771e0d03f58e37a8621b02..5150f972681235727a433dc69254a336aed2dd91 100644 --- a/example/freertos_feature/interrupt/README.md +++ b/example/freertos_feature/interrupt/README.md @@ -26,7 +26,7 @@ ## 1. 例程介绍 本例程示范了freertos环境下的inteerrupt的使用。 -主要介绍了二值信号量、计数信号量、在中断中使用队列等方法 +主要介绍了二值信号量、计数信号量、在中断中使用队列、中断嵌套的使用等方法 ## 2. 如何使用例程 @@ -135,18 +135,23 @@ bootelf -p 0x90100000 ![count](./figs/intr_count.png) -- 输入```intr queue_cre```,启动在中服务程序中使用queue测试 -- 输入```intr queue_del```,删除在中服务程序中使用queue测试 +- 输入```intr queue_cre```,启动在中断服务程序中使用queue测试 +- 输入```intr queue_del```,删除在中断服务程序中使用queue测试 ![queue](./figs/intr_queue.png) +- 输入```intr nest_cre```,启动中断嵌套测试 +- 输入```intr nest_del```,删除中断嵌套测试 + +![nested](./figs/intr_nested.png) + - 测试任务能够能正常创建和删除,输入```ps```查看任务状态正常,即测试正常 ## 3. 如何解决问题 -Q: 三个例程同时运行异常 +Q: 例程同时运行异常 -A: 这三个例程都初始化了intr的软中断,所以同时用会有问题; +A: 例程都初始化了intr的软中断,所以同时用会有问题; ## 4. 修改历史记录 diff --git a/example/freertos_feature/interrupt/configs/e2000d_aarch32_eg_configs b/example/freertos_feature/interrupt/configs/e2000d_aarch32_eg_configs index 22df4f8b68161ebffeeff055523bd84017f6024c..4c1569574661823c508bdb209e99667aca7d13e7 100644 --- a/example/freertos_feature/interrupt/configs/e2000d_aarch32_eg_configs +++ b/example/freertos_feature/interrupt/configs/e2000d_aarch32_eg_configs @@ -68,6 +68,7 @@ CONFIG_ENABLE_Pl011_UART=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -242,7 +243,7 @@ CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 -CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=12 +CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 CONFIG_FREERTOS_MAX_TASK_NAME_LEN=32 diff --git a/example/freertos_feature/interrupt/figs/intr_nested.png b/example/freertos_feature/interrupt/figs/intr_nested.png new file mode 100644 index 0000000000000000000000000000000000000000..b7712b09df9c4caf4b7a09029ee5deae80fc4317 Binary files /dev/null and b/example/freertos_feature/interrupt/figs/intr_nested.png differ diff --git a/example/freertos_feature/interrupt/inc/feature_interrupt.h b/example/freertos_feature/interrupt/inc/feature_interrupt.h index a9da368833a82b4a034abdc4be12ff3c4a46c29f..86bb993a57723f28d5a5ae9ac744b596e6a23ae4 100644 --- a/example/freertos_feature/interrupt/inc/feature_interrupt.h +++ b/example/freertos_feature/interrupt/inc/feature_interrupt.h @@ -20,6 +20,7 @@ * Ver Who Date Changes * ----- ------ -------- -------------------------------------- * 1.0 wangxiaodong 2022/08/09 first commit + * 1.1 wangxiaodong 2023/02/25 add nested interrupt test */ @@ -41,6 +42,9 @@ void DeleteCountSemTasks(void); void CreateQueueTasks(void); void DeleteQueueTasks(void); +void CreateNestedTasks(void); +void DeleteNestedTasks(void); + #ifdef __cplusplus } #endif diff --git a/example/freertos_feature/interrupt/main.c b/example/freertos_feature/interrupt/main.c index 481070c3c3b588bb2910f649ecb50d9328719c7a..7b0ddfc5cd1b2a0ddb64a34ffb255e4e6513c90c 100644 --- a/example/freertos_feature/interrupt/main.c +++ b/example/freertos_feature/interrupt/main.c @@ -12,14 +12,14 @@ * * * FilePath: main.c - * Date: 2022-06-17 08:17:59 - * LastEditTime: 2022-06-17 08:17:59 - * Description: This file is for interrupt example that running shell task and open scheduler + * Date: 2023-02-22 08:17:59 + * LastEditTime: 2023-3-1 08:17:59 + * Description: This file is for nested interrupt test main entry. * * Modify History: - * Ver Who Date Changes + * Ver   Who        Date         Changes * ----- ------ -------- -------------------------------------- - * + * 1.0 wangxiaodong 2023/2/23 first release */ #include "shell.h" @@ -29,7 +29,7 @@ int main(void) { BaseType_t ret; - + ret = LSUserShellTask() ; if (ret != pdPASS) { diff --git a/example/freertos_feature/interrupt/src/interrupt_cmd.c b/example/freertos_feature/interrupt/src/interrupt_cmd.c index 3eef59acbf0b402eee5769097c01876de1853d16..189426d3293f5f4fdeb139f15aa10646d79a54a3 100644 --- a/example/freertos_feature/interrupt/src/interrupt_cmd.c +++ b/example/freertos_feature/interrupt/src/interrupt_cmd.c @@ -20,6 +20,7 @@ * Ver Who Date Changes * ----- ------ -------- -------------------------------------- * 1.0 wangxiaodong 2022/08/09 first commit + * 1.1 wangxiaodong 2023/02/25 add nested interrupt test */ #include "shell.h" #include @@ -31,6 +32,8 @@ typedef enum BINARY_SEM_TASK_INDEX = 0, COUNT_SEM_TASK_INDEX = 1, QUEUE_TASK_INDEX = 2, + NEST_TASK_INDEX = 3, + INTR_FEATURE_LENGTH } FreeRtosIntrFeatureSelect; @@ -49,6 +52,10 @@ static void CreateIntrCmdUsage(void) printf(" -- Create queue tasks now.\r\n"); printf(" intr queue_del \r\n"); printf(" -- Del queue tasks now.\r\n"); + printf(" intr nest_cre \r\n"); + printf(" -- Create nest tasks now.\r\n"); + printf(" intr nest_del \r\n"); + printf(" -- Del nest tasks now.\r\n"); } int CreateIntrCmd(int argc, char *argv[]) @@ -133,6 +140,30 @@ int CreateIntrCmd(int argc, char *argv[]) printf("Please use queue_cre cmd first. \r\n"); } } + else if (!strcmp(argv[1], "nest_cre")) + { + if (create_flg[NEST_TASK_INDEX] == 0) + { + CreateNestedTasks(); + create_flg[NEST_TASK_INDEX] = 1; + } + else + { + printf("Please use nest_del cmd first. \r\n"); + } + } + else if (!strcmp(argv[1], "nest_del")) + { + if (create_flg[NEST_TASK_INDEX] == 1) + { + DeleteNestedTasks(); + create_flg[NEST_TASK_INDEX] = 0; + } + else + { + printf("Please use nest_cre cmd first. \r\n"); + } + } else { printf("Error: Invalid arguments. \r\n"); diff --git a/example/freertos_feature/interrupt/src/nested_interrupt.c b/example/freertos_feature/interrupt/src/nested_interrupt.c new file mode 100644 index 0000000000000000000000000000000000000000..6f5aaeae150ea7a4846b2588246bb4361ded733c --- /dev/null +++ b/example/freertos_feature/interrupt/src/nested_interrupt.c @@ -0,0 +1,172 @@ +/* + * Copyright : (C) 2022 Phytium Information Technology, Inc. + * All Rights Reserved. + * + * This program is OPEN SOURCE software: you can redistribute it and/or modify it + * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd, + * either version 1.0 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 Phytium Public License for more details. + * + * + * FilePath: main.c + * Date: 2023-02-23 14:53:42 + * LastEditTime: 2023-03-01 17:57:36 + * Description:  This file is for nested interrupt test function. + * + * Modify History: + * Ver   Who        Date         Changes + * ----- ------     --------    -------------------------------------- + * 1.0 wangxiaodong 2023/2/23 first release + */ + +#include +#include "FreeRTOSConfig.h" +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "croutine.h" +#include "finterrupt.h" +#include "fcpu_info.h" +#include "fexception.h" + + +static xTaskHandle xtask_handle; + +#define TASK_STACK_SIZE 1024 + +/* The interrupt number to use for the software interrupt generation. This +could be any unused number. In this case the first chip level (non system) +interrupt is used */ +#define INTERRUPT_LOW_ID 0 +#define INTERRUPT_HIGH_ID 1 + +/* The priority of the software interrupt. The interrupt service routine uses +an (interrupt safe) FreeRTOS API function, so the priority of the interrupt must +be equal to or lower than the priority set by +configMAX_SYSCALL_INTERRUPT_PRIORITY - remembering that on the Cortex M3 high +numeric values represent low priority values, which can be confusing as it is +counter intuitive. */ +#define INTERRUPT_LOW_PRIORITY IRQ_PRIORITY_VALUE_14 +#define INTERRUPT_HIGH_PRIORITY (INTERRUPT_LOW_PRIORITY-1) + +/* Macro to force an interrupt. */ +static void vTriggerNestedInterrupt(void); + +static u32 cpu_id = 0; + + +static volatile u8 low_priority_intr_flag = 0; /* Flag to update low priority interrupt counter */ +static volatile u8 high_priority_intr_flag = 0; /* Flag to update high priority interrupt counter */ + + +static void vNestedPeriodTask(void *pvParameters) +{ + u8 count = 0; + for (;;) + { + vTaskDelay(3000 / portTICK_RATE_MS); + printf("Nested Interrupt Test %d.\r\n", count++); + vTriggerNestedInterrupt(); + } +} + + +static void FLowPriorityHandler(s32 vector, void *param) +{ + static float val = 0.3; + + val = val * 2.1; + + /* update the flag to indicate the interrupt */ + low_priority_intr_flag++; + + /* Enable the nested interrupts to allow preemption */ + INTERRUPT_NESTED_ENABLE(); + + InterruptCoreInterSend(INTERRUPT_HIGH_ID, (1 << cpu_id)); + + printf("Nested interrupt enable.\r\n"); + + /* wait till interrupts from counter configured with high priority interrupt */ + while(high_priority_intr_flag == 0) + { + + }; + + /* Disable the nested interrupt before exiting IRQ mode */ + INTERRUPT_NESTED_DISABLE(); + + printf("low_priority_intr_flag is %d, %f \n\n\n", low_priority_intr_flag, val); + +} + +static void FHighPriorityHandler(s32 vector, void *param) +{ + /* update the flag to indicate the interrupt */ + high_priority_intr_flag++; + static float val = 0.3; + + val = val * 2.0; + + printf("high_priority_intr_flag is %d, %f \r\n", high_priority_intr_flag, val); + +} + + +static void prvSetupSoftwareNestedInterrupt() +{ + + GetCpuId(&cpu_id); + + /* The interrupt service routine uses an (interrupt safe) FreeRTOS API + function so the interrupt priority must be at or below the priority defined + by configSYSCALL_INTERRUPT_PRIORITY. */ + InterruptSetPriority(INTERRUPT_LOW_ID, INTERRUPT_LOW_PRIORITY); + + InterruptInstall(INTERRUPT_LOW_ID, FLowPriorityHandler, NULL, NULL); + + /* Enable the interrupt. */ + InterruptUmask(INTERRUPT_LOW_ID); + + + InterruptSetPriority(INTERRUPT_HIGH_ID, INTERRUPT_HIGH_PRIORITY); + + InterruptInstall(INTERRUPT_HIGH_ID, FHighPriorityHandler, NULL, NULL); + + /* Enable the interrupt. */ + InterruptUmask(INTERRUPT_HIGH_ID); + +} + +/* Macro to force an interrupt. */ +static void vTriggerNestedInterrupt(void) +{ + low_priority_intr_flag = 0; + + high_priority_intr_flag = 0; + + InterruptCoreInterSend(INTERRUPT_LOW_ID, (1 << cpu_id)); + +} + + +void CreateNestedTasks(void) +{ + printf("Create Nest Task \r\n"); + prvSetupSoftwareNestedInterrupt(); + xTaskCreate(vNestedPeriodTask, "NestedPeriodic", TASK_STACK_SIZE, NULL, 6, &xtask_handle); + +} + +void DeleteNestedTasks(void) +{ + if (xtask_handle) + { + vTaskDelete(xtask_handle); + printf("Nest Periodic deletion \r\n"); + } + +} \ No newline at end of file diff --git a/example/network/lwip_startup/configs/d2000_aarch32_eg_configs b/example/network/lwip_startup/configs/d2000_aarch32_eg_configs index 807857dee6de7d9733e76ac6cf9c752cf06d2e24..989bbac11c40984578bb2453a3cc9cecb64e6536 100644 --- a/example/network/lwip_startup/configs/d2000_aarch32_eg_configs +++ b/example/network/lwip_startup/configs/d2000_aarch32_eg_configs @@ -27,6 +27,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y CONFIG_USE_AARCH64_L1_TO_AARCH32=y +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -85,6 +86,7 @@ CONFIG_FGMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -103,6 +105,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -487,7 +490,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/d2000_aarch64_eg_configs b/example/network/lwip_startup/configs/d2000_aarch64_eg_configs index 7cc036af3d92ca872c74c1bfeb5af9fadfff6401..2664bc59fafc557b595b08a63a6fa60b9a39bc2f 100644 --- a/example/network/lwip_startup/configs/d2000_aarch64_eg_configs +++ b/example/network/lwip_startup/configs/d2000_aarch64_eg_configs @@ -27,6 +27,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y # CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -85,6 +86,7 @@ CONFIG_FGMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -103,6 +105,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -483,7 +486,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/e2000d_aarch32_eg_configs b/example/network/lwip_startup/configs/e2000d_aarch32_eg_configs index c49acffb84e9af90318891f02dd6a3769ae6345e..fdfd26c51ad5f4211b481084afd67d17163344ff 100644 --- a/example/network/lwip_startup/configs/e2000d_aarch32_eg_configs +++ b/example/network/lwip_startup/configs/e2000d_aarch32_eg_configs @@ -30,6 +30,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y CONFIG_USE_AARCH64_L1_TO_AARCH32=y +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -89,6 +90,7 @@ CONFIG_FXMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -107,6 +109,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -478,7 +481,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/e2000d_aarch64_eg_configs b/example/network/lwip_startup/configs/e2000d_aarch64_eg_configs index c1d1d4560a4122bde9f09a13f6aa23388594d2ad..c030a950420763992b56a942017a446cef727725 100644 --- a/example/network/lwip_startup/configs/e2000d_aarch64_eg_configs +++ b/example/network/lwip_startup/configs/e2000d_aarch64_eg_configs @@ -30,6 +30,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y # CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -89,6 +90,7 @@ CONFIG_FXMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -107,6 +109,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -474,7 +477,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/e2000q_aarch32_eg_configs b/example/network/lwip_startup/configs/e2000q_aarch32_eg_configs index 601c5045bb164fffcd762afd8bba22343b9e73e9..593e12064f7c19e8a237fc1b26fe378f5301d79d 100644 --- a/example/network/lwip_startup/configs/e2000q_aarch32_eg_configs +++ b/example/network/lwip_startup/configs/e2000q_aarch32_eg_configs @@ -30,6 +30,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y CONFIG_USE_AARCH64_L1_TO_AARCH32=y +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -89,6 +90,7 @@ CONFIG_FXMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -107,6 +109,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -478,7 +481,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/e2000q_aarch64_eg_configs b/example/network/lwip_startup/configs/e2000q_aarch64_eg_configs index 02d465499e2c9d7df753f43e78b70701fa4d4bcb..f9e1348f13e6930b427bd80dc761e9383b44b67c 100644 --- a/example/network/lwip_startup/configs/e2000q_aarch64_eg_configs +++ b/example/network/lwip_startup/configs/e2000q_aarch64_eg_configs @@ -30,6 +30,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y # CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -89,6 +90,7 @@ CONFIG_FXMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -107,6 +109,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -474,7 +477,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/ft2004_aarch32_eg_configs b/example/network/lwip_startup/configs/ft2004_aarch32_eg_configs index e0fd87208cc7dc58ffe0684a5811c3a907b471ac..29818bfce781446eb0c31a0ee1d08dec0db752b1 100644 --- a/example/network/lwip_startup/configs/ft2004_aarch32_eg_configs +++ b/example/network/lwip_startup/configs/ft2004_aarch32_eg_configs @@ -27,6 +27,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y CONFIG_USE_AARCH64_L1_TO_AARCH32=y +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -85,6 +86,7 @@ CONFIG_FGMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -103,6 +105,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -487,7 +490,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/configs/ft2004_aarch64_eg_configs b/example/network/lwip_startup/configs/ft2004_aarch64_eg_configs index 90b82d86d68859f29e51b9b68d41cbea69aa2fee..08203ba00c1e836ae89591163ffe75b6ae5612d9 100644 --- a/example/network/lwip_startup/configs/ft2004_aarch64_eg_configs +++ b/example/network/lwip_startup/configs/ft2004_aarch64_eg_configs @@ -27,6 +27,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y # CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -85,6 +86,7 @@ CONFIG_FGMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -103,6 +105,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -483,7 +486,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/sdkconfig b/example/network/lwip_startup/sdkconfig index 02d465499e2c9d7df753f43e78b70701fa4d4bcb..f9e1348f13e6930b427bd80dc761e9383b44b67c 100644 --- a/example/network/lwip_startup/sdkconfig +++ b/example/network/lwip_startup/sdkconfig @@ -30,6 +30,7 @@ CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y # CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set # end of Arch Configuration # @@ -89,6 +90,7 @@ CONFIG_FXMAC_PHY_COMMON=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -107,6 +109,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set # CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_LOG_DISPALY_CORE_NUM is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # @@ -474,7 +477,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/network/lwip_startup/sdkconfig.h b/example/network/lwip_startup/sdkconfig.h index 71611377573e05404513b83c8c28785a9ae09103..91567353774a26759956f5fd83c4128b313b522f 100644 --- a/example/network/lwip_startup/sdkconfig.h +++ b/example/network/lwip_startup/sdkconfig.h @@ -28,6 +28,7 @@ #define CONFIG_USE_MMU #define CONFIG_USE_SYS_TICK /* CONFIG_MMU_DEBUG_PRINTS is not set */ +/* CONFIG_BOOT_WITH_FLUSH_CACHE is not set */ /* end of Arch Configuration */ /* Board Configuration */ @@ -81,6 +82,7 @@ /* CONFIG_USE_PWM is not set */ /* CONFIG_USE_IPC is not set */ /* CONFIG_USE_MEDIA is not set */ +/* CONFIG_USE_SCMI_MHU is not set */ /* end of Components Configuration */ #define CONFIG_USE_NEW_LIBC /* end of Standalone Setting */ @@ -97,6 +99,7 @@ #define CONFIG_INTERRUPT_ROLE_MASTER /* CONFIG_INTERRUPT_ROLE_SLAVE is not set */ /* CONFIG_LOG_EXTRA_INFO is not set */ +/* CONFIG_LOG_DISPALY_CORE_NUM is not set */ /* CONFIG_BOOTUP_DEBUG_PRINTS is not set */ /* Linker Options */ @@ -410,7 +413,7 @@ #define CONFIG_FREERTOS_OPTIMIZED_SCHEDULER #define CONFIG_FREERTOS_HZ 1000 #define CONFIG_FREERTOS_MAX_PRIORITIES 32 -#define CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES 11 +#define CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES 13 #define CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES 11 #define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 #define CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE 1024 diff --git a/example/network/lwip_startup/src/lwip_test.c b/example/network/lwip_startup/src/lwip_test.c index 1c6e818d28eacbf9e87e114771877c0c2333857b..b8ecc83d3ca26edd3c72e0ee6df2c22fc8b543ea 100644 --- a/example/network/lwip_startup/src/lwip_test.c +++ b/example/network/lwip_startup/src/lwip_test.c @@ -210,7 +210,7 @@ void LwipTest(void *args) (UBaseType_t)configMAX_PRIORITIES - 1, /* 任务的优先级 */ NULL); /* 任务控制块指针 */ - FASSERT_MSG(ret == pdPASS, "LwipTestCreate Task create is failed"); + FASSERT_MSG(ret == pdPASS, "LwipTestCreate Task creation is failed"); } diff --git a/example/peripheral/qspi/sdkconfig b/example/peripheral/qspi/sdkconfig index 855b203e9c0f2065dff34cc699fac0bb53eb67b5..748ff821e312e83f9e7a8992125771a3364cc132 100644 --- a/example/peripheral/qspi/sdkconfig +++ b/example/peripheral/qspi/sdkconfig @@ -2,7 +2,7 @@ # # Freertos Configuration # -CONFIG_TARGET_NAME="e2000q_freertos_a64" +CONFIG_TARGET_NAME="e2000d_freertos_a64" # end of Freertos Configuration # @@ -26,8 +26,8 @@ CONFIG_USE_SYS_TICK=y # # CONFIG_TARGET_F2000_4 is not set # CONFIG_TARGET_D2000 is not set -CONFIG_TARGET_E2000Q=y -# CONFIG_TARGET_E2000D is not set +# CONFIG_TARGET_E2000Q is not set +CONFIG_TARGET_E2000D=y # CONFIG_TARGET_E2000S is not set CONFIG_TARGET_E2000=y CONFIG_DEFAULT_DEBUG_PRINT_UART1=y @@ -233,7 +233,7 @@ CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y # CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set # end of Letter Shell Configuration -# CONFIG_USE_TLSF is not set +CONFIG_USE_TLSF=y # CONFIG_USE_SDMMC_CMD is not set # CONFIG_USE_CHERRY_USB is not set # end of Third-Party Configuration diff --git a/example/peripheral/qspi/sdkconfig.h b/example/peripheral/qspi/sdkconfig.h index 4e01cd61e2d014cbc61967b11246e67fffd21ef3..4632543a78d20fe69059123fb0c76cda90765caf 100644 --- a/example/peripheral/qspi/sdkconfig.h +++ b/example/peripheral/qspi/sdkconfig.h @@ -3,7 +3,7 @@ /* Freertos Configuration */ -#define CONFIG_TARGET_NAME "e2000q_freertos_a64" +#define CONFIG_TARGET_NAME "e2000d_freertos_a64" /* end of Freertos Configuration */ /* Standalone Setting */ @@ -24,8 +24,8 @@ /* CONFIG_TARGET_F2000_4 is not set */ /* CONFIG_TARGET_D2000 is not set */ -#define CONFIG_TARGET_E2000Q -/* CONFIG_TARGET_E2000D is not set */ +/* CONFIG_TARGET_E2000Q is not set */ +#define CONFIG_TARGET_E2000D /* CONFIG_TARGET_E2000S is not set */ #define CONFIG_TARGET_E2000 #define CONFIG_DEFAULT_DEBUG_PRINT_UART1 @@ -201,7 +201,7 @@ /* CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set */ /* CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set */ /* end of Letter Shell Configuration */ -/* CONFIG_USE_TLSF is not set */ +#define CONFIG_USE_TLSF /* CONFIG_USE_SDMMC_CMD is not set */ /* CONFIG_USE_CHERRY_USB is not set */ /* end of Third-Party Configuration */ diff --git a/example/peripheral/spi/configs/e2000d_aarch32_eg_configs b/example/peripheral/spi/configs/e2000d_aarch32_eg_configs index b0cc925415a86b17304fe0e9ebe5e6ab85a272d9..f71a006b075411682488c2a6e5a0c4ef7924ddf3 100644 --- a/example/peripheral/spi/configs/e2000d_aarch32_eg_configs +++ b/example/peripheral/spi/configs/e2000d_aarch32_eg_configs @@ -69,6 +69,7 @@ CONFIG_ENABLE_Pl011_UART=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -223,6 +224,8 @@ CONFIG_USE_SFUD=y # SFUD Configuration # CONFIG_SFUD_CTRL_FSPIM=y +CONFIG_SFUD_TRANS_MODE_POLL_FIFO=y +# CONFIG_SFUD_TRANS_MODE_INTRRUPT is not set # CONFIG_SFUD_CTRL_FQSPI is not set # end of SFUD Configuration @@ -250,7 +253,7 @@ CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/peripheral/spi/configs/e2000d_aarch64_eg_configs b/example/peripheral/spi/configs/e2000d_aarch64_eg_configs index b047f3081f4e966a1fee48836c63483474e13358..09f7d6c8f40cf588d36bd6769db02fb5560d26d1 100644 --- a/example/peripheral/spi/configs/e2000d_aarch64_eg_configs +++ b/example/peripheral/spi/configs/e2000d_aarch64_eg_configs @@ -69,6 +69,7 @@ CONFIG_ENABLE_Pl011_UART=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -219,6 +220,8 @@ CONFIG_USE_SFUD=y # SFUD Configuration # CONFIG_SFUD_CTRL_FSPIM=y +# CONFIG_SFUD_TRANS_MODE_POLL_FIFO is not set +CONFIG_SFUD_TRANS_MODE_INTRRUPT=y # CONFIG_SFUD_CTRL_FQSPI is not set # end of SFUD Configuration @@ -246,7 +249,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/peripheral/spi/sdkconfig b/example/peripheral/spi/sdkconfig index b047f3081f4e966a1fee48836c63483474e13358..f71a006b075411682488c2a6e5a0c4ef7924ddf3 100644 --- a/example/peripheral/spi/sdkconfig +++ b/example/peripheral/spi/sdkconfig @@ -2,7 +2,7 @@ # # Freertos Configuration # -CONFIG_TARGET_NAME="e2000d_freertos_a64" +CONFIG_TARGET_NAME="e2000d_freertos_a32" # end of Freertos Configuration # @@ -13,12 +13,12 @@ CONFIG_USE_FREERTOS=y # # Arch Configuration # -# CONFIG_TARGET_ARMV8_AARCH32 is not set -CONFIG_TARGET_ARMV8_AARCH64=y +CONFIG_TARGET_ARMV8_AARCH32=y +# CONFIG_TARGET_ARMV8_AARCH64 is not set CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y -# CONFIG_MMU_DEBUG_PRINTS is not set +CONFIG_USE_AARCH64_L1_TO_AARCH32=y # end of Arch Configuration # @@ -69,6 +69,7 @@ CONFIG_ENABLE_Pl011_UART=y # CONFIG_USE_PWM is not set # CONFIG_USE_IPC is not set # CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set # end of Components Configuration CONFIG_USE_NEW_LIBC=y @@ -86,14 +87,14 @@ CONFIG_LOG_ERROR=y CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y # CONFIG_INTERRUPT_ROLE_SLAVE is not set -CONFIG_LOG_EXTRA_INFO=y +# CONFIG_LOG_EXTRA_INFO is not set # CONFIG_BOOTUP_DEBUG_PRINTS is not set # # Linker Options # -# CONFIG_AARCH32_RAM_LD is not set -CONFIG_AARCH64_RAM_LD=y +CONFIG_AARCH32_RAM_LD=y +# CONFIG_AARCH64_RAM_LD is not set # CONFIG_USER_DEFINED_LD is not set CONFIG_LINK_SCRIPT_ROM=y CONFIG_ROM_START_UP_ADDR=0x80100000 @@ -102,8 +103,12 @@ CONFIG_LINK_SCRIPT_RAM=y CONFIG_RAM_START_UP_ADDR=0x81000000 CONFIG_RAM_SIZE_MB=64 CONFIG_HEAP_SIZE=1 -CONFIG_STACK_SIZE=0x100000 -CONFIG_FPU_STACK_SIZE=0x1000 +CONFIG_SVC_STACK_SIZE=0x1000 +CONFIG_SYS_STACK_SIZE=0x1000 +CONFIG_IRQ_STACK_SIZE=0x1000 +CONFIG_ABORT_STACK_SIZE=0x1000 +CONFIG_FIQ_STACK_SIZE=0x1000 +CONFIG_UNDEF_STACK_SIZE=0x1000 # end of Linker Options # @@ -219,6 +224,8 @@ CONFIG_USE_SFUD=y # SFUD Configuration # CONFIG_SFUD_CTRL_FSPIM=y +CONFIG_SFUD_TRANS_MODE_POLL_FIFO=y +# CONFIG_SFUD_TRANS_MODE_INTRRUPT is not set # CONFIG_SFUD_CTRL_FQSPI is not set # end of SFUD Configuration @@ -235,7 +242,7 @@ CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y # CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set # end of Letter Shell Configuration -CONFIG_USE_TLSF=y +# CONFIG_USE_TLSF is not set # CONFIG_USE_SDMMC_CMD is not set # CONFIG_USE_CHERRY_USB is not set # end of Third-Party Configuration @@ -246,7 +253,7 @@ CONFIG_USE_TLSF=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_MAX_PRIORITIES=32 -CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 diff --git a/example/peripheral/spi/sdkconfig.h b/example/peripheral/spi/sdkconfig.h index 76f830e3b9123f70bfd52788b30f98be36d6428c..4e04c66c9091d7423acdd522798b514ece87bb92 100644 --- a/example/peripheral/spi/sdkconfig.h +++ b/example/peripheral/spi/sdkconfig.h @@ -3,7 +3,7 @@ /* Freertos Configuration */ -#define CONFIG_TARGET_NAME "e2000d_freertos_a64" +#define CONFIG_TARGET_NAME "e2000d_freertos_a32" /* end of Freertos Configuration */ /* Standalone Setting */ @@ -12,12 +12,12 @@ /* Arch Configuration */ -/* CONFIG_TARGET_ARMV8_AARCH32 is not set */ -#define CONFIG_TARGET_ARMV8_AARCH64 +#define CONFIG_TARGET_ARMV8_AARCH32 +/* CONFIG_TARGET_ARMV8_AARCH64 is not set */ #define CONFIG_USE_CACHE #define CONFIG_USE_MMU #define CONFIG_USE_SYS_TICK -/* CONFIG_MMU_DEBUG_PRINTS is not set */ +#define CONFIG_USE_AARCH64_L1_TO_AARCH32 /* end of Arch Configuration */ /* Board Configuration */ @@ -64,6 +64,7 @@ /* CONFIG_USE_PWM is not set */ /* CONFIG_USE_IPC is not set */ /* CONFIG_USE_MEDIA is not set */ +/* CONFIG_USE_SCMI_MHU is not set */ /* end of Components Configuration */ #define CONFIG_USE_NEW_LIBC /* end of Standalone Setting */ @@ -79,13 +80,13 @@ #define CONFIG_USE_DEFAULT_INTERRUPT_CONFIG #define CONFIG_INTERRUPT_ROLE_MASTER /* CONFIG_INTERRUPT_ROLE_SLAVE is not set */ -#define CONFIG_LOG_EXTRA_INFO +/* CONFIG_LOG_EXTRA_INFO is not set */ /* CONFIG_BOOTUP_DEBUG_PRINTS is not set */ /* Linker Options */ -/* CONFIG_AARCH32_RAM_LD is not set */ -#define CONFIG_AARCH64_RAM_LD +#define CONFIG_AARCH32_RAM_LD +/* CONFIG_AARCH64_RAM_LD is not set */ /* CONFIG_USER_DEFINED_LD is not set */ #define CONFIG_LINK_SCRIPT_ROM #define CONFIG_ROM_START_UP_ADDR 0x80100000 @@ -94,8 +95,12 @@ #define CONFIG_RAM_START_UP_ADDR 0x81000000 #define CONFIG_RAM_SIZE_MB 64 #define CONFIG_HEAP_SIZE 1 -#define CONFIG_STACK_SIZE 0x100000 -#define CONFIG_FPU_STACK_SIZE 0x1000 +#define CONFIG_SVC_STACK_SIZE 0x1000 +#define CONFIG_SYS_STACK_SIZE 0x1000 +#define CONFIG_IRQ_STACK_SIZE 0x1000 +#define CONFIG_ABORT_STACK_SIZE 0x1000 +#define CONFIG_FIQ_STACK_SIZE 0x1000 +#define CONFIG_UNDEF_STACK_SIZE 0x1000 /* end of Linker Options */ /* Compiler Options */ @@ -190,6 +195,8 @@ /* SFUD Configuration */ #define CONFIG_SFUD_CTRL_FSPIM +#define CONFIG_SFUD_TRANS_MODE_POLL_FIFO +/* CONFIG_SFUD_TRANS_MODE_INTRRUPT is not set */ /* CONFIG_SFUD_CTRL_FQSPI is not set */ /* end of SFUD Configuration */ /* CONFIG_USE_SPIFFS is not set */ @@ -203,7 +210,7 @@ /* CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set */ /* CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set */ /* end of Letter Shell Configuration */ -#define CONFIG_USE_TLSF +/* CONFIG_USE_TLSF is not set */ /* CONFIG_USE_SDMMC_CMD is not set */ /* CONFIG_USE_CHERRY_USB is not set */ /* end of Third-Party Configuration */ @@ -213,7 +220,7 @@ #define CONFIG_FREERTOS_OPTIMIZED_SCHEDULER #define CONFIG_FREERTOS_HZ 1000 #define CONFIG_FREERTOS_MAX_PRIORITIES 32 -#define CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES 13 +#define CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES 11 #define CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES 11 #define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 #define CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE 1024 diff --git a/example/peripheral/usb/cherryusb_host/configs/e2000d_aarch32_eg_configs b/example/peripheral/usb/cherryusb_host/configs/e2000d_aarch32_eg_configs index c52ecc843f5cbc871807a7d0fc791fbbc24edd56..d4a096eca0db911c292f4b15428d718eae459e71 100644 --- a/example/peripheral/usb/cherryusb_host/configs/e2000d_aarch32_eg_configs +++ b/example/peripheral/usb/cherryusb_host/configs/e2000d_aarch32_eg_configs @@ -58,12 +58,26 @@ CONFIG_ENABLE_Pl011_UART=y # CONFIG_USE_TIMER is not set # CONFIG_USE_MIO is not set # CONFIG_USE_SDMMC is not set -# CONFIG_USE_PCIE is not set +CONFIG_USE_PCIE=y + +# +# Pcie Configuration +# +CONFIG_ENABLE_F_PCIE=y +# end of Pcie Configuration + # CONFIG_USE_WDT is not set # CONFIG_USE_DMA is not set # CONFIG_USE_NAND is not set # CONFIG_USE_RTC is not set -# CONFIG_USE_SATA is not set +CONFIG_USE_SATA=y + +# +# FSATA Configuration +# +CONFIG_ENABLE_FSATA=y +# end of FSATA Configuration + # CONFIG_USE_USB is not set # CONFIG_USE_ADC is not set # CONFIG_USE_PWM is not set @@ -216,7 +230,46 @@ CONFIG_FREERTOS_USE_FSPIM=y # # CONFIG_USE_LWIP is not set CONFIG_USE_BACKTRACE=y -# CONFIG_USE_FATFS_0_1_4 is not set +CONFIG_USE_FATFS_0_1_4=y + +# +# FATFS Configuration (0.1.4) +# +CONFIG_FATFS_RAM_DISK=y + +# +# RAM Disk Configuration +# +CONFIG_FATFS_RAM_DISK_BASE=0xa0000000 +CONFIG_FATFS_RAM_DISK_SIZE_MB=500 +CONFIG_FATFS_RAM_DISK_SECTOR_SIZE_BYTE=512 +# end of RAM Disk Configuration + +# CONFIG_FATFS_SDMMC_FSDIO_TF is not set +# CONFIG_FATFS_SDMMC_FSDIO_EMMC is not set +# CONFIG_FATFS_SDMMC_FSDMMC_TF is not set +CONFIG_FATFS_SATA_DISK=y + +# +# SATA Disk Configuration +# +# CONFIG_FATFS_FSATA is not set +CONFIG_FATFS_FSATA_PCIE=y +# end of SATA Disk Configuration + +# CONFIG_FATFS_USB is not set +CONFIG_FATFS_VOLUME_COUNT=6 +# CONFIG_FATFS_LFN_NONE is not set +CONFIG_FATFS_LFN_HEAP=y +# CONFIG_FATFS_LFN_STACK is not set +CONFIG_FATFS_MAX_LFN=255 +CONFIG_FATFS_FS_LOCK=0 +CONFIG_FATFS_TIMEOUT_MS=10000 +CONFIG_FATFS_PER_FILE_CACHE=y +CONFIG_FATFS_ALLOC_PREFER_MEMP=y +CONFIG_FATFS_MEMP_SIZE=2 +# end of FATFS Configuration (0.1.4) + # CONFIG_USE_SFUD is not set # CONFIG_USE_SPIFFS is not set # CONFIG_USE_AMP is not set diff --git a/third-party/cherryusb-0.6.0/port/xhci/usb_config.h b/example/peripheral/usb/cherryusb_host/inc/usb_config.h similarity index 90% rename from third-party/cherryusb-0.6.0/port/xhci/usb_config.h rename to example/peripheral/usb/cherryusb_host/inc/usb_config.h index c7e5547ede5c5c10172cae44847676f81045602f..3a89de76f1fe88caa9f3b9abb257f548a962e81d 100644 --- a/third-party/cherryusb-0.6.0/port/xhci/usb_config.h +++ b/example/peripheral/usb/cherryusb_host/inc/usb_config.h @@ -14,12 +14,13 @@ * FilePath: usb_config.h * Date: 2022-09-19 17:28:44 * LastEditTime: 2022-09-19 17:28:45 - * Description:  This files is for usb hc xhci configuration + * Description:  This file is for usb hc xhci configuration. * * Modify History: * Ver   Who        Date         Changes * ----- ------     --------    -------------------------------------- * 1.0 zhugengyu 2022/9/19 init commit + * 1.1 liqiaozhong 2023/2/10 update to v0.7.0 */ #ifndef USB_CONFIG_H @@ -31,6 +32,13 @@ extern "C" #endif /* ================ USB common Configuration ================ */ +void *usb_hc_malloc(size_t size); +void usb_hc_free(); +void *usb_hc_malloc_align(size_t align, size_t size); + +#define usb_malloc(size) usb_hc_malloc(size) +#define usb_free(ptr) usb_hc_free(ptr) +#define usb_align(align, size) usb_hc_malloc_align(align, size) #ifndef CONFIG_USB_DBG_LEVEL #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR diff --git a/example/peripheral/usb/cherryusb_host/sdkconfig b/example/peripheral/usb/cherryusb_host/sdkconfig index 4556342147c74a28e5937c93e6bb76806c5512e1..d4a096eca0db911c292f4b15428d718eae459e71 100644 --- a/example/peripheral/usb/cherryusb_host/sdkconfig +++ b/example/peripheral/usb/cherryusb_host/sdkconfig @@ -2,7 +2,7 @@ # # Freertos Configuration # -CONFIG_TARGET_NAME="e2000s_freertos_a64" +CONFIG_TARGET_NAME="e2000d_freertos_a32" # end of Freertos Configuration # @@ -13,12 +13,12 @@ CONFIG_USE_FREERTOS=y # # Arch Configuration # -# CONFIG_TARGET_ARMV8_AARCH32 is not set -CONFIG_TARGET_ARMV8_AARCH64=y +CONFIG_TARGET_ARMV8_AARCH32=y +# CONFIG_TARGET_ARMV8_AARCH64 is not set CONFIG_USE_CACHE=y CONFIG_USE_MMU=y CONFIG_USE_SYS_TICK=y -# CONFIG_MMU_DEBUG_PRINTS is not set +CONFIG_USE_AARCH64_L1_TO_AARCH32=y # end of Arch Configuration # @@ -27,8 +27,8 @@ CONFIG_USE_SYS_TICK=y # CONFIG_TARGET_F2000_4 is not set # CONFIG_TARGET_D2000 is not set # CONFIG_TARGET_E2000Q is not set -# CONFIG_TARGET_E2000D is not set -CONFIG_TARGET_E2000S=y +CONFIG_TARGET_E2000D=y +# CONFIG_TARGET_E2000S is not set CONFIG_TARGET_E2000=y CONFIG_DEFAULT_DEBUG_PRINT_UART1=y # CONFIG_DEFAULT_DEBUG_PRINT_UART0 is not set @@ -58,12 +58,26 @@ CONFIG_ENABLE_Pl011_UART=y # CONFIG_USE_TIMER is not set # CONFIG_USE_MIO is not set # CONFIG_USE_SDMMC is not set -# CONFIG_USE_PCIE is not set +CONFIG_USE_PCIE=y + +# +# Pcie Configuration +# +CONFIG_ENABLE_F_PCIE=y +# end of Pcie Configuration + # CONFIG_USE_WDT is not set # CONFIG_USE_DMA is not set # CONFIG_USE_NAND is not set # CONFIG_USE_RTC is not set -# CONFIG_USE_SATA is not set +CONFIG_USE_SATA=y + +# +# FSATA Configuration +# +CONFIG_ENABLE_FSATA=y +# end of FSATA Configuration + # CONFIG_USE_USB is not set # CONFIG_USE_ADC is not set # CONFIG_USE_PWM is not set @@ -78,10 +92,10 @@ CONFIG_USE_NEW_LIBC=y # Building Option # # CONFIG_LOG_VERBOS is not set -CONFIG_LOG_DEBUG=y +# CONFIG_LOG_DEBUG is not set # CONFIG_LOG_INFO is not set # CONFIG_LOG_WARN is not set -# CONFIG_LOG_ERROR is not set +CONFIG_LOG_ERROR=y # CONFIG_LOG_NONE is not set CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y CONFIG_INTERRUPT_ROLE_MASTER=y @@ -92,8 +106,8 @@ CONFIG_LOG_EXTRA_INFO=y # # Linker Options # -# CONFIG_AARCH32_RAM_LD is not set -CONFIG_AARCH64_RAM_LD=y +CONFIG_AARCH32_RAM_LD=y +# CONFIG_AARCH64_RAM_LD is not set # CONFIG_USER_DEFINED_LD is not set CONFIG_LINK_SCRIPT_ROM=y CONFIG_ROM_START_UP_ADDR=0x80100000 @@ -102,8 +116,12 @@ CONFIG_LINK_SCRIPT_RAM=y CONFIG_RAM_START_UP_ADDR=0x81000000 CONFIG_RAM_SIZE_MB=64 CONFIG_HEAP_SIZE=1 -CONFIG_STACK_SIZE=0x100000 -CONFIG_FPU_STACK_SIZE=0x1000 +CONFIG_SVC_STACK_SIZE=0x1000 +CONFIG_SYS_STACK_SIZE=0x1000 +CONFIG_IRQ_STACK_SIZE=0x1000 +CONFIG_ABORT_STACK_SIZE=0x1000 +CONFIG_FIQ_STACK_SIZE=0x1000 +CONFIG_UNDEF_STACK_SIZE=0x1000 # end of Linker Options # @@ -212,7 +230,46 @@ CONFIG_FREERTOS_USE_FSPIM=y # # CONFIG_USE_LWIP is not set CONFIG_USE_BACKTRACE=y -# CONFIG_USE_FATFS_0_1_4 is not set +CONFIG_USE_FATFS_0_1_4=y + +# +# FATFS Configuration (0.1.4) +# +CONFIG_FATFS_RAM_DISK=y + +# +# RAM Disk Configuration +# +CONFIG_FATFS_RAM_DISK_BASE=0xa0000000 +CONFIG_FATFS_RAM_DISK_SIZE_MB=500 +CONFIG_FATFS_RAM_DISK_SECTOR_SIZE_BYTE=512 +# end of RAM Disk Configuration + +# CONFIG_FATFS_SDMMC_FSDIO_TF is not set +# CONFIG_FATFS_SDMMC_FSDIO_EMMC is not set +# CONFIG_FATFS_SDMMC_FSDMMC_TF is not set +CONFIG_FATFS_SATA_DISK=y + +# +# SATA Disk Configuration +# +# CONFIG_FATFS_FSATA is not set +CONFIG_FATFS_FSATA_PCIE=y +# end of SATA Disk Configuration + +# CONFIG_FATFS_USB is not set +CONFIG_FATFS_VOLUME_COUNT=6 +# CONFIG_FATFS_LFN_NONE is not set +CONFIG_FATFS_LFN_HEAP=y +# CONFIG_FATFS_LFN_STACK is not set +CONFIG_FATFS_MAX_LFN=255 +CONFIG_FATFS_FS_LOCK=0 +CONFIG_FATFS_TIMEOUT_MS=10000 +CONFIG_FATFS_PER_FILE_CACHE=y +CONFIG_FATFS_ALLOC_PREFER_MEMP=y +CONFIG_FATFS_MEMP_SIZE=2 +# end of FATFS Configuration (0.1.4) + # CONFIG_USE_SFUD is not set # CONFIG_USE_SPIFFS is not set # CONFIG_USE_AMP is not set diff --git a/example/peripheral/usb/cherryusb_host/sdkconfig.h b/example/peripheral/usb/cherryusb_host/sdkconfig.h index ba85cf18e5ce115bea0c33a49b3a93e32a815042..9272999d4712c2cab85aebfa8258d23527d51397 100644 --- a/example/peripheral/usb/cherryusb_host/sdkconfig.h +++ b/example/peripheral/usb/cherryusb_host/sdkconfig.h @@ -3,7 +3,7 @@ /* Freertos Configuration */ -#define CONFIG_TARGET_NAME "e2000s_freertos_a64" +#define CONFIG_TARGET_NAME "e2000d_freertos_a32" /* end of Freertos Configuration */ /* Standalone Setting */ @@ -12,12 +12,12 @@ /* Arch Configuration */ -/* CONFIG_TARGET_ARMV8_AARCH32 is not set */ -#define CONFIG_TARGET_ARMV8_AARCH64 +#define CONFIG_TARGET_ARMV8_AARCH32 +/* CONFIG_TARGET_ARMV8_AARCH64 is not set */ #define CONFIG_USE_CACHE #define CONFIG_USE_MMU #define CONFIG_USE_SYS_TICK -/* CONFIG_MMU_DEBUG_PRINTS is not set */ +#define CONFIG_USE_AARCH64_L1_TO_AARCH32 /* end of Arch Configuration */ /* Board Configuration */ @@ -25,8 +25,8 @@ /* CONFIG_TARGET_F2000_4 is not set */ /* CONFIG_TARGET_D2000 is not set */ /* CONFIG_TARGET_E2000Q is not set */ -/* CONFIG_TARGET_E2000D is not set */ -#define CONFIG_TARGET_E2000S +#define CONFIG_TARGET_E2000D +/* CONFIG_TARGET_E2000S is not set */ #define CONFIG_TARGET_E2000 #define CONFIG_DEFAULT_DEBUG_PRINT_UART1 /* CONFIG_DEFAULT_DEBUG_PRINT_UART0 is not set */ @@ -53,12 +53,22 @@ /* CONFIG_USE_TIMER is not set */ /* CONFIG_USE_MIO is not set */ /* CONFIG_USE_SDMMC is not set */ -/* CONFIG_USE_PCIE is not set */ +#define CONFIG_USE_PCIE + +/* Pcie Configuration */ + +#define CONFIG_ENABLE_F_PCIE +/* end of Pcie Configuration */ /* CONFIG_USE_WDT is not set */ /* CONFIG_USE_DMA is not set */ /* CONFIG_USE_NAND is not set */ /* CONFIG_USE_RTC is not set */ -/* CONFIG_USE_SATA is not set */ +#define CONFIG_USE_SATA + +/* FSATA Configuration */ + +#define CONFIG_ENABLE_FSATA +/* end of FSATA Configuration */ /* CONFIG_USE_USB is not set */ /* CONFIG_USE_ADC is not set */ /* CONFIG_USE_PWM is not set */ @@ -71,10 +81,10 @@ /* Building Option */ /* CONFIG_LOG_VERBOS is not set */ -#define CONFIG_LOG_DEBUG +/* CONFIG_LOG_DEBUG is not set */ /* CONFIG_LOG_INFO is not set */ /* CONFIG_LOG_WARN is not set */ -/* CONFIG_LOG_ERROR is not set */ +#define CONFIG_LOG_ERROR /* CONFIG_LOG_NONE is not set */ #define CONFIG_USE_DEFAULT_INTERRUPT_CONFIG #define CONFIG_INTERRUPT_ROLE_MASTER @@ -84,8 +94,8 @@ /* Linker Options */ -/* CONFIG_AARCH32_RAM_LD is not set */ -#define CONFIG_AARCH64_RAM_LD +#define CONFIG_AARCH32_RAM_LD +/* CONFIG_AARCH64_RAM_LD is not set */ /* CONFIG_USER_DEFINED_LD is not set */ #define CONFIG_LINK_SCRIPT_ROM #define CONFIG_ROM_START_UP_ADDR 0x80100000 @@ -94,8 +104,12 @@ #define CONFIG_RAM_START_UP_ADDR 0x81000000 #define CONFIG_RAM_SIZE_MB 64 #define CONFIG_HEAP_SIZE 1 -#define CONFIG_STACK_SIZE 0x100000 -#define CONFIG_FPU_STACK_SIZE 0x1000 +#define CONFIG_SVC_STACK_SIZE 0x1000 +#define CONFIG_SYS_STACK_SIZE 0x1000 +#define CONFIG_IRQ_STACK_SIZE 0x1000 +#define CONFIG_ABORT_STACK_SIZE 0x1000 +#define CONFIG_FIQ_STACK_SIZE 0x1000 +#define CONFIG_UNDEF_STACK_SIZE 0x1000 /* end of Linker Options */ /* Compiler Options */ @@ -184,7 +198,40 @@ /* CONFIG_USE_LWIP is not set */ #define CONFIG_USE_BACKTRACE -/* CONFIG_USE_FATFS_0_1_4 is not set */ +#define CONFIG_USE_FATFS_0_1_4 + +/* FATFS Configuration (0.1.4) */ + +#define CONFIG_FATFS_RAM_DISK + +/* RAM Disk Configuration */ + +#define CONFIG_FATFS_RAM_DISK_BASE 0xa0000000 +#define CONFIG_FATFS_RAM_DISK_SIZE_MB 500 +#define CONFIG_FATFS_RAM_DISK_SECTOR_SIZE_BYTE 512 +/* end of RAM Disk Configuration */ +/* CONFIG_FATFS_SDMMC_FSDIO_TF is not set */ +/* CONFIG_FATFS_SDMMC_FSDIO_EMMC is not set */ +/* CONFIG_FATFS_SDMMC_FSDMMC_TF is not set */ +#define CONFIG_FATFS_SATA_DISK + +/* SATA Disk Configuration */ + +/* CONFIG_FATFS_FSATA is not set */ +#define CONFIG_FATFS_FSATA_PCIE +/* end of SATA Disk Configuration */ +/* CONFIG_FATFS_USB is not set */ +#define CONFIG_FATFS_VOLUME_COUNT 6 +/* CONFIG_FATFS_LFN_NONE is not set */ +#define CONFIG_FATFS_LFN_HEAP +/* CONFIG_FATFS_LFN_STACK is not set */ +#define CONFIG_FATFS_MAX_LFN 255 +#define CONFIG_FATFS_FS_LOCK 0 +#define CONFIG_FATFS_TIMEOUT_MS 10000 +#define CONFIG_FATFS_PER_FILE_CACHE +#define CONFIG_FATFS_ALLOC_PREFER_MEMP +#define CONFIG_FATFS_MEMP_SIZE 2 +/* end of FATFS Configuration (0.1.4) */ /* CONFIG_USE_SFUD is not set */ /* CONFIG_USE_SPIFFS is not set */ /* CONFIG_USE_AMP is not set */ diff --git a/example/storage/qspi_spiffs/sdkconfig b/example/storage/qspi_spiffs/sdkconfig index 3842526ff5eb197cf1949e886b891c2d25eba73f..d6d2f93dc18488b4c73249b8bc2fb993ff51380b 100644 --- a/example/storage/qspi_spiffs/sdkconfig +++ b/example/storage/qspi_spiffs/sdkconfig @@ -2,7 +2,7 @@ # # Freertos Configuration # -CONFIG_TARGET_NAME="e2000q_freertos_a64" +CONFIG_TARGET_NAME="e2000d_freertos_a64" # end of Freertos Configuration # @@ -26,8 +26,8 @@ CONFIG_USE_SYS_TICK=y # # CONFIG_TARGET_F2000_4 is not set # CONFIG_TARGET_D2000 is not set -CONFIG_TARGET_E2000Q=y -# CONFIG_TARGET_E2000D is not set +# CONFIG_TARGET_E2000Q is not set +CONFIG_TARGET_E2000D=y # CONFIG_TARGET_E2000S is not set CONFIG_TARGET_E2000=y CONFIG_DEFAULT_DEBUG_PRINT_UART1=y @@ -252,7 +252,7 @@ CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y # CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set # end of Letter Shell Configuration -# CONFIG_USE_TLSF is not set +CONFIG_USE_TLSF=y # CONFIG_USE_SDMMC_CMD is not set # CONFIG_USE_CHERRY_USB is not set # end of Third-Party Configuration diff --git a/example/storage/qspi_spiffs/sdkconfig.h b/example/storage/qspi_spiffs/sdkconfig.h index e4710ac91da99c98885a091b4230aba3093aba3c..321b9eda0d3ec0e1fb5260899f1eb676d5e93abe 100644 --- a/example/storage/qspi_spiffs/sdkconfig.h +++ b/example/storage/qspi_spiffs/sdkconfig.h @@ -3,7 +3,7 @@ /* Freertos Configuration */ -#define CONFIG_TARGET_NAME "e2000q_freertos_a64" +#define CONFIG_TARGET_NAME "e2000d_freertos_a64" /* end of Freertos Configuration */ /* Standalone Setting */ @@ -24,8 +24,8 @@ /* CONFIG_TARGET_F2000_4 is not set */ /* CONFIG_TARGET_D2000 is not set */ -#define CONFIG_TARGET_E2000Q -/* CONFIG_TARGET_E2000D is not set */ +/* CONFIG_TARGET_E2000Q is not set */ +#define CONFIG_TARGET_E2000D /* CONFIG_TARGET_E2000S is not set */ #define CONFIG_TARGET_E2000 #define CONFIG_DEFAULT_DEBUG_PRINT_UART1 @@ -216,7 +216,7 @@ /* CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set */ /* CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set */ /* end of Letter Shell Configuration */ -/* CONFIG_USE_TLSF is not set */ +#define CONFIG_USE_TLSF /* CONFIG_USE_SDMMC_CMD is not set */ /* CONFIG_USE_CHERRY_USB is not set */ /* end of Third-Party Configuration */ diff --git a/example/storage/spim_spiffs/Kconfig b/example/storage/spim_spiffs/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..0277fb8553f2132f097012a78633194f6173c156 --- /dev/null +++ b/example/storage/spim_spiffs/Kconfig @@ -0,0 +1,19 @@ +# +# For a description of the syntax of this configuration file, +# see tools/kconfiglib/kconfig-language.txt. +# + + +mainmenu "Phytium Freertos Configuration" + + menu "Freertos Configuration" + config TARGET_NAME + string "Build Target Name" + default "freertos" + help + Build Target name for the demo + +endmenu + +source "$(FREERTOS_SDK_ROOT)/Kconfig" + diff --git a/example/storage/spim_spiffs/README.md b/example/storage/spim_spiffs/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b41445e0178487df6029af7b9c3adc88048a3e9d --- /dev/null +++ b/example/storage/spim_spiffs/README.md @@ -0,0 +1,135 @@ +# SPIFFS SPI Nor-flash 文件系统测试 +## 1. 例程介绍 + +>介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作
+ +[SPIFFS](https://github.com/pellepl/spiffs) 是一个面向SPI FLASH的文件系统, 它需要的系统资源极少,可以完全运行在RAM中不需要堆的支持, 有以下几个特点, + +- 1. 面向小型嵌入式系统,不要求系统支持堆和动态内存 +- 2. 尽可能少地进行擦除,只进行大块擦除,清除小块数据时采用标记的方法 +- 3. 支持负载均衡,尽可能延长 Flash 的使用寿命 +- 4. 内置文件系统的一致性检查,对文件系统损坏有一定的保护能力 +- 5. 使用方便,高度可配置 + +但是,SPIFFS 也存在以下几个缺陷, + +- 1. 不支持目录,SPIFFS 提供的是一个平面结构文件系统,路径 `tmp/myfile.txt` 会直接被创建成一个名字为 `tmp/myfile.txt` 的文件 +- 2. 不是实时的,一个写操作的持续时间可能比另一个长得多 +- 3. 支持的 Flash 容量不能超过 128 MB +- 4. 不支持坏块检测和坏块处理 + +本例程通过Freertos下的SPIFFS测试,验证了SPIM Nor-flash文件系统的基本功能,如文件系统格式化,文件的创建、读写、删除和枚举等。例程在E2000 test板上测试通过,使用的Nor Flash介质型号是GD25LQ128E,容量为16MB,如下: +![hardware](./figs/hardware.jpg) + +## 2. 如何使用例程 + +>描述开发平台准备,使用例程配置,构建和下载镜像的过程
+ +### 2.1 硬件配置方法 + +>哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)
+ +本例程支持的硬件平台包括 +- E2000D开发板 +- E2000S开发板 + +对应的配置项是 +- CONFIG_TARGET_E2000D + + +- 本例程适配了GD25Q256、GD25Q128、GD25Q64、S25FS256的Nor-Flash芯片,如使用其他型号,需自行参考适配 +### 2.2 SDK配置方法 + +>依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)
+ +使能以下配置 + +- CONFIG_USE_SPI,使能SPI驱动组件 +- CONFIG_USE_FSPIM,选择FSPIM驱动 +- CONFIG_USE_IOMUX,使能IO复用驱动组件 +- CONFIG_ENABLE_FIOMUX,选择FIOMUX驱动 +- CONFIG_USE_GPIO,使能GPIO驱动组件 +- CONFIG_ENABLE_F_GPIO,选择FGPIO驱动 +- CONFIG_USE_SFUD,选择SFUD协议框架 +- CONFIG_SFUD_CTRL_F_SPIM,关联SFUD框架和FSPIM驱动 +- CONFIG_USE_SPIFFS CONFIG_SPIFFS_ON_FSPIM_SFUD,使能SPIFFS + +本例子已经提供好具体的编译指令,以下进行介绍: +- make 将目录下的工程进行编译 +- make clean 将目录下的工程进行清理 +- make boot 将目录下的工程进行编译,并将生成的elf 复制到目标地址 +- make load_e2000d_aarch64 将预设64bit e2000d 下的配置加载至工程中 +- make load_e2000d_aarch32 将预设32bit e2000d 下的配置加载至工程中 +- make menuconfig 配置目录下的参数变量 +- make backup_kconfig 将目录下的sdkconfig 备份到./configs下 + +### 2.3 构建和下载 + +>描述构建、烧录下载镜像的过程,列出相关的命令
+ +#### 2.3.1 构建过程 + +- 在host侧完成配置 +配置成e2000d,对于其它平台,使用对应的默认配置,如ft2004 `make load_ft2004_aarch32` + +- 选择目标平台 +``` +make load_e2000d_aarch64 +``` + +- 选择例程需要的配置 +``` +make menuconfig +``` + +- 进行编译 +``` +make +``` + +- 将编译出的镜像放置到tftp目录下 +``` +make boot +``` + +#### 2.3.2 下载过程 + +- host侧设置重启host侧tftp服务器 +``` +sudo service tftpd-hpa restart +``` + +- 开发板侧使用bootelf命令跳转 +``` +setenv ipaddr 192.168.4.20 +setenv serverip 192.168.4.50 +setenv gatewayip 192.168.4.1 +tftpboot 0x90100000 freertos.elf +bootelf -p 0x90100000 +``` + +### 2.4 输出与实验现象 + +>描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)
+程序启动后,依次创建Init、Read、Write任务,创建单次模式软件定时器用于删除任务,Init任务会首先初始化并挂载spim flash的部分区域(可通过FSPIFFS_IF_FORMAT选择是否进行格式化操作),随后创建一个文件,然后释放信号量通知Read和Write任务开始执行; + +- init完成,挂载文件系统完成,创建测试文件 +![init](./figs/init.png) + +- 读写任务周期性执行,有两个读任务,一个写任务 +![wr](./figs/wr.png) + +- 软件定时器触发,删除读写任务 +![delete](./figs/delete.png) + +## 3. 如何解决问题 + +>主要记录使用例程中可能会遇到的问题,给出相应的解决方案
+ +- FSPIFFS_IF_FORMAT决定初始化阶段是否格式化指定的区域,TRUE为格式化,FLASE为不格式化 + +## 4. 修改历史记录 + +>记录例程的重大修改记录,标明修改发生的版本号
+ +v0.1. 2022-10-27 首次合入 \ No newline at end of file diff --git a/example/storage/spim_spiffs/configs/e2000d_aarch32_eg_configs b/example/storage/spim_spiffs/configs/e2000d_aarch32_eg_configs new file mode 100644 index 0000000000000000000000000000000000000000..669579a7b50c809e6e83cc265e5afd7175f1c03f --- /dev/null +++ b/example/storage/spim_spiffs/configs/e2000d_aarch32_eg_configs @@ -0,0 +1,276 @@ + +# +# Freertos Configuration +# +CONFIG_TARGET_NAME="e2000d_freertos_a32" +# end of Freertos Configuration + +# +# Standalone Setting +# +CONFIG_USE_FREERTOS=y + +# +# Arch Configuration +# +CONFIG_TARGET_ARMV8_AARCH32=y +# CONFIG_TARGET_ARMV8_AARCH64 is not set +CONFIG_USE_CACHE=y +CONFIG_USE_MMU=y +CONFIG_USE_SYS_TICK=y +CONFIG_USE_AARCH64_L1_TO_AARCH32=y +# end of Arch Configuration + +# +# Board Configuration +# +# CONFIG_TARGET_F2000_4 is not set +# CONFIG_TARGET_D2000 is not set +# CONFIG_TARGET_E2000Q is not set +CONFIG_TARGET_E2000D=y +# CONFIG_TARGET_E2000S is not set +CONFIG_TARGET_E2000=y +CONFIG_DEFAULT_DEBUG_PRINT_UART1=y +# CONFIG_DEFAULT_DEBUG_PRINT_UART0 is not set +# CONFIG_DEFAULT_DEBUG_PRINT_UART2 is not set +# end of Board Configuration + +# +# Components Configuration +# +CONFIG_USE_SPI=y +CONFIG_USE_FSPIM=y +# CONFIG_USE_QSPI is not set +CONFIG_USE_GIC=y +CONFIG_ENABLE_GICV3=y +CONFIG_USE_SERIAL=y + +# +# Usart Configuration +# +CONFIG_ENABLE_Pl011_UART=y +# end of Usart Configuration + +# CONFIG_USE_GPIO is not set +# CONFIG_USE_ETH is not set +# CONFIG_USE_CAN is not set +# CONFIG_USE_I2C is not set +# CONFIG_USE_TIMER is not set +# CONFIG_USE_MIO is not set +# CONFIG_USE_SDMMC is not set +# CONFIG_USE_PCIE is not set +# CONFIG_USE_WDT is not set +# CONFIG_USE_DMA is not set +# CONFIG_USE_NAND is not set +# CONFIG_USE_RTC is not set +# CONFIG_USE_SATA is not set +# CONFIG_USE_USB is not set +# CONFIG_USE_ADC is not set +# CONFIG_USE_PWM is not set +# CONFIG_USE_IPC is not set +# CONFIG_USE_MEDIA is not set +# end of Components Configuration + +CONFIG_USE_NEW_LIBC=y +# end of Standalone Setting + +# +# Building Option +# +# CONFIG_LOG_VERBOS is not set +# CONFIG_LOG_DEBUG is not set +# CONFIG_LOG_INFO is not set +# CONFIG_LOG_WARN is not set +CONFIG_LOG_ERROR=y +# CONFIG_LOG_NONE is not set +CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y +CONFIG_INTERRUPT_ROLE_MASTER=y +# CONFIG_INTERRUPT_ROLE_SLAVE is not set +# CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_BOOTUP_DEBUG_PRINTS is not set + +# +# Linker Options +# +CONFIG_AARCH32_RAM_LD=y +# CONFIG_AARCH64_RAM_LD is not set +# CONFIG_USER_DEFINED_LD is not set +CONFIG_LINK_SCRIPT_ROM=y +CONFIG_ROM_START_UP_ADDR=0x80100000 +CONFIG_ROM_SIZE_MB=1 +CONFIG_LINK_SCRIPT_RAM=y +CONFIG_RAM_START_UP_ADDR=0x81000000 +CONFIG_RAM_SIZE_MB=64 +CONFIG_HEAP_SIZE=1 +CONFIG_SVC_STACK_SIZE=0x1000 +CONFIG_SYS_STACK_SIZE=0x1000 +CONFIG_IRQ_STACK_SIZE=0x1000 +CONFIG_ABORT_STACK_SIZE=0x1000 +CONFIG_FIQ_STACK_SIZE=0x1000 +CONFIG_UNDEF_STACK_SIZE=0x1000 +# end of Linker Options + +# +# Compiler Options +# + +# +# Cross-Compiler Setting +# +CONFIG_GCC_OPTIMIZE_LEVEL=0 +# CONFIG_USE_EXT_COMPILER is not set +# CONFIG_USE_KLIN_SYS is not set +# end of Cross-Compiler Setting + +CONFIG_OUTPUT_BINARY=y +# end of Compiler Options +# end of Building Option + +# +# Component Configuration +# + +# +# Freertos Uart Drivers +# +CONFIG_FREERTOS_USE_UART=y +# end of Freertos Uart Drivers + +# +# Freertos Pwm Drivers +# +# CONFIG_FREERTOS_USE_PWM is not set +# end of Freertos Pwm Drivers + +# +# Freertos Qspi Drivers +# +# CONFIG_FREERTOS_USE_QSPI is not set +# end of Freertos Qspi Drivers + +# +# Freertos Wdt Drivers +# +# CONFIG_FREERTOS_USE_WDT is not set +# end of Freertos Wdt Drivers + +# +# Freertos Eth Drivers +# +# CONFIG_FREERTOS_USE_XMAC is not set +# CONFIG_FREERTOS_USE_GMAC is not set +# end of Freertos Eth Drivers + +# +# Freertos Gpio Drivers +# +# CONFIG_FREERTOS_USE_GPIO is not set +# end of Freertos Gpio Drivers + +# +# Freertos Spim Drivers +# +CONFIG_FREERTOS_USE_FSPIM=y +# end of Freertos Spim Drivers + +# +# Freertos DMA Drivers +# +# CONFIG_FREERTOS_USE_FDDMA is not set +# CONFIG_FREERTOS_USE_FGDMA is not set +# end of Freertos DMA Drivers + +# +# Freertos Adc Drivers +# +# CONFIG_FREERTOS_USE_ADC is not set +# end of Freertos Adc Drivers + +# +# Freertos Can Drivers +# +# CONFIG_FREERTOS_USE_CAN is not set +# end of Freertos Can Drivers + +# +# Freertos I2c Drivers +# +# CONFIG_FREERTOS_USE_I2C is not set +# end of Freertos I2c Drivers + +# +# Freertos Mio Drivers +# +# CONFIG_FREERTOS_USE_MIO is not set +# end of Freertos Mio Drivers + +# +# Freertos Timer Drivers +# +# CONFIG_FREERTOS_USE_TIMER is not set +# end of Freertos Timer Drivers +# end of Component Configuration + +# +# Third-Party Configuration +# +# CONFIG_USE_LWIP is not set +CONFIG_USE_BACKTRACE=y +# CONFIG_USE_FATFS_0_1_4 is not set +CONFIG_USE_SFUD=y + +# +# SFUD Configuration +# +CONFIG_SFUD_CTRL_FSPIM=y +# CONFIG_SFUD_CTRL_FQSPI is not set +# end of SFUD Configuration + +CONFIG_USE_SPIFFS=y + +# +# SPIFFS Configuration +# +CONFIG_SPIFFS_ON_FSPIM_SFUD=y +# CONFIG_SPIFFS_ON_FQSPI_SFUD is not set +# end of SPIFFS Configuration + +# CONFIG_USE_AMP is not set +CONFIG_USE_LETTER_SHELL=y + +# +# Letter Shell Configuration +# +CONFIG_LS_PL011_UART=y +CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y +# CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set +# CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set +# end of Letter Shell Configuration + +CONFIG_USE_TLSF=y +# CONFIG_USE_SDMMC_CMD is not set +# CONFIG_USE_CHERRY_USB is not set +# end of Third-Party Configuration + +# +# Kernel Configuration +# +CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_MAX_PRIORITIES=32 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 +CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 +CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 +CONFIG_FREERTOS_MAX_TASK_NAME_LEN=32 +CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 +CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 +CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 +CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y +# CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set +CONFIG_FREERTOS_TOTAL_HEAP_SIZE=10240 +CONFIG_FREERTOS_TASK_FPU_SUPPORT=1 +# end of Kernel Configuration diff --git a/example/storage/spim_spiffs/configs/e2000d_aarch64_eg_configs b/example/storage/spim_spiffs/configs/e2000d_aarch64_eg_configs new file mode 100644 index 0000000000000000000000000000000000000000..7f168fdce7159842cef5f7444c004aa1a25d9303 --- /dev/null +++ b/example/storage/spim_spiffs/configs/e2000d_aarch64_eg_configs @@ -0,0 +1,286 @@ + +# +# Freertos Configuration +# +CONFIG_TARGET_NAME="e2000d_freertos_a64" +# end of Freertos Configuration + +# +# Standalone Setting +# +CONFIG_USE_FREERTOS=y + +# +# Arch Configuration +# +# CONFIG_TARGET_ARMV8_AARCH32 is not set +CONFIG_TARGET_ARMV8_AARCH64=y +CONFIG_USE_CACHE=y +CONFIG_USE_MMU=y +CONFIG_USE_SYS_TICK=y +# CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set +# end of Arch Configuration + +# +# Board Configuration +# +# CONFIG_TARGET_F2000_4 is not set +# CONFIG_TARGET_D2000 is not set +# CONFIG_TARGET_E2000Q is not set +CONFIG_TARGET_E2000D=y +# CONFIG_TARGET_E2000S is not set +CONFIG_TARGET_E2000=y +CONFIG_DEFAULT_DEBUG_PRINT_UART1=y +# CONFIG_DEFAULT_DEBUG_PRINT_UART0 is not set +# CONFIG_DEFAULT_DEBUG_PRINT_UART2 is not set +# end of Board Configuration + +# +# Components Configuration +# +CONFIG_USE_SPI=y +CONFIG_USE_FSPIM=y +CONFIG_USE_QSPI=y + +# +# Qspi Configuration +# +CONFIG_USE_FQSPI=y +# end of Qspi Configuration + +CONFIG_USE_GIC=y +CONFIG_ENABLE_GICV3=y +CONFIG_USE_SERIAL=y + +# +# Usart Configuration +# +CONFIG_ENABLE_Pl011_UART=y +# end of Usart Configuration + +# CONFIG_USE_GPIO is not set +# CONFIG_USE_ETH is not set +# CONFIG_USE_CAN is not set +# CONFIG_USE_I2C is not set +# CONFIG_USE_TIMER is not set +# CONFIG_USE_MIO is not set +# CONFIG_USE_SDMMC is not set +# CONFIG_USE_PCIE is not set +# CONFIG_USE_WDT is not set +# CONFIG_USE_DMA is not set +# CONFIG_USE_NAND is not set +# CONFIG_USE_RTC is not set +# CONFIG_USE_SATA is not set +# CONFIG_USE_USB is not set +# CONFIG_USE_ADC is not set +# CONFIG_USE_PWM is not set +# CONFIG_USE_IPC is not set +# CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set +# end of Components Configuration + +CONFIG_USE_NEW_LIBC=y +# end of Standalone Setting + +# +# Building Option +# +# CONFIG_LOG_VERBOS is not set +# CONFIG_LOG_DEBUG is not set +# CONFIG_LOG_INFO is not set +# CONFIG_LOG_WARN is not set +CONFIG_LOG_ERROR=y +# CONFIG_LOG_NONE is not set +CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y +CONFIG_INTERRUPT_ROLE_MASTER=y +# CONFIG_INTERRUPT_ROLE_SLAVE is not set +# CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_BOOTUP_DEBUG_PRINTS is not set + +# +# Linker Options +# +# CONFIG_AARCH32_RAM_LD is not set +CONFIG_AARCH64_RAM_LD=y +# CONFIG_USER_DEFINED_LD is not set +CONFIG_LINK_SCRIPT_ROM=y +CONFIG_ROM_START_UP_ADDR=0x80100000 +CONFIG_ROM_SIZE_MB=1 +CONFIG_LINK_SCRIPT_RAM=y +CONFIG_RAM_START_UP_ADDR=0x81000000 +CONFIG_RAM_SIZE_MB=64 +CONFIG_HEAP_SIZE=1 +CONFIG_STACK_SIZE=0x100000 +CONFIG_FPU_STACK_SIZE=0x1000 +# end of Linker Options + +# +# Compiler Options +# + +# +# Cross-Compiler Setting +# +CONFIG_GCC_OPTIMIZE_LEVEL=0 +# CONFIG_USE_EXT_COMPILER is not set +# CONFIG_USE_KLIN_SYS is not set +# end of Cross-Compiler Setting + +CONFIG_OUTPUT_BINARY=y +# end of Compiler Options +# end of Building Option + +# +# Component Configuration +# + +# +# Freertos Uart Drivers +# +CONFIG_FREERTOS_USE_UART=y +# end of Freertos Uart Drivers + +# +# Freertos Pwm Drivers +# +# CONFIG_FREERTOS_USE_PWM is not set +# end of Freertos Pwm Drivers + +# +# Freertos Qspi Drivers +# +CONFIG_FREERTOS_USE_QSPI=y +# end of Freertos Qspi Drivers + +# +# Freertos Wdt Drivers +# +# CONFIG_FREERTOS_USE_WDT is not set +# end of Freertos Wdt Drivers + +# +# Freertos Eth Drivers +# +# CONFIG_FREERTOS_USE_XMAC is not set +# CONFIG_FREERTOS_USE_GMAC is not set +# end of Freertos Eth Drivers + +# +# Freertos Gpio Drivers +# +# CONFIG_FREERTOS_USE_GPIO is not set +# end of Freertos Gpio Drivers + +# +# Freertos Spim Drivers +# +CONFIG_FREERTOS_USE_FSPIM=y +# end of Freertos Spim Drivers + +# +# Freertos DMA Drivers +# +# CONFIG_FREERTOS_USE_FDDMA is not set +# CONFIG_FREERTOS_USE_FGDMA is not set +# end of Freertos DMA Drivers + +# +# Freertos Adc Drivers +# +# CONFIG_FREERTOS_USE_ADC is not set +# end of Freertos Adc Drivers + +# +# Freertos Can Drivers +# +# CONFIG_FREERTOS_USE_CAN is not set +# end of Freertos Can Drivers + +# +# Freertos I2c Drivers +# +# CONFIG_FREERTOS_USE_I2C is not set +# end of Freertos I2c Drivers + +# +# Freertos Mio Drivers +# +# CONFIG_FREERTOS_USE_MIO is not set +# end of Freertos Mio Drivers + +# +# Freertos Timer Drivers +# +# CONFIG_FREERTOS_USE_TIMER is not set +# end of Freertos Timer Drivers +# end of Component Configuration + +# +# Third-Party Configuration +# +# CONFIG_USE_LWIP is not set +CONFIG_USE_BACKTRACE=y +# CONFIG_USE_FATFS_0_1_4 is not set +CONFIG_USE_SFUD=y + +# +# SFUD Configuration +# +CONFIG_SFUD_CTRL_FSPIM=y +CONFIG_SFUD_TRANS_MODE_POLL_FIFO=y +# CONFIG_SFUD_TRANS_MODE_INTRRUPT is not set +CONFIG_SFUD_CTRL_FQSPI=y +# CONFIG_SFUD_QSPI_READ_MODE_READ is not set +# CONFIG_SFUD_QSPI_READ_MODE_DUAL_READ is not set +CONFIG_SFUD_QSPI_READ_MODE_QUAD_READ=y +# end of SFUD Configuration + +CONFIG_USE_SPIFFS=y + +# +# SPIFFS Configuration +# +CONFIG_SPIFFS_ON_FSPIM_SFUD=y +# CONFIG_SPIFFS_ON_FQSPI_SFUD is not set +# end of SPIFFS Configuration + +# CONFIG_USE_AMP is not set +CONFIG_USE_LETTER_SHELL=y + +# +# Letter Shell Configuration +# +CONFIG_LS_PL011_UART=y +CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y +# CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set +# CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set +# end of Letter Shell Configuration + +CONFIG_USE_TLSF=y +# CONFIG_USE_SDMMC_CMD is not set +# CONFIG_USE_CHERRY_USB is not set +# end of Third-Party Configuration + +# +# Kernel Configuration +# +CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_MAX_PRIORITIES=32 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 +CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 +CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 +CONFIG_FREERTOS_MAX_TASK_NAME_LEN=32 +CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 +CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 +CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 +CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y +# CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set +CONFIG_FREERTOS_TOTAL_HEAP_SIZE=10240 +CONFIG_FREERTOS_TASK_FPU_SUPPORT=1 +# end of Kernel Configuration diff --git a/example/storage/spim_spiffs/figs/delete.png b/example/storage/spim_spiffs/figs/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..fb0d47c2e106319953300b8e2da62e54a44513b2 Binary files /dev/null and b/example/storage/spim_spiffs/figs/delete.png differ diff --git a/example/storage/spim_spiffs/figs/hardware.jpg b/example/storage/spim_spiffs/figs/hardware.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e655675198ab62038cc4360ea98c90617803c4b5 Binary files /dev/null and b/example/storage/spim_spiffs/figs/hardware.jpg differ diff --git a/example/storage/spim_spiffs/figs/init.png b/example/storage/spim_spiffs/figs/init.png new file mode 100644 index 0000000000000000000000000000000000000000..49fe3c33bf239f172ec58ed1cdf05b3631d3ab19 Binary files /dev/null and b/example/storage/spim_spiffs/figs/init.png differ diff --git a/example/storage/spim_spiffs/figs/wr.png b/example/storage/spim_spiffs/figs/wr.png new file mode 100644 index 0000000000000000000000000000000000000000..05b0cf56ceb81102d5b02ef24238cc6df1b51345 Binary files /dev/null and b/example/storage/spim_spiffs/figs/wr.png differ diff --git a/example/storage/spim_spiffs/inc/spim_spiffs_example.h b/example/storage/spim_spiffs/inc/spim_spiffs_example.h new file mode 100644 index 0000000000000000000000000000000000000000..44b464bb81912ada8b70c61250b37beefcb4d6b9 --- /dev/null +++ b/example/storage/spim_spiffs/inc/spim_spiffs_example.h @@ -0,0 +1,32 @@ +/* + * Copyright : (C) 2022 Phytium Information Technology, Inc. + * All Rights Reserved. + * + * This program is OPEN SOURCE software: you can redistribute it and/or modify it + * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd, + * either version 1.0 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 Phytium Public License for more details. + * + * + * FilePath: spim_spiffs_example.h + * Date: 2022-06-17 10:42:40 + * LastEditTime: 2022-06-17 10:42:40 + * Description: This file is for the spim_spiffs example function declarations. + * + * Modify History: + * Ver Who Date Changes + * ----- ------ -------- -------------------------------------- + * 1.0 liqiaozhong 2022/11/2 first commit + * + */ + +#ifndef SPIM_SPIFFS_EXAMPLE_H +#define SPIM_SPIFFS_EXAMPLE_H + +/* spim spiffs read and write test */ +BaseType_t FFreeRTOSSpimSpiffsCreate(u32 spim_id); + +#endif // ! \ No newline at end of file diff --git a/example/storage/spim_spiffs/main.c b/example/storage/spim_spiffs/main.c new file mode 100644 index 0000000000000000000000000000000000000000..b5abfe489561915679257a476139679ba305f490 --- /dev/null +++ b/example/storage/spim_spiffs/main.c @@ -0,0 +1,49 @@ +/* + * Copyright : (C) 2022 Phytium Information Technology, Inc. + * All Rights Reserved. + * + * This program is OPEN SOURCE software: you can redistribute it and/or modify it + * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd, + * either version 1.0 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 Phytium Public License for more details. + * + * + * FilePath: main.c + * Date: 2022-06-17 08:17:59 + * LastEditTime: 2022-06-17 08:17:59 + * Description: This file is for the main functions. + * + * Modify History: + * Modify History: + * Ver Who Date Changes + * ----- ------ -------- -------------------------------------- + * 1.0 liqiaozhong 2022/11/2 first commit + */ + +#include "shell.h" +#include "shell_port.h" +#include +#include "spim_spiffs_example.h" + +int main(void) +{ + BaseType_t ret; + + ret = FFreeRTOSSpimSpiffsCreate(0); + if(ret != pdPASS) + goto FAIL_EXIT; + + ret = LSUserShellTask() ; + if(ret != pdPASS) + goto FAIL_EXIT; + + vTaskStartScheduler(); /* 启动任务,开启调度 */ + while (1); /* 正常不会执行到这里 */ + +FAIL_EXIT: + printf("failed 0x%x \r\n", ret); + return 0; +} diff --git a/example/storage/spim_spiffs/makefile b/example/storage/spim_spiffs/makefile new file mode 100644 index 0000000000000000000000000000000000000000..c1f632e855a09d5f79e458e1c21f110a88cb40ba --- /dev/null +++ b/example/storage/spim_spiffs/makefile @@ -0,0 +1,31 @@ +export PROJECT_DIR ?= $(shell pwd) + +export USR_SRC_DIR = $(PROJECT_DIR) \ + ./src +export USR_INC_DIR = $(PROJECT_DIR) \ + ./inc + +# 用户定义的编译目标文件上传路径 +ifeq ($(OS),Windows_NT) + USR_BOOT_DIR ?= $(subst \,/, $(PHYTIUM_DEV_PATH))/tftp +else + USR_BOOT_DIR ?= /mnt/d/tftboot +endif + + +# 设置启动镜像名 +BOOT_IMG_NAME ?= freertos + +# 指定编译freertos项目使用的makefile +include $(FREERTOS_SDK_ROOT)/make/build_freertos.mk + +# 完成编译 +boot: + make -j + @cp ./$(CONFIG_TARGET_NAME).elf $(USR_BOOT_DIR)/$(BOOT_IMG_NAME).elf +ifdef CONFIG_OUTPUT_BINARY + @cp ./$(CONFIG_TARGET_NAME).bin $(USR_BOOT_DIR)/$(BOOT_IMG_NAME).bin +endif + @ls $(USR_BOOT_DIR)/$(BOOT_IMG_NAME).* -l + + diff --git a/example/storage/spim_spiffs/sdkconfig b/example/storage/spim_spiffs/sdkconfig new file mode 100644 index 0000000000000000000000000000000000000000..7f168fdce7159842cef5f7444c004aa1a25d9303 --- /dev/null +++ b/example/storage/spim_spiffs/sdkconfig @@ -0,0 +1,286 @@ + +# +# Freertos Configuration +# +CONFIG_TARGET_NAME="e2000d_freertos_a64" +# end of Freertos Configuration + +# +# Standalone Setting +# +CONFIG_USE_FREERTOS=y + +# +# Arch Configuration +# +# CONFIG_TARGET_ARMV8_AARCH32 is not set +CONFIG_TARGET_ARMV8_AARCH64=y +CONFIG_USE_CACHE=y +CONFIG_USE_MMU=y +CONFIG_USE_SYS_TICK=y +# CONFIG_MMU_DEBUG_PRINTS is not set +# CONFIG_BOOT_WITH_FLUSH_CACHE is not set +# end of Arch Configuration + +# +# Board Configuration +# +# CONFIG_TARGET_F2000_4 is not set +# CONFIG_TARGET_D2000 is not set +# CONFIG_TARGET_E2000Q is not set +CONFIG_TARGET_E2000D=y +# CONFIG_TARGET_E2000S is not set +CONFIG_TARGET_E2000=y +CONFIG_DEFAULT_DEBUG_PRINT_UART1=y +# CONFIG_DEFAULT_DEBUG_PRINT_UART0 is not set +# CONFIG_DEFAULT_DEBUG_PRINT_UART2 is not set +# end of Board Configuration + +# +# Components Configuration +# +CONFIG_USE_SPI=y +CONFIG_USE_FSPIM=y +CONFIG_USE_QSPI=y + +# +# Qspi Configuration +# +CONFIG_USE_FQSPI=y +# end of Qspi Configuration + +CONFIG_USE_GIC=y +CONFIG_ENABLE_GICV3=y +CONFIG_USE_SERIAL=y + +# +# Usart Configuration +# +CONFIG_ENABLE_Pl011_UART=y +# end of Usart Configuration + +# CONFIG_USE_GPIO is not set +# CONFIG_USE_ETH is not set +# CONFIG_USE_CAN is not set +# CONFIG_USE_I2C is not set +# CONFIG_USE_TIMER is not set +# CONFIG_USE_MIO is not set +# CONFIG_USE_SDMMC is not set +# CONFIG_USE_PCIE is not set +# CONFIG_USE_WDT is not set +# CONFIG_USE_DMA is not set +# CONFIG_USE_NAND is not set +# CONFIG_USE_RTC is not set +# CONFIG_USE_SATA is not set +# CONFIG_USE_USB is not set +# CONFIG_USE_ADC is not set +# CONFIG_USE_PWM is not set +# CONFIG_USE_IPC is not set +# CONFIG_USE_MEDIA is not set +# CONFIG_USE_SCMI_MHU is not set +# end of Components Configuration + +CONFIG_USE_NEW_LIBC=y +# end of Standalone Setting + +# +# Building Option +# +# CONFIG_LOG_VERBOS is not set +# CONFIG_LOG_DEBUG is not set +# CONFIG_LOG_INFO is not set +# CONFIG_LOG_WARN is not set +CONFIG_LOG_ERROR=y +# CONFIG_LOG_NONE is not set +CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y +CONFIG_INTERRUPT_ROLE_MASTER=y +# CONFIG_INTERRUPT_ROLE_SLAVE is not set +# CONFIG_LOG_EXTRA_INFO is not set +# CONFIG_BOOTUP_DEBUG_PRINTS is not set + +# +# Linker Options +# +# CONFIG_AARCH32_RAM_LD is not set +CONFIG_AARCH64_RAM_LD=y +# CONFIG_USER_DEFINED_LD is not set +CONFIG_LINK_SCRIPT_ROM=y +CONFIG_ROM_START_UP_ADDR=0x80100000 +CONFIG_ROM_SIZE_MB=1 +CONFIG_LINK_SCRIPT_RAM=y +CONFIG_RAM_START_UP_ADDR=0x81000000 +CONFIG_RAM_SIZE_MB=64 +CONFIG_HEAP_SIZE=1 +CONFIG_STACK_SIZE=0x100000 +CONFIG_FPU_STACK_SIZE=0x1000 +# end of Linker Options + +# +# Compiler Options +# + +# +# Cross-Compiler Setting +# +CONFIG_GCC_OPTIMIZE_LEVEL=0 +# CONFIG_USE_EXT_COMPILER is not set +# CONFIG_USE_KLIN_SYS is not set +# end of Cross-Compiler Setting + +CONFIG_OUTPUT_BINARY=y +# end of Compiler Options +# end of Building Option + +# +# Component Configuration +# + +# +# Freertos Uart Drivers +# +CONFIG_FREERTOS_USE_UART=y +# end of Freertos Uart Drivers + +# +# Freertos Pwm Drivers +# +# CONFIG_FREERTOS_USE_PWM is not set +# end of Freertos Pwm Drivers + +# +# Freertos Qspi Drivers +# +CONFIG_FREERTOS_USE_QSPI=y +# end of Freertos Qspi Drivers + +# +# Freertos Wdt Drivers +# +# CONFIG_FREERTOS_USE_WDT is not set +# end of Freertos Wdt Drivers + +# +# Freertos Eth Drivers +# +# CONFIG_FREERTOS_USE_XMAC is not set +# CONFIG_FREERTOS_USE_GMAC is not set +# end of Freertos Eth Drivers + +# +# Freertos Gpio Drivers +# +# CONFIG_FREERTOS_USE_GPIO is not set +# end of Freertos Gpio Drivers + +# +# Freertos Spim Drivers +# +CONFIG_FREERTOS_USE_FSPIM=y +# end of Freertos Spim Drivers + +# +# Freertos DMA Drivers +# +# CONFIG_FREERTOS_USE_FDDMA is not set +# CONFIG_FREERTOS_USE_FGDMA is not set +# end of Freertos DMA Drivers + +# +# Freertos Adc Drivers +# +# CONFIG_FREERTOS_USE_ADC is not set +# end of Freertos Adc Drivers + +# +# Freertos Can Drivers +# +# CONFIG_FREERTOS_USE_CAN is not set +# end of Freertos Can Drivers + +# +# Freertos I2c Drivers +# +# CONFIG_FREERTOS_USE_I2C is not set +# end of Freertos I2c Drivers + +# +# Freertos Mio Drivers +# +# CONFIG_FREERTOS_USE_MIO is not set +# end of Freertos Mio Drivers + +# +# Freertos Timer Drivers +# +# CONFIG_FREERTOS_USE_TIMER is not set +# end of Freertos Timer Drivers +# end of Component Configuration + +# +# Third-Party Configuration +# +# CONFIG_USE_LWIP is not set +CONFIG_USE_BACKTRACE=y +# CONFIG_USE_FATFS_0_1_4 is not set +CONFIG_USE_SFUD=y + +# +# SFUD Configuration +# +CONFIG_SFUD_CTRL_FSPIM=y +CONFIG_SFUD_TRANS_MODE_POLL_FIFO=y +# CONFIG_SFUD_TRANS_MODE_INTRRUPT is not set +CONFIG_SFUD_CTRL_FQSPI=y +# CONFIG_SFUD_QSPI_READ_MODE_READ is not set +# CONFIG_SFUD_QSPI_READ_MODE_DUAL_READ is not set +CONFIG_SFUD_QSPI_READ_MODE_QUAD_READ=y +# end of SFUD Configuration + +CONFIG_USE_SPIFFS=y + +# +# SPIFFS Configuration +# +CONFIG_SPIFFS_ON_FSPIM_SFUD=y +# CONFIG_SPIFFS_ON_FQSPI_SFUD is not set +# end of SPIFFS Configuration + +# CONFIG_USE_AMP is not set +CONFIG_USE_LETTER_SHELL=y + +# +# Letter Shell Configuration +# +CONFIG_LS_PL011_UART=y +CONFIG_DEFAULT_LETTER_SHELL_USE_UART1=y +# CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set +# CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set +# end of Letter Shell Configuration + +CONFIG_USE_TLSF=y +# CONFIG_USE_SDMMC_CMD is not set +# CONFIG_USE_CHERRY_USB is not set +# end of Third-Party Configuration + +# +# Kernel Configuration +# +CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_MAX_PRIORITIES=32 +CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13 +CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11 +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 +CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024 +CONFIG_FREERTOS_MAX_TASK_NAME_LEN=32 +CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 +CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 +CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 +CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y +# CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set +CONFIG_FREERTOS_TOTAL_HEAP_SIZE=10240 +CONFIG_FREERTOS_TASK_FPU_SUPPORT=1 +# end of Kernel Configuration diff --git a/example/storage/spim_spiffs/sdkconfig.h b/example/storage/spim_spiffs/sdkconfig.h new file mode 100644 index 0000000000000000000000000000000000000000..9a406bbdcd782bcf6af710cfcc10be0e7a879abc --- /dev/null +++ b/example/storage/spim_spiffs/sdkconfig.h @@ -0,0 +1,251 @@ +#ifndef SDK_CONFIG_H__ +#define SDK_CONFIG_H__ + +/* Freertos Configuration */ + +#define CONFIG_TARGET_NAME "e2000d_freertos_a64" +/* end of Freertos Configuration */ + +/* Standalone Setting */ + +#define CONFIG_USE_FREERTOS + +/* Arch Configuration */ + +/* CONFIG_TARGET_ARMV8_AARCH32 is not set */ +#define CONFIG_TARGET_ARMV8_AARCH64 +#define CONFIG_USE_CACHE +#define CONFIG_USE_MMU +#define CONFIG_USE_SYS_TICK +/* CONFIG_MMU_DEBUG_PRINTS is not set */ +/* CONFIG_BOOT_WITH_FLUSH_CACHE is not set */ +/* end of Arch Configuration */ + +/* Board Configuration */ + +/* CONFIG_TARGET_F2000_4 is not set */ +/* CONFIG_TARGET_D2000 is not set */ +/* CONFIG_TARGET_E2000Q is not set */ +#define CONFIG_TARGET_E2000D +/* CONFIG_TARGET_E2000S is not set */ +#define CONFIG_TARGET_E2000 +#define CONFIG_DEFAULT_DEBUG_PRINT_UART1 +/* CONFIG_DEFAULT_DEBUG_PRINT_UART0 is not set */ +/* CONFIG_DEFAULT_DEBUG_PRINT_UART2 is not set */ +/* end of Board Configuration */ + +/* Components Configuration */ + +#define CONFIG_USE_SPI +#define CONFIG_USE_FSPIM +#define CONFIG_USE_QSPI + +/* Qspi Configuration */ + +#define CONFIG_USE_FQSPI +/* end of Qspi Configuration */ +#define CONFIG_USE_GIC +#define CONFIG_ENABLE_GICV3 +#define CONFIG_USE_SERIAL + +/* Usart Configuration */ + +#define CONFIG_ENABLE_Pl011_UART +/* end of Usart Configuration */ +/* CONFIG_USE_GPIO is not set */ +/* CONFIG_USE_ETH is not set */ +/* CONFIG_USE_CAN is not set */ +/* CONFIG_USE_I2C is not set */ +/* CONFIG_USE_TIMER is not set */ +/* CONFIG_USE_MIO is not set */ +/* CONFIG_USE_SDMMC is not set */ +/* CONFIG_USE_PCIE is not set */ +/* CONFIG_USE_WDT is not set */ +/* CONFIG_USE_DMA is not set */ +/* CONFIG_USE_NAND is not set */ +/* CONFIG_USE_RTC is not set */ +/* CONFIG_USE_SATA is not set */ +/* CONFIG_USE_USB is not set */ +/* CONFIG_USE_ADC is not set */ +/* CONFIG_USE_PWM is not set */ +/* CONFIG_USE_IPC is not set */ +/* CONFIG_USE_MEDIA is not set */ +/* CONFIG_USE_SCMI_MHU is not set */ +/* end of Components Configuration */ +#define CONFIG_USE_NEW_LIBC +/* end of Standalone Setting */ + +/* Building Option */ + +/* CONFIG_LOG_VERBOS is not set */ +/* CONFIG_LOG_DEBUG is not set */ +/* CONFIG_LOG_INFO is not set */ +/* CONFIG_LOG_WARN is not set */ +#define CONFIG_LOG_ERROR +/* CONFIG_LOG_NONE is not set */ +#define CONFIG_USE_DEFAULT_INTERRUPT_CONFIG +#define CONFIG_INTERRUPT_ROLE_MASTER +/* CONFIG_INTERRUPT_ROLE_SLAVE is not set */ +/* CONFIG_LOG_EXTRA_INFO is not set */ +/* CONFIG_BOOTUP_DEBUG_PRINTS is not set */ + +/* Linker Options */ + +/* CONFIG_AARCH32_RAM_LD is not set */ +#define CONFIG_AARCH64_RAM_LD +/* CONFIG_USER_DEFINED_LD is not set */ +#define CONFIG_LINK_SCRIPT_ROM +#define CONFIG_ROM_START_UP_ADDR 0x80100000 +#define CONFIG_ROM_SIZE_MB 1 +#define CONFIG_LINK_SCRIPT_RAM +#define CONFIG_RAM_START_UP_ADDR 0x81000000 +#define CONFIG_RAM_SIZE_MB 64 +#define CONFIG_HEAP_SIZE 1 +#define CONFIG_STACK_SIZE 0x100000 +#define CONFIG_FPU_STACK_SIZE 0x1000 +/* end of Linker Options */ + +/* Compiler Options */ + +/* Cross-Compiler Setting */ + +#define CONFIG_GCC_OPTIMIZE_LEVEL 0 +/* CONFIG_USE_EXT_COMPILER is not set */ +/* CONFIG_USE_KLIN_SYS is not set */ +/* end of Cross-Compiler Setting */ +#define CONFIG_OUTPUT_BINARY +/* end of Compiler Options */ +/* end of Building Option */ + +/* Component Configuration */ + +/* Freertos Uart Drivers */ + +#define CONFIG_FREERTOS_USE_UART +/* end of Freertos Uart Drivers */ + +/* Freertos Pwm Drivers */ + +/* CONFIG_FREERTOS_USE_PWM is not set */ +/* end of Freertos Pwm Drivers */ + +/* Freertos Qspi Drivers */ + +#define CONFIG_FREERTOS_USE_QSPI +/* end of Freertos Qspi Drivers */ + +/* Freertos Wdt Drivers */ + +/* CONFIG_FREERTOS_USE_WDT is not set */ +/* end of Freertos Wdt Drivers */ + +/* Freertos Eth Drivers */ + +/* CONFIG_FREERTOS_USE_XMAC is not set */ +/* CONFIG_FREERTOS_USE_GMAC is not set */ +/* end of Freertos Eth Drivers */ + +/* Freertos Gpio Drivers */ + +/* CONFIG_FREERTOS_USE_GPIO is not set */ +/* end of Freertos Gpio Drivers */ + +/* Freertos Spim Drivers */ + +#define CONFIG_FREERTOS_USE_FSPIM +/* end of Freertos Spim Drivers */ + +/* Freertos DMA Drivers */ + +/* CONFIG_FREERTOS_USE_FDDMA is not set */ +/* CONFIG_FREERTOS_USE_FGDMA is not set */ +/* end of Freertos DMA Drivers */ + +/* Freertos Adc Drivers */ + +/* CONFIG_FREERTOS_USE_ADC is not set */ +/* end of Freertos Adc Drivers */ + +/* Freertos Can Drivers */ + +/* CONFIG_FREERTOS_USE_CAN is not set */ +/* end of Freertos Can Drivers */ + +/* Freertos I2c Drivers */ + +/* CONFIG_FREERTOS_USE_I2C is not set */ +/* end of Freertos I2c Drivers */ + +/* Freertos Mio Drivers */ + +/* CONFIG_FREERTOS_USE_MIO is not set */ +/* end of Freertos Mio Drivers */ + +/* Freertos Timer Drivers */ + +/* CONFIG_FREERTOS_USE_TIMER is not set */ +/* end of Freertos Timer Drivers */ +/* end of Component Configuration */ + +/* Third-Party Configuration */ + +/* CONFIG_USE_LWIP is not set */ +#define CONFIG_USE_BACKTRACE +/* CONFIG_USE_FATFS_0_1_4 is not set */ +#define CONFIG_USE_SFUD + +/* SFUD Configuration */ + +#define CONFIG_SFUD_CTRL_FSPIM +#define CONFIG_SFUD_TRANS_MODE_POLL_FIFO +/* CONFIG_SFUD_TRANS_MODE_INTRRUPT is not set */ +#define CONFIG_SFUD_CTRL_FQSPI +/* CONFIG_SFUD_QSPI_READ_MODE_READ is not set */ +/* CONFIG_SFUD_QSPI_READ_MODE_DUAL_READ is not set */ +#define CONFIG_SFUD_QSPI_READ_MODE_QUAD_READ +/* end of SFUD Configuration */ +#define CONFIG_USE_SPIFFS + +/* SPIFFS Configuration */ + +#define CONFIG_SPIFFS_ON_FSPIM_SFUD +/* CONFIG_SPIFFS_ON_FQSPI_SFUD is not set */ +/* end of SPIFFS Configuration */ +/* CONFIG_USE_AMP is not set */ +#define CONFIG_USE_LETTER_SHELL + +/* Letter Shell Configuration */ + +#define CONFIG_LS_PL011_UART +#define CONFIG_DEFAULT_LETTER_SHELL_USE_UART1 +/* CONFIG_DEFAULT_LETTER_SHELL_USE_UART0 is not set */ +/* CONFIG_DEFAULT_LETTER_SHELL_USE_UART2 is not set */ +/* end of Letter Shell Configuration */ +#define CONFIG_USE_TLSF +/* CONFIG_USE_SDMMC_CMD is not set */ +/* CONFIG_USE_CHERRY_USB is not set */ +/* end of Third-Party Configuration */ + +/* Kernel Configuration */ + +#define CONFIG_FREERTOS_OPTIMIZED_SCHEDULER +#define CONFIG_FREERTOS_HZ 1000 +#define CONFIG_FREERTOS_MAX_PRIORITIES 32 +#define CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES 13 +#define CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES 11 +#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE 1024 +#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 32 +#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1 +#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 2048 +#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10 +#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0 +#define CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS +#define CONFIG_FREERTOS_USE_TRACE_FACILITY +#define CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS +/* CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set */ +#define CONFIG_FREERTOS_TOTAL_HEAP_SIZE 10240 +#define CONFIG_FREERTOS_TASK_FPU_SUPPORT 1 +/* end of Kernel Configuration */ + +#endif diff --git a/example/storage/spim_spiffs/src/spim_spiffs_example.c b/example/storage/spim_spiffs/src/spim_spiffs_example.c new file mode 100644 index 0000000000000000000000000000000000000000..9a5b5066a3dd19f7fd074dc44d62af27e703fd00 --- /dev/null +++ b/example/storage/spim_spiffs/src/spim_spiffs_example.c @@ -0,0 +1,621 @@ +/* + * Copyright : (C) 2022 Phytium Information Technology, Inc. + * All Rights Reserved. + * + * This program is OPEN SOURCE software: you can redistribute it and/or modify it + * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd, + * either version 1.0 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 Phytium Public License for more details. + * + * + * FilePath: spim_spiffs_example.c + * Date: 2022-07-11 11:32:48 + * LastEditTime: 2022-07-11 11:32:48 + * Description: This file is for the spim_spiffs example functions. + * + * Modify History: + * Ver Who Date Changes + * ----- ------ -------- -------------------------------------- + * 1.0 liqiaozhong 2022/11/2 first commit + */ +#include +#include +#include +#include "fkernel.h" +#include "FreeRTOSConfig.h" +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "fpinctrl.h" +#include "timers.h" +#include "spim_spiffs_example.h" +#include "strto.h" +#include "fassert.h" +#include "fdebug.h" +#include "fparameters.h" +#include "spiffs_port.h" +#include "sdkconfig.h" +#ifdef CONFIG_SPIFFS_ON_FSPIM_SFUD +#include "fspim_spiffs_port.h" +#endif + +enum +{ + FSPIFFS_OPS_OK = 0, + FSPIFFS_OPS_INIT_FAILED, + FSPIFFS_OPS_ALREADY_INITED, + FSPIFFS_OPS_MOUNT_FAILED, + FSPIFFS_OPS_FORMAT_FAILED, + FSPIFFS_OPS_NOT_YET_MOUNT, + FSPIFFS_OPS_OPEN_FILE_FAILED, + FSPIFFS_OPS_WRITE_FILE_FAILED, + FSPIFFS_OPS_READ_FILE_FAILED, + FSPIFFS_OPS_REMOVE_FILE_FAILED, + FSPIFFS_OPS_CLOSE_FILE_FAILED, +}; + +#define FSPIFFS_DEBUG_TAG "SPIFFS-SPIM" +#define FSPIFFS_ERROR(format, ...) FT_DEBUG_PRINT_E(FSPIFFS_DEBUG_TAG, format, ##__VA_ARGS__) +#define FSPIFFS_WARN(format, ...) FT_DEBUG_PRINT_W(FSPIFFS_DEBUG_TAG, format, ##__VA_ARGS__) +#define FSPIFFS_INFO(format, ...) FT_DEBUG_PRINT_I(FSPIFFS_DEBUG_TAG, format, ##__VA_ARGS__) +#define FSPIFFS_DEBUG(format, ...) FT_DEBUG_PRINT_D(FSPIFFS_DEBUG_TAG, format, ##__VA_ARGS__) + +/* spiffs start address and size */ +#define FSPIFFS_START_ADDR (1 * SZ_1M) +#define FSPIFFS_USE_SIZE SZ_1M + +#define FSPIFFS_RW_BUF_SIZE 64 + +/* if format flash, TRUE is need format, it tasks some time */ +#define FSPIFFS_IF_FORMAT TRUE + +/* 一个页大小两倍的一个RAM缓冲区, 用来加载和维护SPIFFS的逻辑页 */ +static volatile u8 fspiffs_work_buf[FSPIFFS_LOG_PAGE_SIZE * 2] = {0}; +static volatile u8 fspiffs_fds_buf[32 * 4] = {0}; +static volatile u8 fspiffs_cache_buf[(FSPIFFS_LOG_PAGE_SIZE + 32) * 4] = {0}; +static u8 fspiffs_rw_buf[FSPIFFS_RW_BUF_SIZE] = {0}; +static FSpiffs instance; +static spiffs_config config; +static boolean spiffs_inited = FALSE; +const char *file_name = "test.txt"; + +/************************** Constant Definitions *****************************/ + +/* The periods assigned to the one-shot timers. */ +#define ONE_SHOT_TIMER_PERIOD ( pdMS_TO_TICKS( 50000UL ) ) + +/* write and read task delay in milliseconds */ +#define TASK_DELAY_MS 3000UL + +/* write and read task number */ +#define READ_WRITE_TASK_NUM 3 +static xSemaphoreHandle xCountingSemaphore; + +static xTaskHandle spim_read1_handle; +static xTaskHandle spim_read2_handle; +static xTaskHandle spim_write_handle; +static TimerHandle_t xOneShotTimer; + +static void FFreeRTOSSpimSpiffsDelete(void); + +static int FSpiffsOpsMount(boolean do_format) +{ + int result = 0; + + if (do_format) + { + result = SPIFFS_mount(&instance.fs,/*挂载spiffs系统*/ + &config, + (u8_t *)fspiffs_work_buf, + + (u8_t *)fspiffs_fds_buf, + sizeof(fspiffs_fds_buf), + (u8_t *)fspiffs_cache_buf, + sizeof(fspiffs_cache_buf), + NULL); + + /* try mount to get status of filesystem */ + if ((SPIFFS_OK != result) && (SPIFFS_ERR_NOT_A_FS != result)) + { + /* if not a valid filesystem, continue to format, + other error cannot handle, just exit */ + FSPIFFS_ERROR("mount spiffs failed: %d", result); + return FSPIFFS_OPS_MOUNT_FAILED; + } + + /* must be unmounted prior to formatting */ + SPIFFS_unmount(&instance.fs); + + FSPIFFS_DEBUG("format spiffs in progress ...\r\n"); + result = SPIFFS_format(&instance.fs); + if (SPIFFS_OK != result) + { + FSPIFFS_ERROR("format spiffs failed: %d", result); + return FSPIFFS_OPS_FORMAT_FAILED; + } + } + + /* real mount */ + result = SPIFFS_mount(&instance.fs, + &config, + (u8_t *)fspiffs_work_buf, + (u8_t *)fspiffs_fds_buf, + sizeof(fspiffs_fds_buf), + (u8_t *)fspiffs_cache_buf, + sizeof(fspiffs_cache_buf), + NULL); + if (SPIFFS_OK != result) + { + FSPIFFS_ERROR("remount spiffs failed: %d, you may format the medium first", result); + return FSPIFFS_OPS_MOUNT_FAILED; + } + else + { + vPrintf("mount spiffs success !!! \r\n"); + instance.fs_ready = TRUE; + } + + return FSPIFFS_OPS_OK; +} + +static int FSpiffsOpsListAll(void) +{ + int ret = FSPIFFS_OPS_OK; + int result = SPIFFS_OK; + + if (FALSE == instance.fs_ready) + { + FSPIFFS_ERROR("please mount file system first !!!"); + return FSPIFFS_OPS_NOT_YET_MOUNT; + } + + static spiffs_DIR dir; + static struct spiffs_dirent entry; + + memset(&dir, 0, sizeof(dir)); + memset(&entry, 0, sizeof(entry)); + + struct spiffs_dirent *cur_entry = &entry; + (void)SPIFFS_opendir(&instance.fs, "/", &dir); + + while (NULL != (cur_entry = SPIFFS_readdir(&dir, cur_entry))) + { + printf("-- %s file-id: [0x%04x] page-id: [%d] file-size: %d\r\n", + cur_entry->name, + cur_entry->pix, + cur_entry->obj_id, + cur_entry->size); + } + + (void)SPIFFS_closedir(&dir); + return ret; +} + +int FSpiffsOpsCreateFile(const char *file_name) +{ + FASSERT((file_name) && (strlen(file_name) > 0)); + if (FALSE == instance.fs_ready) + { + FSPIFFS_ERROR("please mount file system first !!!"); + return FSPIFFS_OPS_NOT_YET_MOUNT; + } + + int ret = FSPIFFS_OPS_OK; + + /* create file */ + s32_t result = SPIFFS_creat(&instance.fs, file_name, 0); + if (result < 0) + { + FSPIFFS_ERROR("failed to create file %s", file_name); + return FSPIFFS_OPS_OPEN_FILE_FAILED; + } + + /* open file */ + spiffs_file fd = SPIFFS_open(&instance.fs, file_name, SPIFFS_RDONLY, 0); + if (0 > fd) + { + FSPIFFS_ERROR("failed to open file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + return FSPIFFS_OPS_OPEN_FILE_FAILED; + } + + /* check file status */ + static spiffs_stat status; + memset(&status, 0, sizeof(status)); + result = SPIFFS_fstat(&instance.fs, fd, &status); + if (result < 0) + { + FSPIFFS_ERROR("failed to get status of file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + ret = FSPIFFS_OPS_OPEN_FILE_FAILED; + goto err_exit; + } + + if (0 != strcmp(status.name, file_name)) + { + FSPIFFS_ERROR("created file name %s != %s", status.name, file_name); + ret = FSPIFFS_OPS_OPEN_FILE_FAILED; + goto err_exit; + } + + if (0 != status.size) + { + FSPIFFS_ERROR("invalid file size %d", status.size); + ret = FSPIFFS_OPS_OPEN_FILE_FAILED; + goto err_exit; + } + + vPrintf("create file %s success !!!\r\n", file_name); + +err_exit: + (void)SPIFFS_close(&instance.fs, fd); + return ret; +} + +int FSpiffsOpsWriteFile(const char *file_name, const char *str) +{ + FASSERT((file_name) && (strlen(file_name) > 0)); + FASSERT(str); + int ret = FSPIFFS_OPS_OK; + const u32 wr_len = strlen(str) + 1; + + spiffs_file fd = SPIFFS_open(&instance.fs, file_name, SPIFFS_RDWR | SPIFFS_TRUNC, 0); + if (0 > fd) + { + FSPIFFS_ERROR("failed to open file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + return FSPIFFS_OPS_OPEN_FILE_FAILED; + } + + int result = SPIFFS_write(&instance.fs, fd, (void *)str, wr_len); + if (result < 0) + { + FSPIFFS_ERROR("failed to write file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + ret = FSPIFFS_OPS_WRITE_FILE_FAILED; + goto err_exit; + } + + /* check file status */ + static spiffs_stat status; + memset(&status, 0, sizeof(status)); + result = SPIFFS_fstat(&instance.fs, fd, &status); + if (result < 0) + { + FSPIFFS_ERROR("failed to get status of file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + ret = FSPIFFS_OPS_WRITE_FILE_FAILED; + goto err_exit; + } + + if (status.size != wr_len) + { + FSPIFFS_ERROR("file write size %ld != %ld", status.size, wr_len); + ret = FSPIFFS_OPS_WRITE_FILE_FAILED; + goto err_exit; + } + + /* flush all pending writes from cache to flash */ + (void)SPIFFS_fflush(&instance.fs, fd); + vPrintf("write file %s with %d bytes success !!!\r\n", file_name, wr_len); +err_exit: + (void)SPIFFS_close(&instance.fs, fd); + return ret; +} + +int FSpiffsOpsReadFile(const char *file_name) +{ + FASSERT((file_name) && (strlen(file_name) > 0)); + int ret = FSPIFFS_OPS_OK; + int result = SPIFFS_OK; + + if (FALSE == instance.fs_ready) + { + FSPIFFS_ERROR("please mount file system first !!!"); + return FSPIFFS_OPS_NOT_YET_MOUNT; + } + + /* check file status */ + static spiffs_stat status; + + spiffs_flags open_flags = 0; + + /* open the file in read-only mode */ + open_flags = SPIFFS_RDWR; + spiffs_file fd = SPIFFS_open(&instance.fs, file_name, open_flags, 0); + if (0 > fd) + { + FSPIFFS_ERROR("failed to open file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + return FSPIFFS_OPS_OPEN_FILE_FAILED; + } + + /* check file status */ + memset(&status, 0, sizeof(status)); + result = SPIFFS_fstat(&instance.fs, fd, &status); + if (result < 0) + { + FSPIFFS_ERROR("failed to get status of file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + ret = FSPIFFS_OPS_OPEN_FILE_FAILED; + goto err_exit; + } + + s32_t offset = SPIFFS_lseek(&instance.fs, fd, 0, SPIFFS_SEEK_END); + if ((s32_t)status.size != offset) + { + FSPIFFS_ERROR("file %s spiffs:%ld! = fs:%ld", file_name, status.size, offset); + ret = FSPIFFS_OPS_OPEN_FILE_FAILED; + goto err_exit; + } + + memset(fspiffs_rw_buf, 0 , FSPIFFS_RW_BUF_SIZE); + + /* seek to offset and start read */ + if (0 > SPIFFS_lseek(&instance.fs, fd, 0, SPIFFS_SEEK_SET)) + { + FSPIFFS_ERROR("seek file failed !!!"); + ret = FSPIFFS_OPS_READ_FILE_FAILED; + goto err_exit; + } + + /*vPrintf("read %s from position %ld\n", file_name, SPIFFS_tell(&instance.fs, fd));*/ + + s32_t read_len = min((s32_t)FSPIFFS_RW_BUF_SIZE, (s32_t)status.size); + s32_t read_bytes = SPIFFS_read(&instance.fs, fd, (void *)fspiffs_rw_buf, read_len); + if (read_bytes < 0) + { + FSPIFFS_ERROR("failed to read file %s errno %d", file_name, SPIFFS_errno(&instance.fs)); + ret = FSPIFFS_OPS_READ_FILE_FAILED; + goto err_exit; + } + + vPrintf("read %s success, str = %s\n\n", file_name, fspiffs_rw_buf); + +err_exit : + /* close file */ + (void)SPIFFS_close(&instance.fs, fd); + + return ret; +} + + +static void FFreeRTOSSpimSpiffsInitTask(void *pvParameters) +{ + int result = 0; + + if (TRUE == spiffs_inited) + { + FSPIFFS_WARN("spiffs is already initialized"); + return; + } + + /* The spim_id to use is passed in via the parameter. + Cast this to a spim_id pointer. */ + u32 spim_id = (u32)(uintptr)pvParameters; + printf("spim_id: %d\n", spim_id); + + memset(&config, 0, sizeof(config)); + config = *FSpiffsGetDefaultConfig(); + config.phys_addr = FSPIFFS_START_ADDR; /* may use part of flash */ + config.phys_size = FSPIFFS_USE_SIZE; + + memset(&instance, 0, sizeof(instance)); + instance.fs_addr = FSPIFFS_START_ADDR; + instance.fs_size = FSPIFFS_USE_SIZE; + + result = FSpiffsInitialize(&instance, FSPIFFS_PORT_TO_FSPIM); + if (FSPIFFS_PORT_OK != result) + { + FSPIFFS_ERROR("initialize spiffs failed"); + return; + } + + FSpiffsOpsMount(FSPIFFS_IF_FORMAT); + + FSpiffsOpsCreateFile(file_name); + + spiffs_inited = TRUE; + + FSpiffsOpsListAll(); + + FSPIFFS_INFO("spiffs init success !!!\r\n"); + + for (int i = 0; i < READ_WRITE_TASK_NUM; i++) + { + xSemaphoreGive(xCountingSemaphore); + } + + vTaskDelete(NULL); + +} + + +static void FFreeRTOSSpimSpiffsReadTask(void *pvParameters) +{ + const char *pcTaskName = (char *) pvParameters; + const TickType_t xDelay = pdMS_TO_TICKS(TASK_DELAY_MS); + FError ret = FT_SUCCESS; + + xSemaphoreTake(xCountingSemaphore, portMAX_DELAY); + + /* As per most tasks, this task is implemented in an infinite loop. */ + for( ;; ) + { + /* Print out the name of this task. */ + vPrintf( pcTaskName ); + + FSpiffsOpsReadFile(file_name); + + /* Delay for a period. This time a call to vTaskDelay() is used which + places the task into the Blocked state until the delay period has + expired. The parameter takes a time specified in 'ticks', and the + pdMS_TO_TICKS() macro is used (where the xDelay constant is + declared) to convert TASK_DELAY_MS milliseconds into an equivalent time in + ticks. */ + vTaskDelay(xDelay); + } +} + + +static void FFreeRTOSSpimSpiffsWriteTask(void *pvParameters) +{ + const char *pcTaskName = "FFreeRTOSSpimSpiffsWriteTask is running\r\n"; + const TickType_t xDelay = pdMS_TO_TICKS(TASK_DELAY_MS); + FError ret = FT_SUCCESS; + char *string = "spiffs spim write"; + static char string_out[FSPIFFS_RW_BUF_SIZE] = {0}; + + static int i = 0; + + xSemaphoreTake(xCountingSemaphore, portMAX_DELAY); + + /* As per most tasks, this task is implemented in an infinite loop. */ + for (;;) + { + /* Print out the name of this task. */ + vPrintf( pcTaskName ); + i++; + sprintf(string_out, "%s-%d", string, i); + vPrintf( "write to %s, str = %s\n", file_name, string_out); + FSpiffsOpsWriteFile(file_name, string_out); + + /* Delay for a period. This time a call to vTaskDelay() is used which + places the task into the Blocked state until the delay period has + expired. The parameter takes a time specified in 'ticks', and the + pdMS_TO_TICKS() macro is used (where the xDelay constant is + declared) to convert TASK_DELAY_MS milliseconds into an equivalent time in + ticks. */ + vTaskDelay(xDelay); + } +} + +static void prvOneShotTimerCallback( TimerHandle_t xTimer ) +{ + /* Output a string to show the time at which the callback was executed. */ + vPrintf( "One-shot timer callback executing, delete SpimSpiffs ReadTask and WriteTask.\r\n" ); + + FFreeRTOSSpimSpiffsDelete(); +} + + +BaseType_t FFreeRTOSSpimSpiffsCreate(u32 spim_id)/* 主要任务函数 */ +{ + BaseType_t xReturn = pdPASS;/* 定义一个创建信息返回值,默认为 pdPASS */ + BaseType_t xTimerStarted = pdPASS; + + xCountingSemaphore = xSemaphoreCreateCounting(READ_WRITE_TASK_NUM, 0); + if (xCountingSemaphore == NULL) + { + printf("FFreeRTOSSpimSpiffsCreate xCountingSemaphore create failed.\r\n" ); + return pdFAIL; + } + + char *xString1 = "FFreeRTOSSpimSpiffsReadTask1 is running\r\n"; + char *xString2 = "FFreeRTOSSpimSpiffsReadTask2 is running\r\n"; + + taskENTER_CRITICAL(); /* 进入临界区 */ + + xReturn = xTaskCreate((TaskFunction_t )FFreeRTOSSpimSpiffsInitTask, /* 任务入口函数 */ + (const char* )"FFreeRTOSSpimSpiffsInitTask",/* 任务名字 */ + (uint16_t )4096, /* 任务栈大小 */ + (void* )(uintptr)spim_id,/* 任务入口函数参数 */ + (UBaseType_t )1, /* 任务的优先级 */ + NULL); /* 任务控制 */ + + xReturn = xTaskCreate((TaskFunction_t )FFreeRTOSSpimSpiffsReadTask, /* 任务入口函数 */ + (const char* )"FFreeRTOSSpimSpiffsReadTask",/* 任务名字 */ + (uint16_t )4096, /* 任务栈大小 */ + (void* )xString1,/* 任务入口函数参数 */ + (UBaseType_t )configMAX_PRIORITIES-1, /* 任务的优先级 */ + (TaskHandle_t* )&spim_read1_handle); /* 任务控制 */ + + xReturn = xTaskCreate((TaskFunction_t )FFreeRTOSSpimSpiffsReadTask, /* 任务入口函数 */ + (const char* )"FFreeRTOSSpimSpiffsReadTask",/* 任务名字 */ + (uint16_t )4096, /* 任务栈大小 */ + (void* )xString2,/* 任务入口函数参数 */ + (UBaseType_t )configMAX_PRIORITIES-1, /* 任务的优先级 */ + (TaskHandle_t* )&spim_read2_handle); /* 任务控制 */ + + xReturn = xTaskCreate((TaskFunction_t )FFreeRTOSSpimSpiffsWriteTask, /* 任务入口函数 */ + (const char* )"FFreeRTOSSpimSpiffsWriteTask",/* 任务名字 */ + (uint16_t )4096, /* 任务栈大小 */ + (void* )NULL,/* 任务入口函数参数 */ + (UBaseType_t )configMAX_PRIORITIES-1, /* 任务的优先级 */ + (TaskHandle_t* )&spim_write_handle); /* 任务控制 */ + + /* Create the one shot software timer, storing the handle to the created + software timer in xOneShotTimer. */ + xOneShotTimer = xTimerCreate( "OneShot Software Timer", /* Text name for the software timer - not used by FreeRTOS. */ + ONE_SHOT_TIMER_PERIOD, /* The software timer's period in ticks. */ + pdFALSE, /* Setting uxAutoRealod to pdFALSE creates a one-shot software timer. */ + 0, /* This example does not use the timer id. */ + prvOneShotTimerCallback ); /* The callback function to be used by the software timer being created. */ + + /* Check the timers were created. */ + if( xOneShotTimer != NULL ) + { + /* Start the software timers, using a block time of 0 (no block time). + The scheduler has not been started yet so any block time specified here + would be ignored anyway. */ + xTimerStarted = xTimerStart( xOneShotTimer, 0 ); + + /* The implementation of xTimerStart() uses the timer command queue, and + xTimerStart() will fail if the timer command queue gets full. The timer + service task does not get created until the scheduler is started, so all + commands sent to the command queue will stay in the queue until after + the scheduler has been started. Check both calls to xTimerStart() + passed. */ + if( xTimerStarted != pdPASS) + { + vPrintf("CreateSoftwareTimerTasks xTimerStart failed \r\n"); + } + } + else + { + vPrintf("CreateSoftwareTimerTasks xTimerCreate failed \r\n"); + } + + taskEXIT_CRITICAL(); + + return xReturn; +} + +static void FFreeRTOSSpimSpiffsDelete(void) +{ + BaseType_t xReturn = pdPASS; + + FSpiffsDeInitialize(&instance); + + if(spim_read1_handle) + { + vTaskDelete(spim_read1_handle); + vPrintf("Delete FFreeRTOSSpimSpiffsReadTask1 success\r\n"); + } + + if(spim_read2_handle) + { + vTaskDelete(spim_read2_handle); + vPrintf("Delete FFreeRTOSSpimSpiffsReadTask2 success\r\n"); + } + + if(spim_write_handle) + { + vTaskDelete(spim_write_handle); + vPrintf("Delete FFreeRTOSSpimSpiffsWriteTask success\r\n"); + } + + /* delete count sem */ + vSemaphoreDelete(xCountingSemaphore); + + /* delete timer */ + xReturn = xTimerDelete(xOneShotTimer, 0); + if(xReturn != pdPASS) + { + vPrintf("OneShot Software Timer Delete failed.\r\n"); + } + else + { + vPrintf("OneShot Software Timer Delete success.\r\n"); + } + +} + + + diff --git a/install.py b/install.py index 0a96337cf45f3e8e255d66faf08be1f996ad99ec..3174a1c9aae075502f8d532a12ba3edd53a8692f 100644 --- a/install.py +++ b/install.py @@ -86,9 +86,9 @@ os.system("chmod +x ./make/*.mk --silent ") os.system("chmod +x ./lib/Kconfiglib/*.py --silent ") # Add standalone sdk -standalone_sdk_v="v1.0.0" +standalone_sdk_v="6eca557170a2bf50db0cb9ff2403ed6edce937c3" standalone_path=freertos_sdk_path + '/standalone' -standalone_branche="release" +standalone_branche="master" standalone_remote="https://gitee.com/phytium_embedded/phytium-standalone-sdk.git" if not os.path.exists(standalone_path): @@ -108,7 +108,7 @@ if not os.path.exists(standalone_path): os.system("echo \"third-party/fatfs-0.1.4/*\" >> {}".format(r'.git/info/sparse-checkout')) os.system("echo \"third-party/sdmmc/*\" >> {}".format(r'.git/info/sparse-checkout')) os.system("echo \"third-party/lwip-2.1.2/*\" >> {}".format(r'.git/info/sparse-checkout')) - + os.system("echo \"third-party/sfud-1.1.0/*\" >> {}".format(r'.git/info/sparse-checkout')) os.system("git checkout {}".format(standalone_sdk_v)) print('[1]: Standalone sdk download is succeed') diff --git a/third-party/Kconfig b/third-party/Kconfig index 51c610d9374fd1e788c1f357ace6f7b95bf25115..3244c358ae4a2e9398c773972bc6aa5a24a98ead 100644 --- a/third-party/Kconfig +++ b/third-party/Kconfig @@ -101,11 +101,11 @@ config USE_SDMMC_CMD config USE_CHERRY_USB bool default n - prompt "Use CherryUSB" + prompt "Use CherryUSB(0.7.0)" help - Include CherryUSB + Include CherryUSB for XHCI controller if USE_CHERRY_USB - source "$(FREERTOS_SDK_ROOT)/third-party/cherryusb-0.6.0/Kconfig" + source "$(FREERTOS_SDK_ROOT)/third-party/cherryusb-0.7.0/Kconfig" endif diff --git a/third-party/cherryusb-0.6.0/Kconfig b/third-party/cherryusb-0.7.0/Kconfig similarity index 100% rename from third-party/cherryusb-0.6.0/Kconfig rename to third-party/cherryusb-0.7.0/Kconfig diff --git a/third-party/cherryusb-0.6.0/LICENSE b/third-party/cherryusb-0.7.0/LICENSE similarity index 100% rename from third-party/cherryusb-0.6.0/LICENSE rename to third-party/cherryusb-0.7.0/LICENSE diff --git a/third-party/cherryusb-0.6.0/README.md b/third-party/cherryusb-0.7.0/README.md similarity index 95% rename from third-party/cherryusb-0.6.0/README.md rename to third-party/cherryusb-0.7.0/README.md index c4445e511991c81ac8f9f7a4b788ecec0e9f55fd..aee4c6362f926194fd7b626805790d931f85434a 100644 --- a/third-party/cherryusb-0.6.0/README.md +++ b/third-party/cherryusb-0.7.0/README.md @@ -66,14 +66,14 @@ CherryUSB Device Stack has the following functions: CherryUSB Device Stack resource usage (GCC 10.2 with -O2): -| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) | -|:-------------:|:--------------:|:-------------------------:|:-------------:|:---------------------------------:| -|usbd_core.c | 3263 | 384 | 17 | 0 | -|usbd_cdc.c | 490 | 0 | 0 | sizeof(struct usbd_interface) * x | -|usbd_msc.c | 2772 | 128 + 512(default) | 16 | sizeof(struct usbd_interface) * x | -|usbd_hid.c | 501 | 0 | 0 | sizeof(struct usbd_interface) * x | -|usbd_audio.c | 1208 | 0 | 4 | sizeof(struct usbd_interface) * x | -|usbd_video.c | 2272 | 0 | 82 | sizeof(struct usbd_interface) * x | +| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) | +|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:| +|usbd_core.c | 3263 | 384 | 17 | 0 | +|usbd_cdc.c | 490 | 0 | 0 | 0 | +|usbd_msc.c | 2772 | 128 + 512(default) | 16 | 0 | +|usbd_hid.c | 501 | 0 | 0 | 0 | +|usbd_audio.c | 1208 | 0 | 4 | 0 | +|usbd_video.c | 2272 | 0 | 82 | 0 | ## Host Stack Overview diff --git a/third-party/cherryusb-0.6.0/README_zh.md b/third-party/cherryusb-0.7.0/README_zh.md similarity index 95% rename from third-party/cherryusb-0.6.0/README_zh.md rename to third-party/cherryusb-0.7.0/README_zh.md index d19d5207553a33480606a7768069e6ebc287be41..2efcfeaf8ecb7a850fb1dbb4c4dcee8fbf7b9eeb 100644 --- a/third-party/cherryusb-0.6.0/README_zh.md +++ b/third-party/cherryusb-0.7.0/README_zh.md @@ -65,14 +65,14 @@ CherryUSB Device 协议栈当前实现以下功能: CherryUSB Device 协议栈资源占用说明(GCC 10.2 with -O2): -| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) | -|:-------------:|:--------------:|:-------------------------:|:-------------:|:---------------------------------:| -|usbd_core.c | 3263 | 384 | 17 | 0 | -|usbd_cdc.c | 490 | 0 | 0 | sizeof(struct usbd_interface) * x | -|usbd_msc.c | 2772 | 128 + 512(default) | 16 | sizeof(struct usbd_interface) * x | -|usbd_hid.c | 501 | 0 | 0 | sizeof(struct usbd_interface) * x | -|usbd_audio.c | 1208 | 0 | 4 | sizeof(struct usbd_interface) * x | -|usbd_video.c | 2272 | 0 | 82 | sizeof(struct usbd_interface) * x | +| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) | +|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:| +|usbd_core.c | 3263 | 384 | 17 | 0 | +|usbd_cdc.c | 490 | 0 | 0 | 0 | +|usbd_msc.c | 2772 | 128 + 512(default) | 16 | 0 | +|usbd_hid.c | 501 | 0 | 0 | 0 | +|usbd_audio.c | 1208 | 0 | 4 | 0 | +|usbd_video.c | 2272 | 0 | 82 | 0 | ## Host 协议栈简介 diff --git a/third-party/cherryusb-0.6.0/class/audio/usb_audio.h b/third-party/cherryusb-0.7.0/class/audio/usb_audio.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/audio/usb_audio.h rename to third-party/cherryusb-0.7.0/class/audio/usb_audio.h diff --git a/third-party/cherryusb-0.6.0/class/audio/usbd_audio.c b/third-party/cherryusb-0.7.0/class/audio/usbd_audio.c similarity index 98% rename from third-party/cherryusb-0.6.0/class/audio/usbd_audio.c rename to third-party/cherryusb-0.7.0/class/audio/usbd_audio.c index 6755b83dcc264e4fb098c73076e3bf9f7dda5d91..4baab5a4acf123fc20eed692c5d34cb5402343da 100644 --- a/third-party/cherryusb-0.6.0/class/audio/usbd_audio.c +++ b/third-party/cherryusb-0.7.0/class/audio/usbd_audio.c @@ -373,14 +373,8 @@ static void audio_notify_handler(uint8_t event, void *arg) } } -struct usbd_interface *usbd_audio_alloc_intf(void) +struct usbd_interface *usbd_audio_init_intf(struct usbd_interface *intf) { - struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - intf->class_interface_handler = audio_class_interface_request_handler; #if CONFIG_USBDEV_AUDIO_VERSION < 0x0200 intf->class_endpoint_handler = audio_class_endpoint_request_handler; diff --git a/third-party/cherryusb-0.6.0/class/audio/usbd_audio.h b/third-party/cherryusb-0.7.0/class/audio/usbd_audio.h similarity index 87% rename from third-party/cherryusb-0.6.0/class/audio/usbd_audio.h rename to third-party/cherryusb-0.7.0/class/audio/usbd_audio.h index 723e866687531f1518d4a8f9239c0f2acf8d2136..420e88cedcee6b7645ee6f0378c52f72be545f81 100644 --- a/third-party/cherryusb-0.6.0/class/audio/usbd_audio.h +++ b/third-party/cherryusb-0.7.0/class/audio/usbd_audio.h @@ -12,8 +12,8 @@ extern "C" { #endif -/* Alloc audio interface driver */ -struct usbd_interface *usbd_audio_alloc_intf(void); +/* Init audio interface driver */ +struct usbd_interface *usbd_audio_init_intf(struct usbd_interface *intf); void usbd_audio_open(uint8_t intf); void usbd_audio_close(uint8_t intf); diff --git a/third-party/cherryusb-0.6.0/class/cdc/usb_cdc.h b/third-party/cherryusb-0.7.0/class/cdc/usb_cdc.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/cdc/usb_cdc.h rename to third-party/cherryusb-0.7.0/class/cdc/usb_cdc.h diff --git a/third-party/cherryusb-0.6.0/class/cdc/usbd_cdc.c b/third-party/cherryusb-0.7.0/class/cdc/usbd_cdc.c similarity index 95% rename from third-party/cherryusb-0.6.0/class/cdc/usbd_cdc.c rename to third-party/cherryusb-0.7.0/class/cdc/usbd_cdc.c index 8c9ee5a8d1fd9398df92c74e9310eff967a64d39..2f4977f4d52e1ff905aaf9b7afdde90d1604a764 100644 --- a/third-party/cherryusb-0.6.0/class/cdc/usbd_cdc.c +++ b/third-party/cherryusb-0.7.0/class/cdc/usbd_cdc.c @@ -90,14 +90,8 @@ static void cdc_notify_handler(uint8_t event, void *arg) } } -struct usbd_interface *usbd_cdc_acm_alloc_intf(void) +struct usbd_interface *usbd_cdc_acm_init_intf(struct usbd_interface *intf) { - struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - intf->class_interface_handler = cdc_acm_class_interface_request_handler; intf->class_endpoint_handler = NULL; intf->vendor_handler = NULL; diff --git a/third-party/cherryusb-0.6.0/class/cdc/usbd_cdc.h b/third-party/cherryusb-0.7.0/class/cdc/usbd_cdc.h similarity index 83% rename from third-party/cherryusb-0.6.0/class/cdc/usbd_cdc.h rename to third-party/cherryusb-0.7.0/class/cdc/usbd_cdc.h index 8cd88270d86529829aec763fa5cd3c2c96605de3..b4f5d9939366808b8cdd185a8a470e8e88756ada 100644 --- a/third-party/cherryusb-0.6.0/class/cdc/usbd_cdc.h +++ b/third-party/cherryusb-0.7.0/class/cdc/usbd_cdc.h @@ -12,8 +12,8 @@ extern "C" { #endif -/* Alloc cdc acm interface driver */ -struct usbd_interface *usbd_cdc_acm_alloc_intf(void); +/* Init cdc acm interface driver */ +struct usbd_interface *usbd_cdc_acm_init_intf(struct usbd_interface *intf); /* Setup request command callback api */ void usbd_cdc_acm_set_line_coding(uint8_t intf, struct cdc_line_coding *line_coding); diff --git a/third-party/cherryusb-0.6.0/class/cdc/usbh_cdc_acm.c b/third-party/cherryusb-0.7.0/class/cdc/usbh_cdc_acm.c similarity index 98% rename from third-party/cherryusb-0.6.0/class/cdc/usbh_cdc_acm.c rename to third-party/cherryusb-0.7.0/class/cdc/usbh_cdc_acm.c index 8d5a85f10c4b55d9e4097a6a35ef741432a414e4..77300a9c094080462fb274c4cc7638bdd1f4089c 100644 --- a/third-party/cherryusb-0.6.0/class/cdc/usbh_cdc_acm.c +++ b/third-party/cherryusb-0.7.0/class/cdc/usbh_cdc_acm.c @@ -169,9 +169,8 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf) memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm)); usb_free(cdc_acm_class); - if (hport->config.intf[intf].devname[0] != '\0'){ + if (hport->config.intf[intf].devname[0] != '\0') USB_LOG_INFO("Unregister CDC ACM Class:%s\r\n", hport->config.intf[intf].devname); - } } return ret; diff --git a/third-party/cherryusb-0.6.0/class/cdc/usbh_cdc_acm.h b/third-party/cherryusb-0.7.0/class/cdc/usbh_cdc_acm.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/cdc/usbh_cdc_acm.h rename to third-party/cherryusb-0.7.0/class/cdc/usbh_cdc_acm.h diff --git a/third-party/cherryusb-0.6.0/class/dfu/usb_dfu.h b/third-party/cherryusb-0.7.0/class/dfu/usb_dfu.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/dfu/usb_dfu.h rename to third-party/cherryusb-0.7.0/class/dfu/usb_dfu.h diff --git a/third-party/cherryusb-0.6.0/class/dfu/usbd_dfu.c b/third-party/cherryusb-0.7.0/class/dfu/usbd_dfu.c similarity index 98% rename from third-party/cherryusb-0.6.0/class/dfu/usbd_dfu.c rename to third-party/cherryusb-0.7.0/class/dfu/usbd_dfu.c index 10c33a485f4787bab9c0c45cf82d04dd17020eb5..3042e4df4bff9ea10120add78828ce089964f899 100644 --- a/third-party/cherryusb-0.6.0/class/dfu/usbd_dfu.c +++ b/third-party/cherryusb-0.7.0/class/dfu/usbd_dfu.c @@ -477,14 +477,8 @@ static void dfu_notify_handler(uint8_t event, void *arg) } } -struct usbd_interface *usbd_dfu_alloc_intf(void) +struct usbd_interface *usbd_dfu_init_intf(struct usbd_interface *intf) { - struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - intf->class_interface_handler = dfu_class_interface_request_handler; intf->class_endpoint_handler = NULL; intf->vendor_handler = NULL; diff --git a/third-party/cherryusb-0.6.0/class/dfu/usbd_dfu.h b/third-party/cherryusb-0.7.0/class/dfu/usbd_dfu.h similarity index 82% rename from third-party/cherryusb-0.6.0/class/dfu/usbd_dfu.h rename to third-party/cherryusb-0.7.0/class/dfu/usbd_dfu.h index 1cc4510bbee098902e66cee8d588626d7e06af42..9081d0dda1cc9d5ca7e7ede1da23740a714864b7 100644 --- a/third-party/cherryusb-0.6.0/class/dfu/usbd_dfu.h +++ b/third-party/cherryusb-0.7.0/class/dfu/usbd_dfu.h @@ -12,8 +12,8 @@ extern "C" { #endif -/* Alloc dfu interface driver */ -struct usbd_interface *usbd_dfu_alloc_intf(void); +/* Init dfu interface driver */ +struct usbd_interface *usbd_dfu_init_intf(struct usbd_interface *intf); /* Interface functions that need to be implemented by the user */ uint8_t *dfu_read_flash(uint8_t *src, uint8_t *dest, uint32_t len); diff --git a/third-party/cherryusb-0.6.0/class/hid/usb_hid.h b/third-party/cherryusb-0.7.0/class/hid/usb_hid.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/hid/usb_hid.h rename to third-party/cherryusb-0.7.0/class/hid/usb_hid.h diff --git a/third-party/cherryusb-0.6.0/class/hid/usbd_hid.c b/third-party/cherryusb-0.7.0/class/hid/usbd_hid.c similarity index 56% rename from third-party/cherryusb-0.6.0/class/hid/usbd_hid.c rename to third-party/cherryusb-0.7.0/class/hid/usbd_hid.c index 1f47bb3f1d9fb7f0097a8875f4679c1cc3a3afb9..b2659bdf9640bf1ad044dc76cf4799b2f38636b5 100644 --- a/third-party/cherryusb-0.6.0/class/hid/usbd_hid.c +++ b/third-party/cherryusb-0.7.0/class/hid/usbd_hid.c @@ -6,62 +6,6 @@ #include "usbd_core.h" #include "usbd_hid.h" -static int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) -{ - USB_LOG_DBG("HID Custom request: " - "bRequest 0x%02x\r\n", - setup->bRequest); - - if (((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_IN) && - setup->bRequest == USB_REQUEST_GET_DESCRIPTOR) { - uint8_t value = (uint8_t)(setup->wValue >> 8); - uint8_t intf_num = (uint8_t)setup->wIndex; - - usb_slist_t *i; - struct usbd_interface *match_intf = NULL; - - usb_slist_for_each(i, &usbd_intf_head) - { - struct usbd_interface *intf = usb_slist_entry(i, struct usbd_interface, list); - - if (intf->intf_num == intf_num) { - match_intf = intf; - break; - } - } - - if (match_intf == NULL) { - return -2; - } - - switch (value) { - case HID_DESCRIPTOR_TYPE_HID: - USB_LOG_INFO("get HID Descriptor\r\n"); - // *data = (uint8_t *)match_intf->hid_descriptor; - // *len = match_intf->hid_descriptor[0]; - break; - - case HID_DESCRIPTOR_TYPE_HID_REPORT: - USB_LOG_INFO("get Report Descriptor\r\n"); - *data = (uint8_t *)match_intf->hid_report_descriptor; - *len = match_intf->hid_report_descriptor_len; - break; - - case HID_DESCRIPTOR_TYPE_HID_PHYSICAL: - USB_LOG_INFO("get PHYSICAL Descriptor\r\n"); - - break; - - default: - return -2; - } - - return 0; - } - - return -1; -} - static int hid_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) { USB_LOG_DBG("HID Class request: " @@ -105,14 +49,8 @@ static int hid_class_interface_request_handler(struct usb_setup_packet *setup, u return 0; } -struct usbd_interface *usbd_hid_alloc_intf(const uint8_t *desc, uint32_t desc_len) +struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len) { - struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - intf->class_interface_handler = hid_class_interface_request_handler; intf->class_endpoint_handler = NULL; intf->vendor_handler = NULL; diff --git a/third-party/cherryusb-0.6.0/class/hid/usbd_hid.h b/third-party/cherryusb-0.7.0/class/hid/usbd_hid.h similarity index 86% rename from third-party/cherryusb-0.6.0/class/hid/usbd_hid.h rename to third-party/cherryusb-0.7.0/class/hid/usbd_hid.h index d065cf456f9fff3173701f5f9127f448d1fc575e..9c1be36271a73f01d55ccd6c16883a28e4daebae 100644 --- a/third-party/cherryusb-0.6.0/class/hid/usbd_hid.h +++ b/third-party/cherryusb-0.7.0/class/hid/usbd_hid.h @@ -12,8 +12,8 @@ extern "C" { #endif -/* Alloc hid interface driver */ -struct usbd_interface *usbd_hid_alloc_intf(const uint8_t *desc, uint32_t desc_len); +/* Init hid interface driver */ +struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len); /* Register desc api */ void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc); diff --git a/third-party/cherryusb-0.6.0/class/hid/usbh_hid.c b/third-party/cherryusb-0.7.0/class/hid/usbh_hid.c similarity index 98% rename from third-party/cherryusb-0.6.0/class/hid/usbh_hid.c rename to third-party/cherryusb-0.7.0/class/hid/usbh_hid.c index 6fc861a96b941af229881a4e99f94c4f0e0eb7c5..1ad95f1fdcc89cdc43466723472ec37625851da5 100644 --- a/third-party/cherryusb-0.6.0/class/hid/usbh_hid.c +++ b/third-party/cherryusb-0.7.0/class/hid/usbh_hid.c @@ -171,9 +171,8 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf) memset(hid_class, 0, sizeof(struct usbh_hid)); usb_free(hid_class); - if (hport->config.intf[intf].devname[0] != '\0'){ + if (hport->config.intf[intf].devname[0] != '\0') USB_LOG_INFO("Unregister HID Class:%s\r\n", hport->config.intf[intf].devname); - } } return ret; diff --git a/third-party/cherryusb-0.6.0/class/hid/usbh_hid.h b/third-party/cherryusb-0.7.0/class/hid/usbh_hid.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/hid/usbh_hid.h rename to third-party/cherryusb-0.7.0/class/hid/usbh_hid.h diff --git a/third-party/cherryusb-0.6.0/class/hub/usb_hub.h b/third-party/cherryusb-0.7.0/class/hub/usb_hub.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/hub/usb_hub.h rename to third-party/cherryusb-0.7.0/class/hub/usb_hub.h diff --git a/third-party/cherryusb-0.6.0/class/hub/usbh_hub.c b/third-party/cherryusb-0.7.0/class/hub/usbh_hub.c similarity index 99% rename from third-party/cherryusb-0.6.0/class/hub/usbh_hub.c rename to third-party/cherryusb-0.7.0/class/hub/usbh_hub.c index 67374eaa16eee2ab4f40f5ba87ceef94bc7454f9..b62112176e68d36456a276c4c6c54c0f79924870 100644 --- a/third-party/cherryusb-0.6.0/class/hub/usbh_hub.c +++ b/third-party/cherryusb-0.7.0/class/hub/usbh_hub.c @@ -337,9 +337,8 @@ static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf) usbh_hub_unregister(hub); memset(hub, 0, sizeof(struct usbh_hub)); - if (hport->config.intf[intf].devname[0] != '\0'){ + if (hport->config.intf[intf].devname[0] != '\0') USB_LOG_INFO("Unregister HUB Class:%s\r\n", hport->config.intf[intf].devname); - } } return ret; } diff --git a/third-party/cherryusb-0.6.0/class/hub/usbh_hub.h b/third-party/cherryusb-0.7.0/class/hub/usbh_hub.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/hub/usbh_hub.h rename to third-party/cherryusb-0.7.0/class/hub/usbh_hub.h diff --git a/third-party/cherryusb-0.6.0/class/midi/usb_midi.h b/third-party/cherryusb-0.7.0/class/midi/usb_midi.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/midi/usb_midi.h rename to third-party/cherryusb-0.7.0/class/midi/usb_midi.h diff --git a/third-party/cherryusb-0.6.0/class/msc/usb_msc.h b/third-party/cherryusb-0.7.0/class/msc/usb_msc.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/msc/usb_msc.h rename to third-party/cherryusb-0.7.0/class/msc/usb_msc.h diff --git a/third-party/cherryusb-0.6.0/class/msc/usb_scsi.h b/third-party/cherryusb-0.7.0/class/msc/usb_scsi.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/msc/usb_scsi.h rename to third-party/cherryusb-0.7.0/class/msc/usb_scsi.h diff --git a/third-party/cherryusb-0.6.0/class/msc/usbd_msc.c b/third-party/cherryusb-0.7.0/class/msc/usbd_msc.c similarity index 98% rename from third-party/cherryusb-0.6.0/class/msc/usbd_msc.c rename to third-party/cherryusb-0.7.0/class/msc/usbd_msc.c index 708f8d099ce27798cdfe4020926fcf40b06555bc..9655c95179cc12db4995e4f54592be0a8a4b2caf 100644 --- a/third-party/cherryusb-0.6.0/class/msc/usbd_msc.c +++ b/third-party/cherryusb-0.7.0/class/msc/usbd_msc.c @@ -10,10 +10,6 @@ #include "usb_osal.h" #endif -#ifndef CONFIG_USBDEV_MSC_BLOCK_SIZE -#define CONFIG_USBDEV_MSC_BLOCK_SIZE 512 -#endif - #define MSC_THREAD_OP_READ_MEM 1 #define MSC_THREAD_OP_WRITE_MEM 2 #define MSC_THREAD_OP_WRITE_DONE 3 @@ -916,14 +912,8 @@ static void usbd_msc_thread(void *argument) } #endif -struct usbd_interface *usbd_msc_alloc_intf(const uint8_t out_ep, const uint8_t in_ep) +struct usbd_interface *usbd_msc_init_intf(struct usbd_interface *intf, const uint8_t out_ep, const uint8_t in_ep) { - struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - intf->class_interface_handler = msc_storage_class_interface_request_handler; intf->class_endpoint_handler = NULL; intf->vendor_handler = NULL; diff --git a/third-party/cherryusb-0.6.0/class/msc/usbd_msc.h b/third-party/cherryusb-0.7.0/class/msc/usbd_msc.h similarity index 69% rename from third-party/cherryusb-0.6.0/class/msc/usbd_msc.h rename to third-party/cherryusb-0.7.0/class/msc/usbd_msc.h index 53ec4692164c200fc3666ee01485e9ae0924a97c..824b48442a393d859eeb77f3dce3e95095aee9a2 100644 --- a/third-party/cherryusb-0.6.0/class/msc/usbd_msc.h +++ b/third-party/cherryusb-0.7.0/class/msc/usbd_msc.h @@ -12,8 +12,10 @@ extern "C" { #endif -/* Alloc msc interface driver */ -struct usbd_interface *usbd_msc_alloc_intf(const uint8_t out_ep, const uint8_t in_ep); +/* Init msc interface driver */ +struct usbd_interface *usbd_msc_init_intf(struct usbd_interface *intf, + const uint8_t out_ep, + const uint8_t in_ep); void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size); int usbd_msc_sector_read(uint32_t sector, uint8_t *buffer, uint32_t length); diff --git a/third-party/cherryusb-0.6.0/class/msc/usbh_msc.c b/third-party/cherryusb-0.7.0/class/msc/usbh_msc.c similarity index 99% rename from third-party/cherryusb-0.6.0/class/msc/usbh_msc.c rename to third-party/cherryusb-0.7.0/class/msc/usbh_msc.c index 2f77a067d3b7e7eee6b7c7f5f170e39aab89f861..550b0c25d0a80c869aa2d4640fccb9afac8c22ed 100644 --- a/third-party/cherryusb-0.6.0/class/msc/usbh_msc.c +++ b/third-party/cherryusb-0.7.0/class/msc/usbh_msc.c @@ -394,9 +394,8 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf) memset(msc_class, 0, sizeof(struct usbh_msc)); usb_free(msc_class); - if (hport->config.intf[intf].devname[0] != '\0'){ + if (hport->config.intf[intf].devname[0] != '\0') USB_LOG_INFO("Unregister MSC Class:%s\r\n", hport->config.intf[intf].devname); - } } return ret; diff --git a/third-party/cherryusb-0.6.0/class/msc/usbh_msc.h b/third-party/cherryusb-0.7.0/class/msc/usbh_msc.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/msc/usbh_msc.h rename to third-party/cherryusb-0.7.0/class/msc/usbh_msc.h diff --git a/third-party/cherryusb-0.7.0/class/mtp/usb_mtp.h b/third-party/cherryusb-0.7.0/class/mtp/usb_mtp.h new file mode 100644 index 0000000000000000000000000000000000000000..a3b68789dd575ddcc84527f6408c67a0faada384 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/mtp/usb_mtp.h @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef USB_MTP_H +#define USB_MTP_H + +#define USB_MTP_CLASS 0x06 + +#define USB_MTP_SUB_CLASS 0x01U +#define USB_MTP_PROTOCOL 0x01U + +#define MTP_REQUEST_CANCEL 0x64U +#define MTP_REQUEST_GET_EXT_EVENT_DATA 0x65U +#define MTP_REQUEST_RESET 0x66U +#define MTP_REQUEST_GET_DEVICE_STATUS 0x67U + +/* + * MTP Class specification Revision 1.1 + * Appendix B. Object Properties + */ +/* MTP OBJECT PROPERTIES supported*/ +#define MTP_OB_PROP_STORAGE_ID 0xDC01U +#define MTP_OB_PROP_OBJECT_FORMAT 0xDC02U +#define MTP_OB_PROP_PROTECTION_STATUS 0xDC03U +#define MTP_OB_PROP_OBJECT_SIZE 0xDC04U +#define MTP_OB_PROP_ASSOC_TYPE 0xDC05U +#define MTP_OB_PROP_ASSOC_DESC 0xDC06U +#define MTP_OB_PROP_OBJ_FILE_NAME 0xDC07U +#define MTP_OB_PROP_DATE_CREATED 0xDC08U +#define MTP_OB_PROP_DATE_MODIFIED 0xDC09U +#define MTP_OB_PROP_KEYWORDS 0xDC0AU +#define MTP_OB_PROP_PARENT_OBJECT 0xDC0BU +#define MTP_OB_PROP_ALLOWED_FOLD_CONTENTS 0xDC0CU +#define MTP_OB_PROP_HIDDEN 0xDC0DU +#define MTP_OB_PROP_SYSTEM_OBJECT 0xDC0EU +#define MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN 0xDC41U +#define MTP_OB_PROP_SYNCID 0xDC42U +#define MTP_OB_PROP_PROPERTY_BAG 0xDC43U +#define MTP_OB_PROP_NAME 0xDC44U +#define MTP_OB_PROP_CREATED_BY 0xDC45U +#define MTP_OB_PROP_ARTIST 0xDC46U +#define MTP_OB_PROP_DATE_AUTHORED 0xDC47U +#define MTP_OB_PROP_DESCRIPTION 0xDC48U +#define MTP_OB_PROP_URL_REFERENCE 0xDC49U +#define MTP_OB_PROP_LANGUAGELOCALE 0xDC4AU +#define MTP_OB_PROP_COPYRIGHT_INFORMATION 0xDC4BU +#define MTP_OB_PROP_SOURCE 0xDC4CU +#define MTP_OB_PROP_ORIGIN_LOCATION 0xDC4DU +#define MTP_OB_PROP_DATE_ADDED 0xDC4EU +#define MTP_OB_PROP_NON_CONSUMABLE 0xDC4FU +#define MTP_OB_PROP_CORRUPTUNPLAYABLE 0xDC50U +#define MTP_OB_PROP_PRODUCERSERIALNUMBER 0xDC51U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_FORMAT 0xDC81U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_SIZE 0xDC82U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_HEIGHT 0xDC83U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_WIDTH 0xDC84U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DURATION 0xDC85U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DATA 0xDC86U +#define MTP_OB_PROP_WIDTH 0xDC87U +#define MTP_OB_PROP_HEIGHT 0xDC88U +#define MTP_OB_PROP_DURATION 0xDC89U +#define MTP_OB_PROP_RATING 0xDC8AU +#define MTP_OB_PROP_TRACK 0xDC8BU +#define MTP_OB_PROP_GENRE 0xDC8CU +#define MTP_OB_PROP_CREDITS 0xDC8DU +#define MTP_OB_PROP_LYRICS 0xDC8EU +#define MTP_OB_PROP_SUBSCRIPTION_CONTENT_ID 0xDC8FU +#define MTP_OB_PROP_PRODUCED_BY 0xDC90U +#define MTP_OB_PROP_USE_COUNT 0xDC91U +#define MTP_OB_PROP_SKIP_COUNT 0xDC92U +#define MTP_OB_PROP_LAST_ACCESSED 0xDC93U +#define MTP_OB_PROP_PARENTAL_RATING 0xDC94U +#define MTP_OB_PROP_META_GENRE 0xDC95U +#define MTP_OB_PROP_COMPOSER 0xDC96U +#define MTP_OB_PROP_EFFECTIVE_RATING 0xDC97U +#define MTP_OB_PROP_SUBTITLE 0xDC98U +#define MTP_OB_PROP_ORIGINAL_RELEASE_DATE 0xDC99U +#define MTP_OB_PROP_ALBUM_NAME 0xDC9AU +#define MTP_OB_PROP_ALBUM_ARTIST 0xDC9BU +#define MTP_OB_PROP_MOOD 0xDC9CU +#define MTP_OB_PROP_DRM_STATUS 0xDC9DU +#define MTP_OB_PROP_SUB_DESCRIPTION 0xDC9EU +#define MTP_OB_PROP_IS_CROPPED 0xDCD1U +#define MTP_OB_PROP_IS_COLOUR_CORRECTED 0xDCD2U +#define MTP_OB_PROP_IMAGE_BIT_DEPTH 0xDCD3U +#define MTP_OB_PROP_FNUMBER 0xDCD4U +#define MTP_OB_PROP_EXPOSURE_TIME 0xDCD5U +#define MTP_OB_PROP_EXPOSURE_INDEX 0xDCD6U +#define MTP_OB_PROP_TOTAL_BITRATE 0xDE91U +#define MTP_OB_PROP_BITRATE_TYPE 0xDE92U +#define MTP_OB_PROP_SAMPLE_RATE 0xDE93U +#define MTP_OB_PROP_NUMBER_OF_CHANNELS 0xDE94U +#define MTP_OB_PROP_AUDIO_BITDEPTH 0xDE95U +#define MTP_OB_PROP_SCAN_TYPE 0xDE97U +#define MTP_OB_PROP_AUDIO_WAVE_CODEC 0xDE99U +#define MTP_OB_PROP_AUDIO_BITRATE 0xDE9AU +#define MTP_OB_PROP_VIDEO_FOURCC_CODEC 0xDE9BU +#define MTP_OB_PROP_VIDEO_BITRATE 0xDE9CU +#define MTP_OB_PROP_FRAMES_PER_THOUSAND_SECONDS 0xDE9DU +#define MTP_OB_PROP_KEYFRAME_DISTANCE 0xDE9EU +#define MTP_OB_PROP_BUFFER_SIZE 0xDE9FU +#define MTP_OB_PROP_ENCODING_QUALITY 0xDEA0U +#define MTP_OB_PROP_ENCODING_PROFILE 0xDEA1U +#define MTP_OB_PROP_DISPLAY_NAME 0xDCE0U +#define MTP_OB_PROP_BODY_TEXT 0xDCE1U +#define MTP_OB_PROP_SUBJECT 0xDCE2U +#define MTP_OB_PROP_PRIORITY 0xDCE3U +#define MTP_OB_PROP_GIVEN_NAME 0xDD00U +#define MTP_OB_PROP_MIDDLE_NAMES 0xDD01U +#define MTP_OB_PROP_FAMILY_NAME 0xDD02U +#define MTP_OB_PROP_PREFIX 0xDD03U +#define MTP_OB_PROP_SUFFIX 0xDD04U +#define MTP_OB_PROP_PHONETIC_GIVEN_NAME 0xDD05U +#define MTP_OB_PROP_PHONETIC_FAMILY_NAME 0xDD06U +#define MTP_OB_PROP_EMAIL_PRIMARY 0xDD07U +#define MTP_OB_PROP_EMAIL_PERSONAL_1 0xDD08U +#define MTP_OB_PROP_EMAIL_PERSONAL_2 0xDD09U +#define MTP_OB_PROP_EMAIL_BUSINESS_1 0xDD0AU +#define MTP_OB_PROP_EMAIL_BUSINESS_2 0xDD0BU +#define MTP_OB_PROP_EMAIL_OTHERS 0xDD0CU +#define MTP_OB_PROP_PHONE_NUMBER_PRIMARY 0xDD0DU +#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL 0xDD0EU +#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL_2 0xDD0FU +#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS 0xDD10U +#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS_2 0xDD11U +#define MTP_OB_PROP_PHONE_NUMBER_MOBILE 0xDD12U +#define MTP_OB_PROP_PHONE_NUMBER_MOBILE_2 0xDD13U +#define MTP_OB_PROP_FAX_NUMBER_PRIMARY 0xDD14U +#define MTP_OB_PROP_FAX_NUMBER_PERSONAL 0xDD15U +#define MTP_OB_PROP_FAX_NUMBER_BUSINESS 0xDD16U +#define MTP_OB_PROP_PAGER_NUMBER 0xDD17U +#define MTP_OB_PROP_PHONE_NUMBER_OTHERS 0xDD18U +#define MTP_OB_PROP_PRIMARY_WEB_ADDRESS 0xDD19U +#define MTP_OB_PROP_PERSONAL_WEB_ADDRESS 0xDD1AU +#define MTP_OB_PROP_BUSINESS_WEB_ADDRESS 0xDD1BU +#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS 0xDD1CU +#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_2 0xDD1DU +#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_3 0xDD1EU +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_FULL 0xDD1FU +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_1 0xDD20U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_2 0xDD21U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_CITY 0xDD22U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_REGION 0xDD23U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_POSTAL_CODE 0xDD24U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_COUNTRY 0xDD25U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_FULL 0xDD26U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_1 0xDD27U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_2 0xDD28U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_CITY 0xDD29U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_REGION 0xDD2AU +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_POSTAL_CODE 0xDD2BU +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_COUNTRY 0xDD2CU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_FULL 0xDD2DU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_1 0xDD2EU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_2 0xDD2FU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_CITY 0xDD30U +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_REGION 0xDD31U +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_POSTAL_CODE 0xDD32U +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_COUNTRY 0xDD33U +#define MTP_OB_PROP_ORGANIZATION_NAME 0xDD34U +#define MTP_OB_PROP_PHONETIC_ORGANIZATION_NAME 0xDD35U +#define MTP_OB_PROP_ROLE 0xDD36U +#define MTP_OB_PROP_BIRTHDATE 0xDD37U +#define MTP_OB_PROP_MESSAGE_TO 0xDD40U +#define MTP_OB_PROP_MESSAGE_CC 0xDD41U +#define MTP_OB_PROP_MESSAGE_BCC 0xDD42U +#define MTP_OB_PROP_MESSAGE_READ 0xDD43U +#define MTP_OB_PROP_MESSAGE_RECEIVED_TIME 0xDD44U +#define MTP_OB_PROP_MESSAGE_SENDER 0xDD45U +#define MTP_OB_PROP_ACT_BEGIN_TIME 0xDD50U +#define MTP_OB_PROP_ACT_END_TIME 0xDD51U +#define MTP_OB_PROP_ACT_LOCATION 0xDD52U +#define MTP_OB_PROP_ACT_REQUIRED_ATTENDEES 0xDD54U +#define MTP_OB_PROP_ACT_OPTIONAL_ATTENDEES 0xDD55U +#define MTP_OB_PROP_ACT_RESOURCES 0xDD56U +#define MTP_OB_PROP_ACT_ACCEPTED 0xDD57U +#define MTP_OB_PROP_OWNER 0xDD5DU +#define MTP_OB_PROP_EDITOR 0xDD5EU +#define MTP_OB_PROP_WEBMASTER 0xDD5FU +#define MTP_OB_PROP_URL_SOURCE 0xDD60U +#define MTP_OB_PROP_URL_DESTINATION 0xDD61U +#define MTP_OB_PROP_TIME_BOOKMARK 0xDD62U +#define MTP_OB_PROP_OBJECT_BOOKMARK 0xDD63U +#define MTP_OB_PROP_BYTE_BOOKMARK 0xDD64U +#define MTP_OB_PROP_LAST_BUILD_DATE 0xDD70U +#define MTP_OB_PROP_TIME_TO_LIVE 0xDD71U +#define MTP_OB_PROP_MEDIA_GUID 0xDD72U + +/* MTP event codes*/ +#define MTP_EVENT_UNDEFINED 0x4000U +#define MTP_EVENT_CANCELTRANSACTION 0x4001U +#define MTP_EVENT_OBJECTADDED 0x4002U +#define MTP_EVENT_OBJECTREMOVED 0x4003U +#define MTP_EVENT_STOREADDED 0x4004U +#define MTP_EVENT_STOREREMOVED 0x4005U +#define MTP_EVENT_DEVICEPROPCHANGED 0x4006U +#define MTP_EVENT_OBJECTINFOCHANGED 0x4007U +#define MTP_EVENT_DEVICEINFOCHANGED 0x4008U +#define MTP_EVENT_REQUESTOBJECTTRANSFER 0x4009U +#define MTP_EVENT_STOREFULL 0x400AU +#define MTP_EVENT_DEVICERESET 0x400BU +#define MTP_EVENT_STORAGEINFOCHANGED 0x400CU +#define MTP_EVENT_CAPTURECOMPLETE 0x400DU +#define MTP_EVENT_UNREPORTEDSTATUS 0x400EU +#define MTP_EVENT_OBJECTPROPCHANGED 0xC801U +#define MTP_EVENT_OBJECTPROPDESCCHANGED 0xC802U +#define MTP_EVENT_OBJECTREFERENCESCHANGED 0xC803U + +/* + * MTP Class specification Revision 1.1 + * Appendix D. Operations + */ + +/* Operations code */ +#define MTP_OP_GET_DEVICE_INFO 0x1001U +#define MTP_OP_OPEN_SESSION 0x1002U +#define MTP_OP_CLOSE_SESSION 0x1003U +#define MTP_OP_GET_STORAGE_IDS 0x1004U +#define MTP_OP_GET_STORAGE_INFO 0x1005U +#define MTP_OP_GET_NUM_OBJECTS 0x1006U +#define MTP_OP_GET_OBJECT_HANDLES 0x1007U +#define MTP_OP_GET_OBJECT_INFO 0x1008U +#define MTP_OP_GET_OBJECT 0x1009U +#define MTP_OP_GET_THUMB 0x100AU +#define MTP_OP_DELETE_OBJECT 0x100BU +#define MTP_OP_SEND_OBJECT_INFO 0x100CU +#define MTP_OP_SEND_OBJECT 0x100DU +#define MTP_OP_FORMAT_STORE 0x100FU +#define MTP_OP_RESET_DEVICE 0x1010U +#define MTP_OP_GET_DEVICE_PROP_DESC 0x1014U +#define MTP_OP_GET_DEVICE_PROP_VALUE 0x1015U +#define MTP_OP_SET_DEVICE_PROP_VALUE 0x1016U +#define MTP_OP_RESET_DEVICE_PROP_VALUE 0x1017U +#define MTP_OP_TERMINATE_OPEN_CAPTURE 0x1018U +#define MTP_OP_MOVE_OBJECT 0x1019U +#define MTP_OP_COPY_OBJECT 0x101AU +#define MTP_OP_GET_PARTIAL_OBJECT 0x101BU +#define MTP_OP_INITIATE_OPEN_CAPTURE 0x101CU +#define MTP_OP_GET_OBJECT_PROPS_SUPPORTED 0x9801U +#define MTP_OP_GET_OBJECT_PROP_DESC 0x9802U +#define MTP_OP_GET_OBJECT_PROP_VALUE 0x9803U +#define MTP_OP_SET_OBJECT_PROP_VALUE 0x9804U +#define MTP_OP_GET_OBJECT_PROPLIST 0x9805U +#define MTP_OP_GET_OBJECT_PROP_REFERENCES 0x9810U +#define MTP_OP_GETSERVICEIDS 0x9301U +#define MTP_OP_GETSERVICEINFO 0x9302U +#define MTP_OP_GETSERVICECAPABILITIES 0x9303U +#define MTP_OP_GETSERVICEPROPDESC 0x9304U + +/* + * MTP Class specification Revision 1.1 + * Appendix C. Device Properties + */ + +/* MTP device properties code*/ +#define MTP_DEV_PROP_UNDEFINED 0x5000U +#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U +#define MTP_DEV_PROP_FUNCTIONAL_MODE 0x5002U +#define MTP_DEV_PROP_IMAGE_SIZE 0x5003U +#define MTP_DEV_PROP_COMPRESSION_SETTING 0x5004U +#define MTP_DEV_PROP_WHITE_BALANCE 0x5005U +#define MTP_DEV_PROP_RGB_GAIN 0x5006U +#define MTP_DEV_PROP_F_NUMBER 0x5007U +#define MTP_DEV_PROP_FOCAL_LENGTH 0x5008U +#define MTP_DEV_PROP_FOCUS_DISTANCE 0x5009U +#define MTP_DEV_PROP_FOCUS_MODE 0x500AU +#define MTP_DEV_PROP_EXPOSURE_METERING_MODE 0x500BU +#define MTP_DEV_PROP_FLASH_MODE 0x500CU +#define MTP_DEV_PROP_EXPOSURE_TIME 0x500DU +#define MTP_DEV_PROP_EXPOSURE_PROGRAM_MODE 0x500EU +#define MTP_DEV_PROP_EXPOSURE_INDEX 0x500FU +#define MTP_DEV_PROP_EXPOSURE_BIAS_COMPENSATION 0x5010U +#define MTP_DEV_PROP_DATETIME 0x5011U +#define MTP_DEV_PROP_CAPTURE_DELAY 0x5012U +#define MTP_DEV_PROP_STILL_CAPTURE_MODE 0x5013U +#define MTP_DEV_PROP_CONTRAST 0x5014U +#define MTP_DEV_PROP_SHARPNESS 0x5015U +#define MTP_DEV_PROP_DIGITAL_ZOOM 0x5016U +#define MTP_DEV_PROP_EFFECT_MODE 0x5017U +#define MTP_DEV_PROP_BURST_NUMBER 0x5018U +#define MTP_DEV_PROP_BURST_INTERVAL 0x5019U +#define MTP_DEV_PROP_TIMELAPSE_NUMBER 0x501AU +#define MTP_DEV_PROP_TIMELAPSE_INTERVAL 0x501BU +#define MTP_DEV_PROP_FOCUS_METERING_MODE 0x501CU +#define MTP_DEV_PROP_UPLOAD_URL 0x501DU +#define MTP_DEV_PROP_ARTIST 0x501EU +#define MTP_DEV_PROP_COPYRIGHT_INFO 0x501FU +#define MTP_DEV_PROP_SYNCHRONIZATION_PARTNER 0xD401U +#define MTP_DEV_PROP_DEVICE_FRIENDLY_NAME 0xD402U +#define MTP_DEV_PROP_VOLUME 0xD403U +#define MTP_DEV_PROP_SUPPORTEDFORMATSORDERED 0xD404U +#define MTP_DEV_PROP_DEVICEICON 0xD405U +#define MTP_DEV_PROP_PLAYBACK_RATE 0xD410U +#define MTP_DEV_PROP_PLAYBACK_OBJECT 0xD411U +#define MTP_DEV_PROP_PLAYBACK_CONTAINER 0xD412U +#define MTP_DEV_PROP_SESSION_INITIATOR_VERSION_INFO 0xD406U +#define MTP_DEV_PROP_PERCEIVED_DEVICE_TYPE 0xD407U + +/* Container Types */ +#define MTP_CONT_TYPE_UNDEFINED 0U +#define MTP_CONT_TYPE_COMMAND 1U +#define MTP_CONT_TYPE_DATA 2U +#define MTP_CONT_TYPE_RESPONSE 3U +#define MTP_CONT_TYPE_EVENT 4U + +#ifndef MTP_STORAGE_ID +#define MTP_STORAGE_ID 0x00010001U /* SD card is inserted*/ +#endif /* MTP_STORAGE_ID */ + +#define MTP_NBR_STORAGE_ID 1U +#define FREE_SPACE_IN_OBJ_NOT_USED 0xFFFFFFFFU + +/* MTP storage type */ +#define MTP_STORAGE_UNDEFINED 0U +#define MTP_STORAGE_FIXED_ROM 0x0001U +#define MTP_STORAGE_REMOVABLE_ROM 0x0002U +#define MTP_STORAGE_FIXED_RAM 0x0003U +#define MTP_STORAGE_REMOVABLE_RAM 0x0004U + +/* MTP file system type */ +#define MTP_FILESYSTEM_UNDEFINED 0U +#define MTP_FILESYSTEM_GENERIC_FLAT 0x0001U +#define MTP_FILESYSTEM_GENERIC_HIERARCH 0x0002U +#define MTP_FILESYSTEM_DCF 0x0003U + +/* MTP access capability */ +#define MTP_ACCESS_CAP_RW 0U /* read write */ +#define MTP_ACCESS_CAP_RO_WITHOUT_DEL 0x0001U +#define MTP_ACCESS_CAP_RO_WITH_DEL 0x0002U + +/* MTP standard data types supported */ +#define MTP_DATATYPE_INT8 0x0001U +#define MTP_DATATYPE_UINT8 0x0002U +#define MTP_DATATYPE_INT16 0x0003U +#define MTP_DATATYPE_UINT16 0x0004U +#define MTP_DATATYPE_INT32 0x0005U +#define MTP_DATATYPE_UINT32 0x0006U +#define MTP_DATATYPE_INT64 0x0007U +#define MTP_DATATYPE_UINT64 0x0008U +#define MTP_DATATYPE_UINT128 0x000AU +#define MTP_DATATYPE_STR 0xFFFFU + +/* MTP reading only or reading/writing */ +#define MTP_PROP_GET 0x00U +#define MTP_PROP_GET_SET 0x01U + +#endif /* USB_MTP_H */ diff --git a/third-party/cherryusb-0.7.0/class/mtp/usbd_mtp.c b/third-party/cherryusb-0.7.0/class/mtp/usbd_mtp.c new file mode 100644 index 0000000000000000000000000000000000000000..38661e914648d72646a6833e56f7645f4a31ca3b --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/mtp/usbd_mtp.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "usbd_core.h" +#include "usbd_mtp.h" + +struct mtp_cfg_priv { + uint8_t device_status; +} usbd_mtp_cfg; + +/* max USB packet size */ +#ifndef CONFIG_USB_HS +#define MTP_BULK_EP_MPS 64 +#else +#define MTP_BULK_EP_MPS 512 +#endif + +#define MSD_OUT_EP_IDX 0 +#define MSD_IN_EP_IDX 1 + +/* Describe EndPoints configuration */ +static struct usbd_interface mtp_ep_data[2]; + +static int mtp_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) +{ + USB_LOG_DBG("MTP Class request: " + "bRequest 0x%02x\r\n", + setup->bRequest); + + switch (setup->bRequest) { + case MTP_REQUEST_CANCEL: + + break; + case MTP_REQUEST_GET_EXT_EVENT_DATA: + + break; + case MTP_REQUEST_RESET: + + break; + case MTP_REQUEST_GET_DEVICE_STATUS: + + break; + + default: + USB_LOG_WRN("Unhandled MTP Class bRequest 0x%02x\r\n", setup->bRequest); + return -1; + } + + return 0; +} + +static void usbd_mtp_bulk_out(uint8_t ep) +{ +} + +static void usbd_mtp_bulk_in(uint8_t ep) +{ +} + +static void mtp_notify_handler(uint8_t event, void *arg) +{ + switch (event) { + case USBD_EVENT_RESET: + break; + + default: + break; + } +} \ No newline at end of file diff --git a/third-party/cherryusb-0.7.0/class/mtp/usbd_mtp.h b/third-party/cherryusb-0.7.0/class/mtp/usbd_mtp.h new file mode 100644 index 0000000000000000000000000000000000000000..7162141c9859d41fe338d52cb9d3450fc8180ab8 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/mtp/usbd_mtp.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef USBD_MTP_H +#define USBD_MTP_H + +#include "usb_mtp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* USBD_MTP_H */ diff --git a/third-party/cherryusb-0.7.0/class/mtp/usbh_mtp.c b/third-party/cherryusb-0.7.0/class/mtp/usbh_mtp.c new file mode 100644 index 0000000000000000000000000000000000000000..98c02a8b333d3aee82d811f20589fd50b2ae36e5 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/mtp/usbh_mtp.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "usbh_core.h" +#include "usbh_mtp.h" + +#define DEV_FORMAT "/dev/mtp" + +static int usbh_mtp_connect(struct usbh_hubport *hport, uint8_t intf) +{ + struct usbh_endpoint_cfg ep_cfg = { 0 }; + struct usb_endpoint_descriptor *ep_desc; + int ret; + + struct usbh_mtp *mtp_class = usb_malloc(sizeof(struct usbh_mtp)); + if (mtp_class == NULL) { + USB_LOG_ERR("Fail to alloc mtp_class\r\n"); + return -ENOMEM; + } + + memset(mtp_class, 0, sizeof(struct usbh_mtp)); + + mtp_class->hport = hport; + mtp_class->ctrl_intf = intf; + mtp_class->data_intf = intf + 1; + + hport->config.intf[intf].priv = mtp_class; + hport->config.intf[intf + 1].priv = NULL; + strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN); + +#ifdef CONFIG_USBHOST_MTP_NOTIFY + ep_desc = &hport->config.intf[intf].ep[0].ep_desc; + ep_cfg.ep_addr = ep_desc->bEndpointAddress; + ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; + ep_cfg.ep_mps = ep_desc->wMaxPacketSize; + ep_cfg.ep_interval = ep_desc->bInterval; + ep_cfg.hport = hport; + usbh_pipe_alloc(&mtp_class->intin, &ep_cfg); + +#endif + for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc; + + ep_cfg.ep_addr = ep_desc->bEndpointAddress; + ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; + ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK;; + ep_cfg.ep_interval = ep_desc->bInterval; + ep_cfg.hport = hport; + if (ep_desc->bEndpointAddress & 0x80) { + usbh_pipe_alloc(&mtp_class->bulkin, &ep_cfg); + } else { + usbh_pipe_alloc(&mtp_class->bulkout, &ep_cfg); + } + } + + strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN); + + USB_LOG_INFO("Register MTP Class:%s\r\n", hport->config.intf[intf].devname); + + return ret; +} + +static int usbh_mtp_disconnect(struct usbh_hubport *hport, uint8_t intf) +{ + int ret = 0; + + struct usbh_mtp *mtp_class = (struct usbh_mtp *)hport->config.intf[intf].priv; + + if (mtp_class) { + if (mtp_class->bulkin) { + usbh_pipe_free(mtp_class->bulkin); + } + + if (mtp_class->bulkout) { + usbh_pipe_free(mtp_class->bulkout); + } + + usb_free(mtp_class); + + if (hport->config.intf[intf].devname[0] != '\0') + USB_LOG_INFO("Unregister MTP Class:%s\r\n", hport->config.intf[intf].devname); + + memset(hport->config.intf[intf].devname, 0, CONFIG_USBHOST_DEV_NAMELEN); + hport->config.intf[intf].priv = NULL; + hport->config.intf[intf + 1].priv = NULL; + } + + return ret; +} + +static const struct usbh_class_driver mtp_class_driver = { + .driver_name = "mtp", + .connect = usbh_mtp_connect, + .disconnect = usbh_mtp_disconnect +}; + +CLASS_INFO_DEFINE const struct usbh_class_info mtp_class_info = { + .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL, + .class = USB_MTP_CLASS, + .subclass = USB_MTP_SUB_CLASS, + .protocol = USB_MTP_PROTOCOL, + .vid = 0x00, + .pid = 0x00, + .class_driver = &mtp_class_driver +}; diff --git a/third-party/cherryusb-0.7.0/class/mtp/usbh_mtp.h b/third-party/cherryusb-0.7.0/class/mtp/usbh_mtp.h new file mode 100644 index 0000000000000000000000000000000000000000..5fdf28c5ee693897c6860a471c7db95580eda1e4 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/mtp/usbh_mtp.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef USBH_MTP_H +#define USBH_MTP_H + +#include "usb_mtp.h" + +struct usbh_mtp { + struct usbh_hubport *hport; + + uint8_t intf; /* interface number */ + usbh_pipe_t bulkin; /* BULK IN endpoint */ + usbh_pipe_t bulkout; /* BULK OUT endpoint */ +#ifdef CONFIG_USBHOST_MTP_NOTIFY + usbh_pipe_t intin; /* Interrupt IN endpoint (optional) */ +#endif +}; + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* USBH_MTP_H */ diff --git a/third-party/cherryusb-0.7.0/class/printer/usb_printer.h b/third-party/cherryusb-0.7.0/class/printer/usb_printer.h new file mode 100644 index 0000000000000000000000000000000000000000..c8105c9fcf16a8097896e361fb2d8c67854aefee --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/printer/usb_printer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef USB_PRINTER_H +#define USB_PRINTER_H + +#define PRINTER_SUBCLASS 0x01U + +#define PRINTER_REQUEST_GET_DEVICE_ID 0x00U +#define PRINTER_REQUEST_GET_PORT_SATTUS 0x01U +#define PRINTER_REQUEST_SOFT_RESET 0x02U + +#define PRINTER_STATUS_NO_ERROR 0x00U +#define PRINTER_STATUS_SELECTED 0x08U +#define PRINTER_STATUS_PAPER_EMPTY 0x10U + +#endif /* USB_PRINTER_H */ diff --git a/third-party/cherryusb-0.7.0/class/printer/usbd_printer.c b/third-party/cherryusb-0.7.0/class/printer/usbd_printer.c new file mode 100644 index 0000000000000000000000000000000000000000..bdc5984c4c165b9b4d23536eddc057b97d9be9fc --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/printer/usbd_printer.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "usbd_core.h" +#include "usbd_printer.h" + +struct printer_cfg_priv { + uint8_t *device_id; + uint8_t port_status; +} usbd_printer_cfg; + +static int printer_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) +{ + USB_LOG_DBG("Printer Class request: " + "bRequest 0x%02x\r\n", + setup->bRequest); + + switch (setup->bRequest) { + case PRINTER_REQUEST_GET_DEVICE_ID: + + break; + case PRINTER_REQUEST_GET_PORT_SATTUS: + + break; + case PRINTER_REQUEST_SOFT_RESET: + + break; + default: + USB_LOG_WRN("Unhandled Printer Class bRequest 0x%02x\r\n", setup->bRequest); + return -1; + } + + return 0; +} + +static void printer_notify_handler(uint8_t event, void *arg) +{ + switch (event) { + case USBD_EVENT_RESET: + break; + + default: + break; + } +} + +struct usbd_interface *usbd_printer_alloc_intf(void) +{ + struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); + if (intf == NULL) { + USB_LOG_ERR("no mem to alloc intf\r\n"); + return NULL; + } + + intf->class_interface_handler = printer_class_interface_request_handler; + intf->class_endpoint_handler = NULL; + intf->vendor_handler = NULL; + intf->notify_handler = printer_notify_handler; + + return intf; +} \ No newline at end of file diff --git a/third-party/cherryusb-0.7.0/class/printer/usbd_printer.h b/third-party/cherryusb-0.7.0/class/printer/usbd_printer.h new file mode 100644 index 0000000000000000000000000000000000000000..7f691dfcf0b3f86841105b4808bb9baf589ba744 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/printer/usbd_printer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef USBD_PRINTER_H +#define USBD_PRINTER_H + +#include "usb_printer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Alloc printer interface driver */ +struct usbd_interface *usbd_printer_alloc_intf(void); + +#ifdef __cplusplus +} +#endif + +#endif /* USBD_PRINTER_H */ diff --git a/third-party/cherryusb-0.7.0/class/printer/usbh_printer.c b/third-party/cherryusb-0.7.0/class/printer/usbh_printer.c new file mode 100644 index 0000000000000000000000000000000000000000..6b55b06819dcd320bbb598f6d7916f59392f435a --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/printer/usbh_printer.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "usbh_core.h" +#include "usbh_printer.h" + +#define DEV_FORMAT "/dev/printer" + +static int usbh_printer_get_device_id(struct usbh_printer *printer_class, uint8_t *buffer) +{ + struct usb_setup_packet *setup = &printer_class->hport->setup; + int ret; + + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; + setup->bRequest = PRINTER_REQUEST_GET_DEVICE_ID; + setup->wValue = 0; + setup->wIndex = printer_class->intf; + setup->wLength = 256; + + return usbh_control_transfer(printer_class->hport->ep0, setup, buffer); +} + +static int usbh_printer_get_port_status(struct usbh_printer *printer_class, uint8_t *buffer) +{ + struct usb_setup_packet *setup = &printer_class->hport->setup; + int ret; + + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; + setup->bRequest = PRINTER_REQUEST_GET_PORT_SATTUS; + setup->wValue = 0; + setup->wIndex = printer_class->intf; + setup->wLength = 1; + + return usbh_control_transfer(printer_class->hport->ep0, setup, buffer); +} + +static int usbh_printer_soft_reset(struct usbh_printer *printer_class) +{ + struct usb_setup_packet *setup = &printer_class->hport->setup; + int ret; + + setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; + setup->bRequest = PRINTER_REQUEST_SOFT_RESET; + setup->wValue = 0; + setup->wIndex = printer_class->intf; + setup->wLength = 0; + + return usbh_control_transfer(printer_class->hport->ep0, setup, NULL); +} + +static int usbh_printer_connect(struct usbh_hubport *hport, uint8_t intf) +{ + struct usbh_endpoint_cfg ep_cfg = { 0 }; + struct usb_endpoint_descriptor *ep_desc; + int ret; + + struct usbh_printer *printer_class = usb_malloc(sizeof(struct usbh_printer)); + if (printer_class == NULL) { + USB_LOG_ERR("Fail to alloc printer_class\r\n"); + return -ENOMEM; + } + + memset(printer_class, 0, sizeof(struct usbh_printer)); + + printer_class->hport = hport; + printer_class->intf = intf; + + hport->config.intf[intf].priv = printer_class; + + for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc; + + ep_cfg.ep_addr = ep_desc->bEndpointAddress; + ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; + ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; + ep_cfg.ep_interval = ep_desc->bInterval; + ep_cfg.hport = hport; + if (ep_desc->bEndpointAddress & 0x80) { + usbh_pipe_alloc(&printer_class->bulkin, &ep_cfg); + } else { + usbh_pipe_alloc(&printer_class->bulkout, &ep_cfg); + } + } + + // uint8_t *device_id = usb_iomalloc(256); + // ret = usbh_printer_get_device_id(printer_class, device_id); + strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN); + + USB_LOG_INFO("Register Printer Class:%s\r\n", hport->config.intf[intf].devname); + + return ret; +} + +static int usbh_printer_disconnect(struct usbh_hubport *hport, uint8_t intf) +{ + int ret = 0; + + struct usbh_printer *printer_class = (struct usbh_printer *)hport->config.intf[intf].priv; + + if (printer_class) { + if (printer_class->bulkin) { + usbh_pipe_free(printer_class->bulkin); + } + + if (printer_class->bulkout) { + usbh_pipe_free(printer_class->bulkout); + } + + usb_free(printer_class); + + if (hport->config.intf[intf].devname[0] != '\0') + USB_LOG_INFO("Unregister Printer Class:%s\r\n", hport->config.intf[intf].devname); + + memset(hport->config.intf[intf].devname, 0, CONFIG_USBHOST_DEV_NAMELEN); + hport->config.intf[intf].priv = NULL; + } + + return ret; +} + +static const struct usbh_class_driver printer_class_driver = { + .driver_name = "printer", + .connect = usbh_printer_connect, + .disconnect = usbh_printer_disconnect +}; + +CLASS_INFO_DEFINE const struct usbh_class_info printer_class_info = { + .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL, + .class = USB_DEVICE_CLASS_PRINTER, + .subclass = PRINTER_SUBCLASS, + .protocol = 0x00, + .vid = 0x00, + .pid = 0x00, + .class_driver = &printer_class_driver +}; diff --git a/third-party/cherryusb-0.7.0/class/printer/usbh_printer.h b/third-party/cherryusb-0.7.0/class/printer/usbh_printer.h new file mode 100644 index 0000000000000000000000000000000000000000..f9648a3fa22dee4fb8633ea5dad85312f027490e --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/printer/usbh_printer.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef USBH_PRINTER_H +#define USBH_PRINTER_H + +#include "usb_printer.h" + +struct usbh_printer { + struct usbh_hubport *hport; + + uint8_t intf; /* interface number */ + usbh_pipe_t bulkin; /* BULK IN endpoint */ + usbh_pipe_t bulkout; /* BULK OUT endpoint */ +}; + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* USBH_PRINTER_H */ diff --git a/third-party/cherryusb-0.6.0/class/template/usb_xxx.h b/third-party/cherryusb-0.7.0/class/template/usb_xxx.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/template/usb_xxx.h rename to third-party/cherryusb-0.7.0/class/template/usb_xxx.h diff --git a/third-party/cherryusb-0.6.0/class/template/usbd_xxx.c b/third-party/cherryusb-0.7.0/class/template/usbd_xxx.c similarity index 100% rename from third-party/cherryusb-0.6.0/class/template/usbd_xxx.c rename to third-party/cherryusb-0.7.0/class/template/usbd_xxx.c diff --git a/third-party/cherryusb-0.6.0/class/template/usbd_xxx.h b/third-party/cherryusb-0.7.0/class/template/usbd_xxx.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/template/usbd_xxx.h rename to third-party/cherryusb-0.7.0/class/template/usbd_xxx.h diff --git a/third-party/cherryusb-0.6.0/class/template/usbh_xxx.c b/third-party/cherryusb-0.7.0/class/template/usbh_xxx.c similarity index 100% rename from third-party/cherryusb-0.6.0/class/template/usbh_xxx.c rename to third-party/cherryusb-0.7.0/class/template/usbh_xxx.c diff --git a/third-party/cherryusb-0.6.0/class/template/usbh_xxx.h b/third-party/cherryusb-0.7.0/class/template/usbh_xxx.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/template/usbh_xxx.h rename to third-party/cherryusb-0.7.0/class/template/usbh_xxx.h diff --git a/third-party/cherryusb-0.7.0/class/vendor/asix.h b/third-party/cherryusb-0.7.0/class/vendor/asix.h new file mode 100644 index 0000000000000000000000000000000000000000..2d153b9bb65c41045343d217a408506430100875 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/vendor/asix.h @@ -0,0 +1,596 @@ +/* + * Change Logs + * Date Author Notes + * 2022-04-17 aozima the first version for CherryUSB. + */ + +#ifndef __LINUX_USBNET_ASIX_H +#define __LINUX_USBNET_ASIX_H + +// #define __BIG_ENDIAN_BITFIELD +#define __LITTLE_ENDIAN_BITFIELD +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; + +#define KERNEL_VERSION(...) (0) +#define LINUX_VERSION_CODE (1) + +/* + * Turn on this flag if the implementation of your USB host controller + * cannot handle non-double word aligned buffer. + * When turn on this flag, driver will fixup egress packet aligned on double + * word boundary before deliver to USB host controller. And will Disable the + * function "skb_reserve (skb, NET_IP_ALIGN)" to retain the buffer aligned on + * double word alignment for ingress packets. + */ +#define AX_FORCE_BUFF_ALIGN 0 + +//#define RX_SKB_COPY + +#define AX_MONITOR_MODE 0x01 +#define AX_MONITOR_LINK 0x02 +#define AX_MONITOR_MAGIC 0x04 +#define AX_MONITOR_HSFS 0x10 + +/* AX88172 Medium Status Register values */ +#define AX_MEDIUM_FULL_DUPLEX 0x02 +#define AX_MEDIUM_TX_ABORT_ALLOW 0x04 +#define AX_MEDIUM_FLOW_CONTROL_EN 0x10 +#define AX_MCAST_FILTER_SIZE 8 +#define AX_MAX_MCAST 64 + +#define AX_EEPROM_LEN 0x40 + +#define AX_SWRESET_CLEAR 0x00 +#define AX_SWRESET_RR 0x01 +#define AX_SWRESET_RT 0x02 +#define AX_SWRESET_PRTE 0x04 +#define AX_SWRESET_PRL 0x08 +#define AX_SWRESET_BZ 0x10 +#define AX_SWRESET_IPRL 0x20 +#define AX_SWRESET_IPPD 0x40 +#define AX_SWRESET_IPOSC 0x0080 +#define AX_SWRESET_IPPSL_0 0x0100 +#define AX_SWRESET_IPPSL_1 0x0200 +#define AX_SWRESET_IPCOPS 0x0400 +#define AX_SWRESET_IPCOPSC 0x0800 +#define AX_SWRESET_AUTODETACH 0x1000 +#define AX_SWRESET_WOLLP 0x8000 + +#define AX88772_IPG0_DEFAULT 0x15 +#define AX88772_IPG1_DEFAULT 0x0c +#define AX88772_IPG2_DEFAULT 0x0E + +#define AX88772A_IPG0_DEFAULT 0x15 +#define AX88772A_IPG1_DEFAULT 0x16 +#define AX88772A_IPG2_DEFAULT 0x1A + +#define AX88772_MEDIUM_FULL_DUPLEX 0x0002 +#define AX88772_MEDIUM_RESERVED 0x0004 +#define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 +#define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 +#define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 +#define AX88772_MEDIUM_RX_ENABLE 0x0100 +#define AX88772_MEDIUM_100MB 0x0200 +#define AX88772_MEDIUM_DEFAULT \ + (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ + AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ + AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE) + +#define AX_CMD_SET_SW_MII 0x06 +#define AX_CMD_READ_MII_REG 0x07 +#define AX_CMD_WRITE_MII_REG 0x08 +#define AX_CMD_READ_STATMNGSTS_REG 0x09 + #define AX_HOST_EN 0x01 + +#define AX_CMD_SET_HW_MII 0x0a +#define AX_CMD_READ_EEPROM 0x0b +#define AX_CMD_WRITE_EEPROM 0x0c +#define AX_CMD_WRITE_EEPROM_EN 0x0d +#define AX_CMD_WRITE_EEPROM_DIS 0x0e +#define AX_CMD_WRITE_RX_CTL 0x10 +#define AX_CMD_READ_IPG012 0x11 +#define AX_CMD_WRITE_IPG0 0x12 +#define AX_CMD_WRITE_IPG1 0x13 +#define AX_CMD_WRITE_IPG2 0x14 +#define AX_CMD_WRITE_MULTI_FILTER 0x16 +#define AX_CMD_READ_NODE_ID 0x17 +#define AX_CMD_READ_PHY_ID 0x19 +#define AX_CMD_READ_MEDIUM_MODE 0x1a +#define AX_CMD_WRITE_MEDIUM_MODE 0x1b +#define AX_CMD_READ_MONITOR_MODE 0x1c +#define AX_CMD_WRITE_MONITOR_MODE 0x1d +#define AX_CMD_WRITE_GPIOS 0x1f +#define AX_CMD_SW_RESET 0x20 +#define AX_CMD_SW_PHY_STATUS 0x21 +#define AX_CMD_SW_PHY_SELECT 0x22 + #define AX_PHYSEL_PSEL (1 << 0) + #define AX_PHYSEL_ASEL (1 << 1) + #define AX_PHYSEL_SSMII (0 << 2) + #define AX_PHYSEL_SSRMII (1 << 2) + #define AX_PHYSEL_SSRRMII (3 << 2) + #define AX_PHYSEL_SSEN (1 << 4) +#define AX88772_CMD_READ_NODE_ID 0x13 +#define AX88772_CMD_WRITE_NODE_ID 0x14 +#define AX_CMD_READ_WKFARY 0x23 +#define AX_CMD_WRITE_WKFARY 0x24 +#define AX_CMD_READ_RXCOE_CTL 0x2b +#define AX_CMD_WRITE_RXCOE_CTL 0x2c +#define AX_CMD_READ_TXCOE_CTL 0x2d +#define AX_CMD_WRITE_TXCOE_CTL 0x2e + +#define REG_LENGTH 2 +#define PHY_ID_MASK 0x1f + +#define AX_RXCOE_IPCE 0x0001 +#define AX_RXCOE_IPVE 0x0002 +#define AX_RXCOE_V6VE 0x0004 +#define AX_RXCOE_TCPE 0x0008 +#define AX_RXCOE_UDPE 0x0010 +#define AX_RXCOE_ICMP 0x0020 +#define AX_RXCOE_IGMP 0x0040 +#define AX_RXCOE_ICV6 0x0080 +#define AX_RXCOE_TCPV6 0x0100 +#define AX_RXCOE_UDPV6 0x0200 +#define AX_RXCOE_ICMV6 0x0400 +#define AX_RXCOE_IGMV6 0x0800 +#define AX_RXCOE_ICV6V6 0x1000 +#define AX_RXCOE_FOPC 0x8000 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22) +#define AX_RXCOE_DEF_CSUM (AX_RXCOE_IPCE | AX_RXCOE_IPVE | \ + AX_RXCOE_V6VE | AX_RXCOE_TCPE | \ + AX_RXCOE_UDPE | AX_RXCOE_ICV6 | \ + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6) +#else +#define AX_RXCOE_DEF_CSUM (AX_RXCOE_IPCE | AX_RXCOE_IPVE | \ + AX_RXCOE_TCPE | AX_RXCOE_UDPE) +#endif + +#define AX_RXCOE_64TE 0x0100 +#define AX_RXCOE_PPPOE 0x0200 +#define AX_RXCOE_RPCE 0x8000 + +#define AX_TXCOE_IP 0x0001 +#define AX_TXCOE_TCP 0x0002 +#define AX_TXCOE_UDP 0x0004 +#define AX_TXCOE_ICMP 0x0008 +#define AX_TXCOE_IGMP 0x0010 +#define AX_TXCOE_ICV6 0x0020 + +#define AX_TXCOE_TCPV6 0x0100 +#define AX_TXCOE_UDPV6 0x0200 +#define AX_TXCOE_ICMV6 0x0400 +#define AX_TXCOE_IGMV6 0x0800 +#define AX_TXCOE_ICV6V6 0x1000 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22) +#define AX_TXCOE_DEF_CSUM (AX_TXCOE_TCP | AX_TXCOE_UDP | \ + AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6) +#else +#define AX_TXCOE_DEF_CSUM (AX_TXCOE_TCP | AX_TXCOE_UDP) +#endif + +#define AX_TXCOE_64TE 0x0001 +#define AX_TXCOE_PPPE 0x0002 + +#define AX88772B_MAX_BULKIN_2K 0 +#define AX88772B_MAX_BULKIN_4K 1 +#define AX88772B_MAX_BULKIN_6K 2 +#define AX88772B_MAX_BULKIN_8K 3 +#define AX88772B_MAX_BULKIN_16K 4 +#define AX88772B_MAX_BULKIN_20K 5 +#define AX88772B_MAX_BULKIN_24K 6 +#define AX88772B_MAX_BULKIN_32K 7 +struct {unsigned short size, byte_cnt, threshold; } AX88772B_BULKIN_SIZE[] = { + /* 2k */ + {2048, 0x8000, 0x8001}, + /* 4k */ + {4096, 0x8100, 0x8147}, + /* 6k */ + {6144, 0x8200, 0x81EB}, + /* 8k */ + {8192, 0x8300, 0x83D7}, + /* 16 */ + {16384, 0x8400, 0x851E}, + /* 20k */ + {20480, 0x8500, 0x8666}, + /* 24k */ + {24576, 0x8600, 0x87AE}, + /* 32k */ + {32768, 0x8700, 0x8A3D}, +}; + + +#define AX_RX_CTL_RH1M 0x0100 /* Enable RX-Header mode 0 */ +#define AX_RX_CTL_RH2M 0x0200 /* Enable IP header in receive buffer aligned on 32-bit aligment */ +#define AX_RX_CTL_RH3M 0x0400 /* checksum value in rx header 3 */ +#define AX_RX_HEADER_DEFAULT (AX_RX_CTL_RH1M | AX_RX_CTL_RH2M) + +#define AX_RX_CTL_MFB 0x0300 /* Maximum Frame size 16384bytes */ +#define AX_RX_CTL_START 0x0080 /* Ethernet MAC start */ +#define AX_RX_CTL_AP 0x0020 /* Accept physcial address from Multicast array */ +#define AX_RX_CTL_AM 0x0010 +#define AX_RX_CTL_AB 0x0008 /* Accetp Brocadcast frames*/ +#define AX_RX_CTL_SEP 0x0004 /* Save error packets */ +#define AX_RX_CTL_AMALL 0x0002 /* Accetp all multicast frames */ +#define AX_RX_CTL_PRO 0x0001 /* Promiscuous Mode */ +#define AX_RX_CTL_STOP 0x0000 /* Stop MAC */ + +#define AX_MONITOR_MODE 0x01 +#define AX_MONITOR_LINK 0x02 +#define AX_MONITOR_MAGIC 0x04 +#define AX_MONITOR_HSFS 0x10 + +#define AX_MCAST_FILTER_SIZE 8 +#define AX_MAX_MCAST 64 +#define AX_INTERRUPT_BUFSIZE 8 + +#define AX_EEPROM_LEN 0x40 +#define AX_EEPROM_MAGIC 0xdeadbeef +#define EEPROMMASK 0x7f + +/* GPIO REGISTER */ +#define AXGPIOS_GPO0EN 0X01 /* 1 << 0 */ +#define AXGPIOS_GPO0 0X02 /* 1 << 1 */ +#define AXGPIOS_GPO1EN 0X04 /* 1 << 2 */ +#define AXGPIOS_GPO1 0X08 /* 1 << 3 */ +#define AXGPIOS_GPO2EN 0X10 /* 1 << 4 */ +#define AXGPIOS_GPO2 0X20 /* 1 << 5 */ +#define AXGPIOS_RSE 0X80 /* 1 << 7 */ + +/* TX-header format */ +#define AX_TX_HDR_CPHI 0x4000 +#define AX_TX_HDR_DICF 0x8000 + +/* GMII register definitions */ +#define GMII_PHY_CONTROL 0x00 /* control reg */ +#define GMII_PHY_STATUS 0x01 /* status reg */ +#define GMII_PHY_OUI 0x02 /* most of the OUI bits */ +#define GMII_PHY_MODEL 0x03 /* model/rev bits, and rest of OUI */ +#define GMII_PHY_ANAR 0x04 /* AN advertisement reg */ +#define GMII_PHY_ANLPAR 0x05 /* AN Link Partner */ +#define GMII_PHY_ANER 0x06 /* AN expansion reg */ +#define GMII_PHY_1000BT_CONTROL 0x09 /* control reg for 1000BT */ +#define GMII_PHY_1000BT_STATUS 0x0A /* status reg for 1000BT */ + +/* Bit definitions: GMII Control */ +#define GMII_CONTROL_RESET 0x8000 /* reset bit in control reg */ +#define GMII_CONTROL_LOOPBACK 0x4000 /* loopback bit in control reg */ +#define GMII_CONTROL_10MB 0x0000 /* 10 Mbit */ +#define GMII_CONTROL_100MB 0x2000 /* 100Mbit */ +#define GMII_CONTROL_1000MB 0x0040 /* 1000Mbit */ +#define GMII_CONTROL_SPEED_BITS 0x2040 /* speed bit mask */ +#define GMII_CONTROL_ENABLE_AUTO 0x1000 /* autonegotiate enable */ +#define GMII_CONTROL_POWER_DOWN 0x0800 +#define GMII_CONTROL_ISOLATE 0x0400 /* islolate bit */ +#define GMII_CONTROL_START_AUTO 0x0200 /* restart autonegotiate */ +#define GMII_CONTROL_FULL_DUPLEX 0x0100 + +/* Bit definitions: GMII Status */ +#define GMII_STATUS_100MB_MASK 0xE000 /* any of these indicate 100 Mbit */ +#define GMII_STATUS_10MB_MASK 0x1800 /* either of these indicate 10 Mbit */ +#define GMII_STATUS_AUTO_DONE 0x0020 /* auto negotiation complete */ +#define GMII_STATUS_AUTO 0x0008 /* auto negotiation is available */ +#define GMII_STATUS_LINK_UP 0x0004 /* link status bit */ +#define GMII_STATUS_EXTENDED 0x0001 /* extended regs exist */ +#define GMII_STATUS_100T4 0x8000 /* capable of 100BT4 */ +#define GMII_STATUS_100TXFD 0x4000 /* capable of 100BTX full duplex */ +#define GMII_STATUS_100TX 0x2000 /* capable of 100BTX */ +#define GMII_STATUS_10TFD 0x1000 /* capable of 10BT full duplex */ +#define GMII_STATUS_10T 0x0800 /* capable of 10BT */ + +/* Bit definitions: Auto-Negotiation Advertisement */ +#define GMII_ANAR_ASYM_PAUSE 0x0800 /* support asymetric pause */ +#define GMII_ANAR_PAUSE 0x0400 /* support pause packets */ +#define GMII_ANAR_100T4 0x0200 /* support 100BT4 */ +#define GMII_ANAR_100TXFD 0x0100 /* support 100BTX full duplex */ +#define GMII_ANAR_100TX 0x0080 /* support 100BTX half duplex */ +#define GMII_ANAR_10TFD 0x0040 /* support 10BT full duplex */ +#define GMII_ANAR_10T 0x0020 /* support 10BT half duplex */ +#define GMII_SELECTOR_FIELD 0x001F /* selector field. */ + +/* Bit definitions: Auto-Negotiation Link Partner Ability */ +#define GMII_ANLPAR_100T4 0x0200 /* support 100BT4 */ +#define GMII_ANLPAR_100TXFD 0x0100 /* support 100BTX full duplex */ +#define GMII_ANLPAR_100TX 0x0080 /* support 100BTX half duplex */ +#define GMII_ANLPAR_10TFD 0x0040 /* support 10BT full duplex */ +#define GMII_ANLPAR_10T 0x0020 /* support 10BT half duplex */ +#define GMII_ANLPAR_PAUSE 0x0400 /* support pause packets */ +#define GMII_ANLPAR_ASYM_PAUSE 0x0800 /* support asymetric pause */ +#define GMII_ANLPAR_ACK 0x4000 /* means LCB was successfully rx'd */ +#define GMII_SELECTOR_8023 0x0001; + +/* Bit definitions: 1000BaseT AUX Control */ +#define GMII_1000_AUX_CTRL_MASTER_SLAVE 0x1000 +#define GMII_1000_AUX_CTRL_FD_CAPABLE 0x0200 /* full duplex capable */ +#define GMII_1000_AUX_CTRL_HD_CAPABLE 0x0100 /* half duplex capable */ + +/* Bit definitions: 1000BaseT AUX Status */ +#define GMII_1000_AUX_STATUS_FD_CAPABLE 0x0800 /* full duplex capable */ +#define GMII_1000_AUX_STATUS_HD_CAPABLE 0x0400 /* half duplex capable */ + +/* Cicada MII Registers */ +#define GMII_AUX_CTRL_STATUS 0x1C +#define GMII_AUX_ANEG_CPLT 0x8000 +#define GMII_AUX_FDX 0x0020 +#define GMII_AUX_SPEED_1000 0x0010 +#define GMII_AUX_SPEED_100 0x0008 + +#ifndef ADVERTISE_PAUSE_CAP +#define ADVERTISE_PAUSE_CAP 0x0400 +#endif + +#ifndef MII_STAT1000 +#define MII_STAT1000 0x000A +#endif + +#ifndef LPA_1000FULL +#define LPA_1000FULL 0x0800 +#endif + +/* medium mode register */ +#define MEDIUM_GIGA_MODE 0x0001 +#define MEDIUM_FULL_DUPLEX_MODE 0x0002 +#define MEDIUM_TX_ABORT_MODE 0x0004 +#define MEDIUM_ENABLE_125MHZ 0x0008 +#define MEDIUM_ENABLE_RX_FLOWCTRL 0x0010 +#define MEDIUM_ENABLE_TX_FLOWCTRL 0x0020 +#define MEDIUM_ENABLE_JUMBO_FRAME 0x0040 +#define MEDIUM_CHECK_PAUSE_FRAME_MODE 0x0080 +#define MEDIUM_ENABLE_RECEIVE 0x0100 +#define MEDIUM_MII_100M_MODE 0x0200 +#define MEDIUM_ENABLE_JAM_PATTERN 0x0400 +#define MEDIUM_ENABLE_STOP_BACKPRESSURE 0x0800 +#define MEDIUM_ENABLE_SUPPER_MAC_SUPPORT 0x1000 + +/* PHY mode */ +#define PHY_MODE_MARVELL 0 +#define PHY_MODE_CICADA_FAMILY 1 +#define PHY_MODE_CICADA_V1 1 +#define PHY_MODE_AGERE_FAMILY 2 +#define PHY_MODE_AGERE_V0 2 +#define PHY_MODE_CICADA_V2 5 +#define PHY_MODE_AGERE_V0_GMII 6 +#define PHY_MODE_CICADA_V2_ASIX 9 +#define PHY_MODE_VSC8601 10 +#define PHY_MODE_RTL8211CL 12 +#define PHY_MODE_RTL8211BN 13 +#define PHY_MODE_RTL8251CL 14 +#define PHY_MODE_ATTANSIC_V0 0x40 +#define PHY_MODE_ATTANSIC_FAMILY 0x40 +#define PHY_MODE_MAC_TO_MAC_GMII 0x7C + +/* */ +#define LED_MODE_MARVELL 0 +#define LED_MODE_CAMEO 1 + +#define MARVELL_LED_CTRL 0x18 +#define MARVELL_MANUAL_LED 0x19 + +#define PHY_IDENTIFIER 0x0002 +#define PHY_AGERE_IDENTIFIER 0x0282 +#define PHY_CICADA_IDENTIFIER 0x000f +#define PHY_MARVELL_IDENTIFIER 0x0141 + +#define PHY_MARVELL_STATUS 0x001b +#define MARVELL_STATUS_HWCFG 0x0004 /* SGMII without clock */ + +#define PHY_MARVELL_CTRL 0x0014 +#define MARVELL_CTRL_RXDELAY 0x0080 +#define MARVELL_CTRL_TXDELAY 0x0002 + +#define PHY_CICADA_EXTPAGE 0x001f +#define CICADA_EXTPAGE_EN 0x0001 +#define CICADA_EXTPAGE_DIS 0x0000 + +/* External ethernet phy */ +#define EXTPHY_ID_MASK_OUI(phyid1, phyid2) ((phyid1 << 6) | ((phyid2 & 0xFC00) >> 10)) +#define EXTPHY_ID_MASK_MODEL(phyid2) ((phyid2 & 0x3F0) >> 4) + +#define EXTPHY_BROADCOM_OUI 0x2B8094 +#define EXTPHY_BCM89811_MODEL 0x02 + +struct {unsigned short value, offset; } CICADA_FAMILY_HWINIT[] = { + {0x0001, 0x001f}, {0x1c25, 0x0017}, {0x2a30, 0x001f}, {0x234c, 0x0010}, + {0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0xa7fa, 0x0000}, + {0x0012, 0x0002}, {0x3002, 0x0001}, {0x87fa, 0x0000}, {0x52b5, 0x001f}, + {0xafac, 0x0000}, {0x000d, 0x0002}, {0x001c, 0x0001}, {0x8fac, 0x0000}, + {0x2a30, 0x001f}, {0x0012, 0x0008}, {0x2a30, 0x001f}, {0x0400, 0x0014}, + {0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0xa760, 0x0000}, + {0x0000, 0x0002}, {0xfaff, 0x0001}, {0x8760, 0x0000}, {0x52b5, 0x001f}, + {0xa760, 0x0000}, {0x0000, 0x0002}, {0xfaff, 0x0001}, {0x8760, 0x0000}, + {0x52b5, 0x001f}, {0xafae, 0x0000}, {0x0004, 0x0002}, {0x0671, 0x0001}, + {0x8fae, 0x0000}, {0x2a30, 0x001f}, {0x0012, 0x0008}, {0x0000, 0x001f}, +}; + +struct {unsigned short value, offset; } CICADA_V2_HWINIT[] = { + {0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0x000f, 0x0002}, + {0x472a, 0x0001}, {0x8fa4, 0x0000}, {0x2a30, 0x001f}, {0x0212, 0x0008}, + {0x0000, 0x001f}, +}; + +struct {unsigned short value, offset; } CICADA_V2_ASIX_HWINIT[] = { + {0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0x0012, 0x0002}, + {0x3002, 0x0001}, {0x87fa, 0x0000}, {0x52b5, 0x001f}, {0x000f, 0x0002}, + {0x472a, 0x0001}, {0x8fa4, 0x0000}, {0x2a30, 0x001f}, {0x0212, 0x0008}, + {0x0000, 0x001f}, +}; + +struct {unsigned short value, offset; } AGERE_FAMILY_HWINIT[] = { + {0x0800, 0x0000}, {0x0007, 0x0012}, {0x8805, 0x0010}, {0xb03e, 0x0011}, + {0x8808, 0x0010}, {0xe110, 0x0011}, {0x8806, 0x0010}, {0xb03e, 0x0011}, + {0x8807, 0x0010}, {0xff00, 0x0011}, {0x880e, 0x0010}, {0xb4d3, 0x0011}, + {0x880f, 0x0010}, {0xb4d3, 0x0011}, {0x8810, 0x0010}, {0xb4d3, 0x0011}, + {0x8817, 0x0010}, {0x1c00, 0x0011}, {0x300d, 0x0010}, {0x0001, 0x0011}, + {0x0002, 0x0012}, +}; + +struct ax88178_data { + u16 EepromData; + u16 MediaLink; + int UseGpio0; + int UseRgmii; + u8 PhyMode; + u8 LedMode; + u8 BuffaloOld; +}; + +enum watchdog_state { + AX_NOP = 0, + CHK_LINK, /* Routine A */ + CHK_CABLE_EXIST, /* Called by A */ + CHK_CABLE_EXIST_AGAIN, /* Routine B */ + PHY_POWER_UP, /* Called by B */ + PHY_POWER_UP_BH, + PHY_POWER_DOWN, + CHK_CABLE_STATUS, /* Routine C */ + WAIT_AUTONEG_COMPLETE, + AX_SET_RX_CFG, + AX_CHK_AUTODETACH, +}; + +#if 0 +struct ax88772b_data { + struct usbnet *dev; + struct workqueue_struct *ax_work; + struct work_struct check_link; + unsigned long time_to_chk; + u16 psc; + u8 pw_enabled; + u8 Event; + u8 checksum; + u8 PhySelect:1; + u8 OperationMode:1; + u16 presvd_phy_advertise; + u16 presvd_phy_bmcr; + + u32 ext_phy_oui; + u8 ext_phy_model; +}; +#endif + +/* define for MAC or PHY mode */ +#define OPERATION_MAC_MODE 0 +#define OPERATION_PHY_MODE 1 + +#if 0 +struct ax88772a_data { + struct usbnet *dev; + struct workqueue_struct *ax_work; + struct work_struct check_link; + unsigned long autoneg_start; +#define AX88772B_WATCHDOG (6 * HZ) + u8 Event; + u8 TickToExpire; + u8 DlyIndex; + u8 DlySel; + u16 EepromData; + u16 presvd_phy_advertise; + u16 presvd_phy_bmcr; +}; + +struct ax88772_data { + struct usbnet *dev; + struct workqueue_struct *ax_work; + struct work_struct check_link; + unsigned long autoneg_start; + u8 Event; + u8 TickToExpire; + u16 presvd_phy_advertise; + u16 presvd_phy_bmcr; +}; +#endif + +#define AX_RX_CHECKSUM 1 +#define AX_TX_CHECKSUM 2 + +#if 0 +/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ +struct ax8817x_data { + u8 multi_filter[AX_MCAST_FILTER_SIZE]; + int (*resume) (struct usb_interface *intf); + int (*suspend) (struct usb_interface *intf, +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 10) + pm_message_t message); +#else + u32 message); +#endif +}; +#endif + +struct ax88172_int_data { + u16 res1; +#define AX_INT_PPLS_LINK (1 << 0) +#define AX_INT_SPLS_LINK (1 << 1) +#define AX_INT_CABOFF_UNPLUG (1 << 7) + u8 link; + u16 res2; + u8 status; + u16 res3; +} __attribute__ ((packed)); + +#define AX_RXHDR_L4_ERR (1 << 8) +#define AX_RXHDR_L3_ERR (1 << 9) + +#define AX_RXHDR_L4_TYPE_UDP 1 +#define AX_RXHDR_L4_TYPE_ICMP 2 +#define AX_RXHDR_L4_TYPE_IGMP 3 +#define AX_RXHDR_L4_TYPE_TCP 4 +#define AX_RXHDR_L4_TYPE_TCMPV6 5 +#define AX_RXHDR_L4_TYPE_MASK 7 + +#define AX_RXHDR_L3_TYPE_IP 1 +#define AX_RXHDR_L3_TYPE_IPV6 2 + +struct ax88772b_rx_header { +#if defined(__LITTLE_ENDIAN_BITFIELD) + u16 len:11, + res1:1, + crc:1, + mii:1, + runt:1, + mc_bc:1; + + u16 len_bar:11, + res2:5; + + u8 vlan_ind:3, + vlan_tag_striped:1, + pri:3, + res3:1; + + u8 l4_csum_err:1, + l3_csum_err:1, + l4_type:3, + l3_type:2, + ce:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + u16 mc_bc:1, + runt:1, + mii:1, + crc:1, + res1:1, + len:11; + + u16 res2:5, + len_bar:11; + + u8 res3:1, + pri:3, + vlan_tag_striped:1, + vlan_ind:3; + + u8 ce:1, + l3_type:2, + l4_type:3, + l3_csum_err:1, + l4_csum_err:1; +#else +#error "Please fix " +#endif + +} __attribute__ ((packed)); + + +#endif /* __LINUX_USBNET_ASIX_H */ + diff --git a/third-party/cherryusb-0.7.0/class/vendor/axusbnet.c b/third-party/cherryusb-0.7.0/class/vendor/axusbnet.c new file mode 100644 index 0000000000000000000000000000000000000000..2faeb6b198346a4d3880ba6f4f674c3c2204b2ea --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/vendor/axusbnet.c @@ -0,0 +1,1208 @@ +/* + * Copyright (c) 2022, aozima + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* + * Change Logs + * Date Author Notes + * 2022-04-17 aozima the first version for CherryUSB. + */ + +#include + +#include "usbh_core.h" +#include "axusbnet.h" + +static const char *DEV_FORMAT = "/dev/u%d"; + +#define USE_RTTHREAD (1) +// #define RX_DUMP +// #define TX_DUMP +// #define DUMP_RAW + +#if USE_RTTHREAD +#include + +#include +#include +#endif /* USE_RTTHREAD */ + +#define MAX_ADDR_LEN 6 +#define ETH_ALEN MAX_ADDR_LEN +#define mdelay rt_thread_delay +#define msleep rt_thread_delay +#define deverr(dev, fmt, ...) USB_LOG_ERR(fmt, ##__VA_ARGS__) +#define cpu_to_le16(a) (a) +#define le32_to_cpus(a) (a) + +/* Generic MII registers. */ +#define MII_BMCR 0x00 /* Basic mode control register */ +#define MII_BMSR 0x01 /* Basic mode status register */ +#define MII_PHYSID1 0x02 /* PHYS ID 1 */ +#define MII_PHYSID2 0x03 /* PHYS ID 2 */ +#define MII_ADVERTISE 0x04 /* Advertisement control reg */ +#define MII_LPA 0x05 /* Link partner ability reg */ +#define MII_EXPANSION 0x06 /* Expansion register */ +#define MII_CTRL1000 0x09 /* 1000BASE-T control */ +#define MII_STAT1000 0x0a /* 1000BASE-T status */ +#define MII_MMD_CTRL 0x0d /* MMD Access Control Register */ +#define MII_MMD_DATA 0x0e /* MMD Access Data Register */ +#define MII_ESTATUS 0x0f /* Extended Status */ +#define MII_DCOUNTER 0x12 /* Disconnect counter */ +#define MII_FCSCOUNTER 0x13 /* False carrier counter */ +#define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */ +#define MII_RERRCOUNTER 0x15 /* Receive error counter */ +#define MII_SREVISION 0x16 /* Silicon revision */ +#define MII_RESV1 0x17 /* Reserved... */ +#define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */ +#define MII_PHYADDR 0x19 /* PHY address */ +#define MII_RESV2 0x1a /* Reserved... */ +#define MII_TPISTATUS 0x1b /* TPI status for 10mbps */ +#define MII_NCONFIG 0x1c /* Network interface config */ + +/* Basic mode control register. */ +#define BMCR_RESV 0x003f /* Unused... */ +#define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */ +#define BMCR_CTST 0x0080 /* Collision test */ +#define BMCR_FULLDPLX 0x0100 /* Full duplex */ +#define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */ +#define BMCR_ISOLATE 0x0400 /* Isolate data paths from MII */ +#define BMCR_PDOWN 0x0800 /* Enable low power state */ +#define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */ +#define BMCR_SPEED100 0x2000 /* Select 100Mbps */ +#define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */ +#define BMCR_RESET 0x8000 /* Reset to default state */ +#define BMCR_SPEED10 0x0000 /* Select 10Mbps */ + +/* Advertisement control register. */ +#define ADVERTISE_SLCT 0x001f /* Selector bits */ +#define ADVERTISE_CSMA 0x0001 /* Only selector supported */ +#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */ +#define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */ +#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */ +#define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */ +#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */ +#define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */ +#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ +#define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */ +#define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */ +#define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */ +#define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */ +#define ADVERTISE_RESV 0x1000 /* Unused... */ +#define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */ +#define ADVERTISE_LPACK 0x4000 /* Ack link partners response */ +#define ADVERTISE_NPAGE 0x8000 /* Next page bit */ + +#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \ + ADVERTISE_CSMA) +#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \ + ADVERTISE_100HALF | ADVERTISE_100FULL) + +struct mii_if_info { + int phy_id; +}; + +struct usbnet +{ +#if USE_RTTHREAD + /* inherit from ethernet device */ + struct eth_device parent; +#endif /* USE_RTTHREAD */ + + struct usbh_axusbnet *class; + + uint8_t dev_addr[MAX_ADDR_LEN]; + + uint8_t internalphy:1; + uint8_t PhySelect:1; + uint8_t OperationMode:1; + + struct mii_if_info mii; +}; +typedef struct usbnet * usbnet_t; +static struct usbnet usbh_axusbnet_eth_device; + +#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ') +static void dump_hex(const void *ptr, uint32_t buflen) +{ + unsigned char *buf = (unsigned char*)ptr; + int i, j; + + for (i=0; itot_len); +#ifdef DUMP_RAW + const struct pbuf* q; + rt_uint32_t i,j; + rt_uint8_t *ptr; + + // rt_kprintf("%s %d byte\n", msg, p->tot_len); + + i=0; + for(q=p; q != RT_NULL; q= q->next) + { + ptr = q->payload; + + for(j=0; jlen; j++) + { + if( (i%8) == 0 ) + { + rt_kprintf(" "); + } + if( (i%16) == 0 ) + { + rt_kprintf("\r\n"); + } + rt_kprintf("%02X ", *ptr); + + i++; + ptr++; + } + } + + rt_kprintf("\n\n"); +#endif /* DUMP_RAW */ +} +#else +#define packet_dump(...) +#endif /* dump */ + +static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, + u16 size, void *data) +{ + int ret = 0; + struct usbh_hubport *hport = dev->class->hport; + struct usb_setup_packet *setup = hport->setup; + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE; + setup->bRequest = cmd; + setup->wValue = value; + setup->wIndex = index; + setup->wLength = size; + + ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)data); + if (ret != 0) { + USB_LOG_ERR("%s cmd=%d ret: %d\r\n", __FUNCTION__, cmd, ret); + return ret; + } + +_exit: + + return ret; +} + +static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, + u16 size, void *data) +{ + int ret = 0; + struct usbh_hubport *hport = dev->class->hport; + struct usb_setup_packet *setup = hport->setup; + setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE; + setup->bRequest = cmd; + setup->wValue = value; + setup->wIndex = index; + setup->wLength = size; + + ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)data); + if (ret != 0) { + USB_LOG_ERR("%s cmd=%d ret: %d\r\n", __FUNCTION__, cmd, ret); + return ret; + } + +_exit: + + return ret; +} + +static int ax8817x_mdio_read(struct usbnet *dev, int phy_id, int loc) +{ + // struct usbnet *dev = netdev_priv(netdev); + u16 res, ret; + u8 smsr; + int i = 0; + + // res = kmalloc(2, GFP_ATOMIC); + // if (!res) + // return 0; + + do { + ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL); + + msleep(1); + + // smsr = (u8 *)&ret; + ax8817x_read_cmd(dev, AX_CMD_READ_STATMNGSTS_REG, 0, 0, 1, &smsr); + } while (!(smsr & AX_HOST_EN) && (i++ < 30)); + + ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (uint16_t)loc, 2, &res); + ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, NULL); + + // ret = *res & 0xffff; + // kfree(res); + + return res; +} + +/* same as above, but converts resulting value to cpu byte order */ +static int ax8817x_mdio_read_le(struct usbnet *netdev, int phy_id, int loc) +{ + return (ax8817x_mdio_read(netdev, phy_id, loc)); +} + +static void +ax8817x_mdio_write(struct usbnet *dev, int phy_id, int loc, int val) +{ + // struct usbnet *dev = netdev_priv(netdev); + u16 res; + u8 smsr; + int i = 0; + + // res = kmalloc(2, GFP_ATOMIC); + // if (!res) + // return; + // smsr = (u8 *) res; + + do { + ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL); + + msleep(1); + + ax8817x_read_cmd(dev, AX_CMD_READ_STATMNGSTS_REG, 0, 0, 1, &smsr); + } while (!(smsr & AX_HOST_EN) && (i++ < 30)); + + // *res = val; + res = val; + + ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (uint16_t)loc, 2, &res); + ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, NULL); + + // kfree(res); +} + +static void +ax88772b_mdio_write(struct usbnet *dev, int phy_id, int loc, int val) +{ + // struct usbnet *dev = netdev_priv(netdev); + u16 res = val; + + // res = kmalloc(2, GFP_ATOMIC); + // if (!res) + // return; + // *res = val; + + ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL); + ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (uint16_t)loc, 2, &res); + + if (loc == MII_ADVERTISE) { + res = cpu_to_le16(BMCR_ANENABLE | BMCR_ANRESTART); + ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (uint16_t)MII_BMCR, 2, &res); + } + + ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, NULL); + + // kfree(res); +} + +/* same as above, but converts new value to le16 byte order before writing */ +static void +ax8817x_mdio_write_le(struct usbnet *netdev, int phy_id, int loc, int val) +{ + ax8817x_mdio_write(netdev, phy_id, loc, cpu_to_le16(val)); +} + +static int access_eeprom_mac(struct usbnet *dev, u8 *buf, u8 offset, bool wflag) +{ + int ret = 0, i; + u16 *tmp = (u16 *)buf; + + if (wflag) { + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_EEPROM_EN, + 0, 0, 0, NULL); + if (ret < 0) + return ret; + + mdelay(15); + } + + for (i = 0; i < (ETH_ALEN >> 1); i++) { + if (wflag) { + // u16 wd = cpu_to_le16(*(tmp + i)); + u16 wd = (*(tmp + i)); + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_EEPROM, offset + i, + wd, 0, NULL); + if (ret < 0) + break; + + mdelay(15); + } else { + ret = ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, + offset + i, 0, 2, tmp + i); + if (ret < 0) + break; + } + } + + if (!wflag) { + if (ret < 0) { +// #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) +// netdev_dbg(dev->net, "Failed to read MAC address from EEPROM: %d\n", ret); +// #else +// devdbg(dev, "Failed to read MAC address from EEPROM: %d\n", ret); +// #endif + USB_LOG_ERR("Failed to read MAC address from EEPROM: %d\n", ret); + return ret; + } + // memcpy(dev->net->dev_addr, buf, ETH_ALEN); + } else { + ax8817x_write_cmd(dev, AX_CMD_WRITE_EEPROM_DIS, + 0, 0, 0, NULL); + if (ret < 0) + return ret; + + /* reload eeprom data */ + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, + AXGPIOS_RSE, 0, 0, NULL); + if (ret < 0) + return ret; + } + + return 0; +} + +static int ax88772a_phy_powerup(struct usbnet *dev) +{ + int ret; + /* set the embedded Ethernet PHY in power-down state */ + ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, + AX_SWRESET_IPPD | AX_SWRESET_IPRL, 0, 0, NULL); + if (ret < 0) { + deverr(dev, "Failed to power down PHY: %d", ret); + return ret; + } + + msleep(10); + + /* set the embedded Ethernet PHY in power-up state */ + ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL, + 0, 0, NULL); + if (ret < 0) { + deverr(dev, "Failed to reset PHY: %d", ret); + return ret; + } + + msleep(600); + + /* set the embedded Ethernet PHY in reset state */ + ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, + 0, 0, NULL); + if (ret < 0) { + deverr(dev, "Failed to power up PHY: %d", ret); + return ret; + } + + /* set the embedded Ethernet PHY in power-up state */ + ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL, + 0, 0, NULL); + if (ret < 0) { + deverr(dev, "Failed to reset PHY: %d", ret); + return ret; + } + + return 0; +} + +static int ax88772b_reset(struct usbnet *dev) +{ + int ret; + + ret = ax88772a_phy_powerup(dev); + if (ret < 0) + return ret; + + /* Set the MAC address */ + ret = ax8817x_write_cmd(dev, AX88772_CMD_WRITE_NODE_ID, + 0, 0, ETH_ALEN, dev->dev_addr); + if (ret < 0) { + deverr(dev, "set MAC address failed: %d", ret); + } + + /* stop MAC operation */ + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, AX_RX_CTL_STOP, + 0, 0, NULL); + if (ret < 0){ + deverr(dev, "Reset RX_CTL failed: %d", ret); + } + + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, + AX88772_MEDIUM_DEFAULT, 0, 0, + NULL); + if (ret < 0){ + deverr(dev, "Write medium mode register: %d", ret); + } + + return ret; +} + +static int ax8817x_get_mac(struct usbnet *dev, u8 *buf) +{ + int ret, i; + + ret = access_eeprom_mac(dev, buf, 0x04, 0); + if (ret < 0) + goto out; + + // if (ax8817x_check_ether_addr(dev)) { + // ret = access_eeprom_mac(dev, dev->net->dev_addr, 0x04, 1); + // if (ret < 0) { + // deverr(dev, "Failed to write MAC to EEPROM: %d", ret); + // goto out; + // } + + // msleep(5); + + // ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, + // 0, 0, ETH_ALEN, buf); + // if (ret < 0) { + // deverr(dev, "Failed to read MAC address: %d", ret); + // goto out; + // } + + // for (i = 0; i < ETH_ALEN; i++) + // if (*(dev->net->dev_addr + i) != *((u8 *)buf + i)) { + // devwarn(dev, "Found invalid EEPROM part or non-EEPROM"); + // break; + // } + // } + + // memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); + + // /* Set the MAC address */ + // ax8817x_write_cmd(dev, AX88772_CMD_WRITE_NODE_ID, 0, 0, + // ETH_ALEN, dev->net->dev_addr); + + // if (ret < 0) { + // deverr(dev, "Failed to write MAC address: %d", ret); + // goto out; + // } + + return 0; +out: + return ret; +} + +#if USE_RTTHREAD +static rt_err_t rt_rndis_eth_init(rt_device_t dev) +{ + return RT_EOK; +} + +static rt_err_t rt_rndis_eth_open(rt_device_t dev, rt_uint16_t oflag) +{ + return RT_EOK; +} + +static rt_err_t rt_rndis_eth_close(rt_device_t dev) +{ + return RT_EOK; +} + +static rt_size_t rt_rndis_eth_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) +{ + rt_set_errno(-RT_ENOSYS); + return 0; +} + +static rt_size_t rt_rndis_eth_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) +{ + rt_set_errno(-RT_ENOSYS); + return 0; +} +static rt_err_t rt_rndis_eth_control(rt_device_t dev, int cmd, void *args) +{ + usbnet_t rndis_eth_dev = (usbnet_t)dev; + + USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__); + switch(cmd) + { + case NIOCTL_GADDR: + /* get mac address */ + if(args) + { + USB_LOG_INFO("%s L%d NIOCTL_GADDR\r\n", __FUNCTION__, __LINE__); + rt_memcpy(args, rndis_eth_dev->dev_addr, MAX_ADDR_LEN); + } + else + { + return -RT_ERROR; + } + break; + default : + break; + } + + return RT_EOK; +} + +/* reception packet. */ +static struct pbuf *rt_rndis_eth_rx(rt_device_t dev) +{ + struct pbuf* p = RT_NULL; + + // USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__); + + return p; +} + +/* transmit packet. */ +static rt_err_t rt_rndis_eth_tx(rt_device_t dev, struct pbuf* p) +{ + int ret = 0; + rt_err_t result = RT_EOK; + uint8_t *tmp_buf = RT_NULL; + usbnet_t rndis_eth = (usbnet_t)dev; + struct usbh_axusbnet *class = rndis_eth->class; + rt_tick_t tick_start, tick_end; + uint8_t int_notify_buf[8]; + +#ifdef TX_DUMP + packet_dump("TX", p); +#endif /* TX_DUMP */ + + tmp_buf = (uint8_t *)rt_malloc(16 + p->tot_len ); + if (!tmp_buf) { + USB_LOG_INFO("[%s L%d], no memory for pbuf, len=%d.", __FUNCTION__, __LINE__, p->tot_len); + goto _exit; + } + + uint32_t slen = p->tot_len; + + uint32_t head = slen; + head = ((head ^ 0x0000ffff) << 16) + (head); + + tmp_buf[0] = head & 0xFF; + tmp_buf[1] = (head >> 8) & 0xFF; + tmp_buf[2] = (head >> 16) & 0xFF; + tmp_buf[3] = (head >> 24) & 0xFF; + slen += 4; + + int padlen = ((p->tot_len + 4) % 512) ? 0 : 4; + if (padlen) { + tmp_buf[4 + slen + 0] = 0x00; + tmp_buf[4 + slen + 1] = 0x00; + tmp_buf[4 + slen + 2] = 0xFF; + tmp_buf[4 + slen + 3] = 0xFF; + slen += 4; + } + + pbuf_copy_partial(p, tmp_buf + 4, p->tot_len, 0); + + tick_start = rt_tick_get(); + ret = usbh_ep_bulk_transfer(class->bulkout, tmp_buf, slen, 500); + if (ret < 0) { + result = -RT_EIO; + USB_LOG_ERR("%s L%d send over ret:%d\r\n", __FUNCTION__, __LINE__, ret); + goto _exit; + } + tick_end = rt_tick_get(); + +_exit: + if(tmp_buf) + { + rt_free(tmp_buf); + } + + return result; +} + +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops rndis_device_ops = +{ + rt_rndis_eth_init, + rt_rndis_eth_open, + rt_rndis_eth_close, + rt_rndis_eth_read, + rt_rndis_eth_write, + rt_rndis_eth_control +} +#endif /* RT_USING_DEVICE_OPS */ +#endif /* USE_RTTHREAD */ + +static void rt_thread_axusbnet_entry(void *parameter) +{ + int ret; + struct usbh_hubport *hport; + uint8_t intf; + uint8_t buf[2+8]; + + USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__); + rt_thread_delay(200); + USB_LOG_INFO("%s L%d\r\n\r\n\r\n\r\n", __FUNCTION__, __LINE__); + + const char *dname = "/dev/u0"; + struct usbh_axusbnet *class = (struct usbh_axusbnet *)usbh_find_class_instance(dname); + if (class == NULL) { + USB_LOG_ERR("do not find %s\r\n", dname); + return; + } + USB_LOG_INFO("axusbnet=%p\r\n", dname); + + usbh_axusbnet_eth_device.class = class; + + struct usbnet *dev = &usbh_axusbnet_eth_device; + + ret = ax8817x_read_cmd(dev, AX_CMD_SW_PHY_STATUS, + 0, 0, 1, buf); + if (ret < 0) { + USB_LOG_ERR("AX_CMD_SW_PHY_STATUS ret=%d\r\n", ret); + return; + } + u8 tempphyselect = buf[0]; + if (tempphyselect == AX_PHYSEL_SSRMII) { + USB_LOG_ERR("%s L%d AX_PHYSEL_SSRMII\r\n", __FUNCTION__, __LINE__); + dev->internalphy = false; + return; + // dev->OperationMode = OPERATION_MAC_MODE; + // dev->PhySelect = 0x00; + } else if (tempphyselect == AX_PHYSEL_SSRRMII) { + USB_LOG_ERR("%s L%d AX_PHYSEL_SSRRMII\r\n", __FUNCTION__, __LINE__); + dev->internalphy = true; + return; + // dev->OperationMode = OPERATION_PHY_MODE; + // dev->PhySelect = 0x00; + } else if (tempphyselect == AX_PHYSEL_SSMII) { + USB_LOG_INFO("%s L%d internalphy AX_PHYSEL_SSMII & OPERATION_MAC_MODE\r\n", __FUNCTION__, __LINE__); + dev->internalphy = true; + dev->OperationMode = OPERATION_MAC_MODE; + dev->PhySelect = 0x01; + } else { + // deverr(dev, "Unknown MII type\n"); + USB_LOG_INFO("%s L%d Unknown MII type\r\n", __FUNCTION__, __LINE__); + return; + } + + /* reload eeprom data */ + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, AXGPIOS_RSE, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("reload eeprom data ret=%d\r\n", ret); + return; + } + + /* Get the EEPROM data: power saving configuration*/ + ret = ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, 0x18, 0, 2, buf); + if (ret < 0) { + USB_LOG_ERR("read SROM address 18h failed: %d\r\n", ret); + goto err_out; + } + USB_LOG_INFO("reading AX88772C psc: %02x %02x\r\n", buf[0], buf[1]); + // le16_to_cpus(tmp16); + // ax772b_data->psc = *tmp16 & 0xFF00; + /* End of get EEPROM data */ + + ret = ax8817x_get_mac(dev, buf); + if (ret < 0) { + USB_LOG_ERR("Get HW address failed: %d\r\n", ret); + return; + } + dump_hex(buf, ETH_ALEN); + memcpy(dev->dev_addr, buf, ETH_ALEN); + + uint16_t chipcode = 0xFFFF; + { + uint16_t smsr; + // asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1, &chipcode, 0); + ax8817x_read_cmd(dev, AX_CMD_READ_STATMNGSTS_REG, 0, 0, 1, &chipcode); + USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG ret: %d %04X\r\n", ret, chipcode); + +// #define AX_CHIPCODE_MASK 0x70 +// #define AX_AX88772_CHIPCODE 0x00 +// #define AX_AX88772A_CHIPCODE 0x10 +// #define AX_AX88772B_CHIPCODE 0x20 +// #define AX_HOST_EN 0x01 + + chipcode &= 0x70;//AX_CHIPCODE_MASK; AX_AX88772_CHIPCODE + if(chipcode == 0x00) + { + USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG AX_AX88772_CHIPCODE\r\n"); + } + else if(chipcode == 0x10) + { + USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG AX_AX88772A_CHIPCODE\r\n"); + } + else if(chipcode == 0x20) + { + USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG AX_AX88772B_CHIPCODE\r\n"); + } + } + + /* Get the PHY id: E0 10 */ + ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf); + if (ret < 0) { + USB_LOG_ERR("Error reading PHY ID: %02x\r\n", ret); + return; + } + if (dev->internalphy) { + dev->mii.phy_id = *((u8 *)buf + 1); + } else { + dev->mii.phy_id = *((u8 *)buf); + } + USB_LOG_INFO("reading %s PHY ID: %02x\r\n", dev->internalphy?"internal":"external", dev->mii.phy_id); + + ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, dev->PhySelect, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Select PHY #1 failed: %d", ret); + return; + } + + ret = ax88772a_phy_powerup(dev); + if (ret < 0) { + USB_LOG_ERR("ax88772a_phy_powerup failed: %d", ret); + return; + } + + /* stop MAC operation */ + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, + AX_RX_CTL_STOP, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Reset RX_CTL failed: %d", ret); + goto err_out; + } + + /* make sure the driver can enable sw mii operation */ + ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Enabling software MII failed: %d\r\n", ret); + goto err_out; + } + + if ((dev->OperationMode == OPERATION_MAC_MODE) && + (dev->PhySelect == 0x00)) { + USB_LOG_ERR("not support the external phy\r\n"); + goto err_out; + } + + if (dev->OperationMode == OPERATION_PHY_MODE) { + ax8817x_mdio_write_le(dev, dev->mii.phy_id, MII_BMCR, 0x3900); + } + + if (dev->mii.phy_id != 0x10) + { + USB_LOG_ERR("not support phy_id != 0x10\r\n"); + // ax8817x_mdio_write_le(dev->net, 0x10, MII_BMCR, 0x3900); + } + + if (dev->mii.phy_id == 0x10 && dev->OperationMode != OPERATION_PHY_MODE) { + u16 tmp16 = ax8817x_mdio_read_le(dev, dev->mii.phy_id, 0x12); + ax8817x_mdio_write_le(dev, dev->mii.phy_id, 0x12, ((tmp16 & 0xFF9F) | 0x0040)); + } + + ax8817x_mdio_write_le(dev, dev->mii.phy_id, MII_ADVERTISE, + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); + + // mii_nway_restart(&dev->mii); + { + /* if autoneg is off, it's an error */ + uint16_t bmcr = ax8817x_mdio_read_le(dev, dev->mii.phy_id, MII_BMCR); + if (bmcr & BMCR_ANENABLE) { + bmcr |= BMCR_ANRESTART; + USB_LOG_ERR("BMCR_ANENABLE ==> BMCR_ANRESTART\r\n"); + ax8817x_mdio_write_le(dev, dev->mii.phy_id, MII_BMCR, bmcr); + } else + { + USB_LOG_ERR("not BMCR_ANENABLE BMCR=%04X\r\n", bmcr); + } + } + + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, 0, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Failed to write medium mode: %d", ret); + goto err_out; + } + + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, + AX88772A_IPG0_DEFAULT | AX88772A_IPG1_DEFAULT << 8, + AX88772A_IPG2_DEFAULT, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Failed to write interframe gap: %d", ret); + goto err_out; + } + + memset(buf, 0, 4); + ret = ax8817x_read_cmd(dev, AX_CMD_READ_IPG012, 0, 0, 3, buf); + *((u8 *)buf + 3) = 0x00; + if (ret < 0) { + USB_LOG_ERR("Failed to read IPG,IPG1,IPG2 failed: %d", ret); + goto err_out; + } else { + uint32_t tmp32 = *((u32*)buf); + le32_to_cpus(&tmp32); + if (tmp32 != (AX88772A_IPG2_DEFAULT << 16 | + AX88772A_IPG1_DEFAULT << 8 | AX88772A_IPG0_DEFAULT)) { + USB_LOG_ERR("Non-authentic ASIX product\nASIX does not support it\n"); + // ret = -ENODEV; + goto err_out; + } + } + + // TODO: optimized for high speed. + ret = ax8817x_write_cmd(dev, 0x2A, 0x8000, 0x8001, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Reset RX_CTL failed: %d", ret); + goto err_out; + } + + ret = ax88772b_reset(dev); + if (ret < 0) { + USB_LOG_ERR("ax88772b_reset failed: %d", ret); + goto err_out; + } + + // OUT 29 0 0 0 AX_CMD_WRITE_MONITOR_MODE + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, 0, 0, 0, NULL); + if (ret < 0) { + deverr(dev, "AX_CMD_WRITE_MONITOR_MODE failed: %d", ret); + } + + /* Set the MAC address */ + ret = ax8817x_write_cmd(dev, AX88772_CMD_WRITE_NODE_ID, + 0, 0, ETH_ALEN, dev->dev_addr); + if (ret < 0) { + deverr(dev, "set MAC address failed: %d", ret); + } + + // update Multicast AX_CMD_WRITE_MULTI_FILTER. + const uint8_t multi_filter[] = {0x00, 0x00, 0x20, 0x80, 0x00, 0x00, 0x00, 0x40}; + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, AX_MCAST_FILTER_SIZE, (void *)multi_filter); + if (ret < 0) { + USB_LOG_ERR("Reset RX_CTL failed: %d", ret); + goto err_out; + } + + /* Configure RX header type */ + // u16 rx_reg = (AX_RX_CTL_PRO | AX_RX_CTL_AMALL | AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_HEADER_DEFAULT); + u16 rx_reg = (AX_RX_CTL_AB | AX_RX_CTL_AM | AX_RX_CTL_START); + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, rx_reg, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("Reset RX_CTL failed: %d", ret); + goto err_out; + } + + /* set the embedded Ethernet PHY in power-up state */ + // ax772b_data->psc = *tmp16 & 0xFF00; + // psc: 15 5a AX88772C psc: %02x %02x\r\n", buf[0], buf[1]); + ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | (0x5a00 & 0x7FFF), + 0, 0, NULL); + if (ret < 0) { + deverr(dev, "Failed to reset PHY: %d", ret); + // return ret; + } + + rt_thread_delay(1000); + u16 mode = AX88772_MEDIUM_DEFAULT; + ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); + if (ret < 0) { + USB_LOG_ERR("AX_CMD_WRITE_MEDIUM_MODE failed: %d", ret); + goto err_out; + } + +#if USE_RTTHREAD +#ifdef RT_USING_DEVICE_OPS + usbh_axusbnet_eth_device.parent.parent.ops = &rndis_device_ops; +#else + usbh_axusbnet_eth_device.parent.parent.init = rt_rndis_eth_init; + usbh_axusbnet_eth_device.parent.parent.open = rt_rndis_eth_open; + usbh_axusbnet_eth_device.parent.parent.close = rt_rndis_eth_close; + usbh_axusbnet_eth_device.parent.parent.read = rt_rndis_eth_read; + usbh_axusbnet_eth_device.parent.parent.write = rt_rndis_eth_write; + usbh_axusbnet_eth_device.parent.parent.control = rt_rndis_eth_control; +#endif + usbh_axusbnet_eth_device.parent.parent.user_data = RT_NULL; + + usbh_axusbnet_eth_device.parent.eth_rx = rt_rndis_eth_rx; + usbh_axusbnet_eth_device.parent.eth_tx = rt_rndis_eth_tx; + + usbh_axusbnet_eth_device.class = class; + + eth_device_init(&usbh_axusbnet_eth_device.parent, "u0"); + eth_device_linkchange(&usbh_axusbnet_eth_device.parent, RT_FALSE); +#endif /* USE_RTTHREAD */ + // check link status. + { + u16 bmcr = ax8817x_mdio_read_le(dev, dev->mii.phy_id, MII_BMCR); + u16 mode = AX88772_MEDIUM_DEFAULT; + + USB_LOG_ERR("%s L%d MII_BMCR=%04X\r\n", __FUNCTION__, __LINE__, bmcr); + if (!(bmcr & BMCR_FULLDPLX)) + { + mode &= ~AX88772_MEDIUM_FULL_DUPLEX; + USB_LOG_ERR("%s L%d not AX88772_MEDIUM_FULL_DUPLEX\r\n", __FUNCTION__, __LINE__); + } + if (!(bmcr & BMCR_SPEED100)) + { + mode &= ~AX88772_MEDIUM_100MB; + USB_LOG_ERR("%s L%d not AX88772_MEDIUM_100MB\r\n", __FUNCTION__, __LINE__); + } + ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); + } + + while (1) + { + // USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__); + + ret = usbh_ep_bulk_transfer(class->bulkin, class->bulkin_buf, sizeof(class->bulkin_buf), 1000); + if (ret < 0) { + if (ret != -2) { + USB_LOG_ERR("%s L%d bulk in error ret=%d\r\n", __FUNCTION__, __LINE__, ret); + } + continue; + } + + { + const uint8_t *data = class->bulkin_buf; + uint16_t len1, len2; + + len1 = data[0] | ((uint16_t)(data[1])<<8); + len2 = data[2] | ((uint16_t)(data[3])<<8); + + // USB_LOG_INFO("transfer bulkin len1:%04X, len2:%04X, len2':%04X.\r\n", len1, len2, ~len2); + + len1 &= 0x07ff; + + if (data[0] != ((uint8_t)(~data[2]))) { + USB_LOG_ERR("transfer bulkin len1:%04X, len2:%04X, len2':%04X.\r\n", len1, len2, ~len2); + + dump_hex(data, 32); + continue; + } + +#if !USE_RTTHREAD + { + static uint32_t count = 0; + USB_LOG_INFO("recv: #%d, len=%d\r\n", count, ret); + dump_hex(data+4, 32); + + if ((count % 10) == 0) { + // 192.168.89.14 ==> 255.255.255.255:7 echo hello world! + const uint8_t packet_bytes[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x36, 0xb0, 0xfd, 0x00, 0x00, 0x80, 0x11, + 0x00, 0x00, 0xc0, 0xa8, 0x59, 0x0e, 0xff, 0xff, + 0xff, 0xff, 0x00, 0x07, 0x00, 0x07, 0x00, 0x22, + 0x53, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, + 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x66, 0x72, + 0x6f, 0x6d, 0x20, 0x41, 0x58, 0x38, 0x38, 0x37, + 0x37, 0x32, 0x43, 0x2e + }; + + uint8_t *send_buf = (uint8_t *)class->bulkin_buf; + send_buf[0] = sizeof(packet_bytes); + send_buf[1] = sizeof(packet_bytes) >> 8; + send_buf[2] = ~send_buf[0]; + send_buf[3] = ~send_buf[1]; + memcpy(send_buf+4, packet_bytes, sizeof(packet_bytes)); + memcpy(send_buf+4+6, dev->dev_addr, 6);// update src mac. + + ret = usbh_ep_bulk_transfer(class->bulkout, send_buf, 4 + sizeof(packet_bytes), 500); + USB_LOG_INFO("bulkout, ret=%d\r\n", ret); + dump_hex(send_buf, 64); + } + + count++; + } +#endif /* RT-Thread */ + +#if USE_RTTHREAD + { + static uint32_t count = 0; + + if (count == 0) { + eth_device_linkchange(&usbh_axusbnet_eth_device.parent, RT_TRUE); + } + + count++; + } + + /* allocate buffer */ + struct pbuf *p = RT_NULL; + p = pbuf_alloc(PBUF_LINK, len1, PBUF_RAM); + if (p != NULL) { + pbuf_take(p, data + 4, len1); + +#ifdef RX_DUMP + packet_dump("RX", p); +#endif /* RX_DUMP */ + struct eth_device *eth_dev = &usbh_axusbnet_eth_device.parent; + if ((eth_dev->netif->input(p, eth_dev->netif)) != ERR_OK) { + USB_LOG_INFO("F:%s L:%d IP input error\r\n", __FUNCTION__, __LINE__); + pbuf_free(p); + p = RT_NULL; + } + // USB_LOG_INFO("%s L%d input OK\r\n", __FUNCTION__, __LINE__); + } else { + USB_LOG_ERR("%s L%d pbuf_alloc NULL\r\n", __FUNCTION__, __LINE__); + } +#endif /* RT-Thread */ + } + } // while (1) + +err_out: +out2: + + return; +} + +static int axusbnet_startup(void) +{ + const char *tname = "axusbnet"; + usb_osal_thread_t usb_thread; + + usb_thread = usb_osal_thread_create(tname, 1024 * 6, CONFIG_USBHOST_PSC_PRIO, rt_thread_axusbnet_entry, NULL); + if (usb_thread == NULL) { + return -1; + } + + return 0; +} + +static int usbh_axusbnet_connect(struct usbh_hubport *hport, uint8_t intf) +{ + int ret = 0; + struct usbh_endpoint_cfg ep_cfg = { 0 }; + struct usb_endpoint_descriptor *ep_desc; + + USB_LOG_INFO("%s %d\r\n", __FUNCTION__, __LINE__); + + struct usbh_axusbnet *class = usb_malloc(sizeof(struct usbh_axusbnet)); + if (class == NULL) + { + USB_LOG_ERR("Fail to alloc class\r\n"); + return -ENOMEM; + } + memset(class, 0, sizeof(struct usbh_axusbnet)); + class->hport = hport; + + class->intf = intf; + + snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, intf); + USB_LOG_INFO("Register axusbnet Class:%s\r\n", hport->config.intf[intf].devname); + hport->config.intf[intf].priv = class; + +#if 1 + USB_LOG_INFO("hport=%p, intf=%d, intf_desc.bNumEndpoints:%d\r\n", hport, intf, hport->config.intf[intf].intf_desc.bNumEndpoints); + for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) + { + ep_desc = &hport->config.intf[intf].ep[i].ep_desc; + + USB_LOG_INFO("ep[%d] bLength=%d, type=%d\r\n", i, ep_desc->bLength, ep_desc->bDescriptorType); + USB_LOG_INFO("ep_addr=%02X, attr=%02X\r\n", ep_desc->bEndpointAddress, ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK); + USB_LOG_INFO("wMaxPacketSize=%d, bInterval=%d\r\n\r\n", ep_desc->wMaxPacketSize, ep_desc->bInterval); + } +#endif + + for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) + { + ep_desc = &hport->config.intf[intf].ep[i].ep_desc; + + ep_cfg.ep_addr = ep_desc->bEndpointAddress; + ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; + ep_cfg.ep_mps = ep_desc->wMaxPacketSize; + ep_cfg.ep_interval = ep_desc->bInterval; + ep_cfg.hport = hport; + + if(ep_cfg.ep_type == USB_ENDPOINT_TYPE_BULK) + { + if (ep_desc->bEndpointAddress & 0x80) { + usbh_pipe_alloc(&class->bulkin, &ep_cfg); + } else { + usbh_pipe_alloc(&class->bulkout, &ep_cfg); + } + } + else + { + usbh_pipe_alloc(&class->int_notify, &ep_cfg); + } + } + + axusbnet_startup(); + + return ret; +} + +static int usbh_axusbnet_disconnect(struct usbh_hubport *hport, uint8_t intf) +{ + int ret = 0; + + USB_LOG_ERR("TBD: %s %d\r\n", __FUNCTION__, __LINE__); + return ret; +} + +// Class:0xff,Subclass:0xff,Protocl:0x00 +static const struct usbh_class_driver axusbnet_class_driver = { + .driver_name = "axusbnet", + .connect = usbh_axusbnet_connect, + .disconnect = usbh_axusbnet_disconnect +}; + +CLASS_INFO_DEFINE const struct usbh_class_info axusbnet_class_info = { + .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL, + .class = USB_DEVICE_CLASS_VEND_SPECIFIC, + .subclass = 0xff, + .protocol = 0x00, + .vid = 0x0b95, + .pid = 0x772b, + .class_driver = &axusbnet_class_driver +}; diff --git a/third-party/cherryusb-0.7.0/class/vendor/axusbnet.h b/third-party/cherryusb-0.7.0/class/vendor/axusbnet.h new file mode 100644 index 0000000000000000000000000000000000000000..75badc45f1c854e198454972e9aa2545097cf8fc --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/vendor/axusbnet.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, aozima + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* + * Change Logs + * Date Author Notes + * 2022-04-17 aozima the first version for CherryUSB. + */ + +#ifndef __USB_CLASHH_AXUSBNET_H__ +#define __USB_CLASHH_AXUSBNET_H__ + +#include "usbh_core.h" +#include "asix.h" + +struct usbh_axusbnet { + struct usbh_hubport *hport; + + uint8_t intf; /* interface number */ + + usbh_pipe_t int_notify; /* Notify endpoint */ + usbh_pipe_t bulkin; /* Bulk IN endpoint */ + usbh_pipe_t bulkout; /* Bulk OUT endpoint */ + + uint32_t bulkin_buf[2048/sizeof(uint32_t)]; +}; + +#endif /* __USB_CLASHH_AXUSBNET_H__ */ diff --git a/third-party/cherryusb-0.7.0/class/vendor/usbh_air724.c b/third-party/cherryusb-0.7.0/class/vendor/usbh_air724.c new file mode 100644 index 0000000000000000000000000000000000000000..72ffcab345d11d8366ece3445870e8bda308e859 --- /dev/null +++ b/third-party/cherryusb-0.7.0/class/vendor/usbh_air724.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "usbh_core.h" + +#define DEV_FORMAT "/dev/air724" + +static uint32_t g_devinuse = 0; + +struct usbh_cdc_custom_air724 { + struct usbh_hubport *hport; + + usbh_pipe_t bulkin; /* Bulk IN endpoint */ + usbh_pipe_t bulkout; /* Bulk OUT endpoint */ +}; + +int usbh_air724_connect(struct usbh_hubport *hport, uint8_t intf) +{ + struct usbh_endpoint_cfg ep_cfg = { 0 }; + struct usb_endpoint_descriptor *ep_desc; + int ret; + + if (intf != 3) { + USB_LOG_WRN("ignore intf:%d\r\n", intf); + return 0; + } + struct usbh_cdc_custom_air724 *cdc_custom_class = usb_malloc(sizeof(struct usbh_cdc_custom_air724)); + if (cdc_custom_class == NULL) { + USB_LOG_ERR("Fail to alloc cdc_custom_class\r\n"); + return -ENOMEM; + } + + memset(cdc_custom_class, 0, sizeof(struct usbh_cdc_custom_air724)); + cdc_custom_class->hport = hport; + + strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN); + + hport->config.intf[intf].priv = cdc_custom_class; + + for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc; + + if (ep_desc->bEndpointAddress & 0x80) { + usbh_hport_activate_epx(&cdc_custom_class->bulkin, hport, ep_desc); + } else { + usbh_hport_activate_epx(&cdc_custom_class->bulkout, hport, ep_desc); + } + } + + USB_LOG_INFO("Register air724 Class:%s\r\n", hport->config.intf[intf].devname); +// uint8_t cdc_buffer[32] = {0X41,0X54,0x0d,0x0a}; +// ret = usbh_ep_bulk_transfer(cdc_custom_class->bulkout, cdc_buffer, 4, 3000); +// if (ret < 0) { +// USB_LOG_ERR("bulk out error,ret:%d\r\n", ret); +// } else { +// USB_LOG_RAW("send over:%d\r\n", ret); +// } +// ret = usbh_ep_bulk_transfer(cdc_custom_class->bulkin, cdc_buffer, 10, 3000); +// if (ret < 0) { +// USB_LOG_ERR("bulk in error,ret:%d\r\n", ret); +// } else { +// USB_LOG_RAW("recv over:%d\r\n", ret); +// for (size_t i = 0; i < ret; i++) { +// USB_LOG_RAW("0x%02x ", cdc_buffer[i]); +// } +// } + + return ret; +} + +int usbh_air724_disconnect(struct usbh_hubport *hport, uint8_t intf) +{ + return 0; +} + +const struct usbh_class_driver cdc_custom_class_driver = { + .driver_name = "cdc_acm", + .connect = usbh_air724_connect, + .disconnect = usbh_air724_disconnect +}; + +CLASS_INFO_DEFINE const struct usbh_class_info cdc_custom_class_info = { + .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL, + .class = 0xff, + .subclass = 0, + .protocol = 0, + .vid = 0x1782, + .pid = 0x4e00, + .class_driver = &cdc_custom_class_driver +}; diff --git a/third-party/cherryusb-0.6.0/class/video/usb_video.h b/third-party/cherryusb-0.7.0/class/video/usb_video.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/video/usb_video.h rename to third-party/cherryusb-0.7.0/class/video/usb_video.h diff --git a/third-party/cherryusb-0.6.0/class/video/usbd_video.c b/third-party/cherryusb-0.7.0/class/video/usbd_video.c similarity index 99% rename from third-party/cherryusb-0.6.0/class/video/usbd_video.c rename to third-party/cherryusb-0.7.0/class/video/usbd_video.c index fbb2beec35ba91e95daaf8d2f6cc9ca138c205a2..be27bba56be1d32df7a72bfed03cc70f62db0039 100644 --- a/third-party/cherryusb-0.6.0/class/video/usbd_video.c +++ b/third-party/cherryusb-0.7.0/class/video/usbd_video.c @@ -742,14 +742,11 @@ void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_ usbd_video_cfg.commit.bMaxVersion = 0; } -struct usbd_interface *usbd_video_alloc_intf(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize) +struct usbd_interface *usbd_video_init_intf(struct usbd_interface *intf, + uint32_t dwFrameInterval, + uint32_t dwMaxVideoFrameSize, + uint32_t dwMaxPayloadTransferSize) { - struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - intf->class_interface_handler = video_class_interface_request_handler; intf->class_endpoint_handler = NULL; intf->vendor_handler = NULL; @@ -780,7 +777,7 @@ uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8 picture_pos += usbd_video_cfg.probe.dwMaxPayloadTransferSize - 2; } } - uvc_header[1] ^=1; + uvc_header[1] ^= 1; *out_len = (input_len + 2 * packets); return packets; } \ No newline at end of file diff --git a/third-party/cherryusb-0.6.0/class/video/usbd_video.h b/third-party/cherryusb-0.7.0/class/video/usbd_video.h similarity index 56% rename from third-party/cherryusb-0.6.0/class/video/usbd_video.h rename to third-party/cherryusb-0.7.0/class/video/usbd_video.h index cbb54d715b2be88cf24795cd2d883439e06d0086..75d7f9ed9adec4a03c5b5367b007f792d8657d73 100644 --- a/third-party/cherryusb-0.6.0/class/video/usbd_video.h +++ b/third-party/cherryusb-0.7.0/class/video/usbd_video.h @@ -12,10 +12,11 @@ extern "C" { #endif -/* Alloc video interface driver */ -struct usbd_interface *usbd_video_alloc_intf(uint32_t dwFrameInterval, - uint32_t dwMaxVideoFrameSize, - uint32_t dwMaxPayloadTransferSize); +/* Init video interface driver */ +struct usbd_interface *usbd_video_init_intf(struct usbd_interface *intf, + uint32_t dwFrameInterval, + uint32_t dwMaxVideoFrameSize, + uint32_t dwMaxPayloadTransferSize); void usbd_video_open(uint8_t intf); void usbd_video_close(uint8_t intf); diff --git a/third-party/cherryusb-0.6.0/class/video/usbh_video.c b/third-party/cherryusb-0.7.0/class/video/usbh_video.c similarity index 100% rename from third-party/cherryusb-0.6.0/class/video/usbh_video.c rename to third-party/cherryusb-0.7.0/class/video/usbh_video.c diff --git a/third-party/cherryusb-0.6.0/class/video/usbh_video.h b/third-party/cherryusb-0.7.0/class/video/usbh_video.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/video/usbh_video.h rename to third-party/cherryusb-0.7.0/class/video/usbh_video.h diff --git a/third-party/cherryusb-0.6.0/class/wireless/ndis.h b/third-party/cherryusb-0.7.0/class/wireless/ndis.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/wireless/ndis.h rename to third-party/cherryusb-0.7.0/class/wireless/ndis.h diff --git a/third-party/cherryusb-0.6.0/class/wireless/rndis_protocol.h b/third-party/cherryusb-0.7.0/class/wireless/rndis_protocol.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/wireless/rndis_protocol.h rename to third-party/cherryusb-0.7.0/class/wireless/rndis_protocol.h diff --git a/third-party/cherryusb-0.6.0/class/wireless/usbd_rndis.c b/third-party/cherryusb-0.7.0/class/wireless/usbd_rndis.c similarity index 98% rename from third-party/cherryusb-0.6.0/class/wireless/usbd_rndis.c rename to third-party/cherryusb-0.7.0/class/wireless/usbd_rndis.c index 2479bb0bfa819e4e577f3b2f1bd3d57f4a795394..6b58d9375cc5e9d5b3486653f59b3e17998c27d6 100644 --- a/third-party/cherryusb-0.6.0/class/wireless/usbd_rndis.c +++ b/third-party/cherryusb-0.7.0/class/wireless/usbd_rndis.c @@ -529,14 +529,11 @@ int usbd_rndis_eth_tx(struct pbuf *p) return usbd_ep_start_write(rndis_ep_data[RNDIS_IN_EP_IDX].ep_addr, g_rndis_tx_buffer, g_rndis_tx_data_length); } #endif -struct usbd_interface *usbd_rndis_alloc_intf(uint8_t out_ep, uint8_t in_ep, uint8_t int_ep, uint8_t mac[6]) +struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf, + const uint8_t out_ep, + const uint8_t in_ep, + const uint8_t int_ep, uint8_t mac[6]) { - struct usbd_interface *intf = (struct usbd_interface *)usb_malloc(sizeof(struct usbd_interface)); - if (intf == NULL) { - USB_LOG_ERR("no mem to alloc intf\r\n"); - return NULL; - } - memcpy(usbd_rndis_cfg.mac, mac, 6); rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr = out_ep; diff --git a/third-party/cherryusb-0.6.0/class/wireless/usbd_rndis.h b/third-party/cherryusb-0.7.0/class/wireless/usbd_rndis.h similarity index 52% rename from third-party/cherryusb-0.6.0/class/wireless/usbd_rndis.h rename to third-party/cherryusb-0.7.0/class/wireless/usbd_rndis.h index 05ed53ae4a578cfbf75c71014b0d9f6cf9184112..d9f9f646e6fb8f2d3302715d34f0bdc08bfcdbe0 100644 --- a/third-party/cherryusb-0.6.0/class/wireless/usbd_rndis.h +++ b/third-party/cherryusb-0.7.0/class/wireless/usbd_rndis.h @@ -12,7 +12,11 @@ extern "C" { #endif -struct usbd_interface *usbd_rndis_alloc_intf(uint8_t out_ep, uint8_t in_ep, uint8_t int_ep, uint8_t mac[6]); +/* Init rndis interface driver */ +struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf, + const uint8_t out_ep, + const uint8_t in_ep, + const uint8_t int_ep, uint8_t mac[6]); #ifdef CONFIG_USBDEV_RNDIS_USING_LWIP struct pbuf *usbd_rndis_eth_rx(void); diff --git a/third-party/cherryusb-0.6.0/class/wireless/usbh_rndis.c b/third-party/cherryusb-0.7.0/class/wireless/usbh_rndis.c similarity index 83% rename from third-party/cherryusb-0.6.0/class/wireless/usbh_rndis.c rename to third-party/cherryusb-0.7.0/class/wireless/usbh_rndis.c index 4c2674672ada721e6faf64f7cdd39590db2fb375..515b6456dd163fe643dc7de5630d1053dcb11093 100644 --- a/third-party/cherryusb-0.6.0/class/wireless/usbh_rndis.c +++ b/third-party/cherryusb-0.7.0/class/wireless/usbh_rndis.c @@ -9,19 +9,23 @@ #define DEV_FORMAT "/dev/rndis" +USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[1024]; + static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class) { struct usb_setup_packet *setup = &rndis_class->hport->setup; int ret = 0; - rndis_initialize_msg_t cmd; - rndis_initialize_cmplt_t resp; + rndis_initialize_msg_t *cmd; + rndis_initialize_cmplt_t *resp; + + cmd = (rndis_initialize_msg_t *)g_rndis_buf; - cmd.MessageType = REMOTE_NDIS_INITIALIZE_MSG; - cmd.MessageLength = sizeof(rndis_initialize_msg_t); - cmd.RequestId = rndis_class->request_id++; - cmd.MajorVersion = 1; - cmd.MinorVersion = 0; - cmd.MaxTransferSize = 0x4000; + cmd->MessageType = REMOTE_NDIS_INITIALIZE_MSG; + cmd->MessageLength = sizeof(rndis_initialize_msg_t); + cmd->RequestId = rndis_class->request_id++; + cmd->MajorVersion = 1; + cmd->MinorVersion = 0; + cmd->MaxTransferSize = 0x4000; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_SEND_ENCAPSULATED_COMMAND; @@ -29,7 +33,7 @@ static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class) setup->wIndex = 0; setup->wLength = sizeof(rndis_initialize_msg_t); - ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)&cmd); + ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)cmd); if (ret < 0) { USB_LOG_ERR("rndis_initialize_msg_t send error, ret: %d\r\n", ret); return ret; @@ -37,13 +41,15 @@ static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class) //ret = usbh_ep_intr_transfer() + resp = (rndis_initialize_cmplt_t *)g_rndis_buf; + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE; setup->wValue = 0; setup->wIndex = 0; setup->wLength = 4096; - ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)&resp); + ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)resp); if (ret < 0) { USB_LOG_ERR("rndis_initialize_cmplt_t recv error, ret: %d\r\n", ret); return ret; @@ -56,16 +62,18 @@ int usbh_rndis_query_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid, { struct usb_setup_packet *setup = &rndis_class->hport->setup; int ret = 0; - rndis_query_msg_t cmd; + rndis_query_msg_t *cmd; rndis_query_cmplt_t *resp; - cmd.MessageType = REMOTE_NDIS_QUERY_MSG; - cmd.MessageLength = query_len + sizeof(rndis_query_msg_t); - cmd.RequestId = rndis_class->request_id++; - cmd.Oid = oid; - cmd.InformationBufferLength = query_len; - cmd.InformationBufferOffset = 20; - cmd.DeviceVcHandle = 0; + cmd = (rndis_query_msg_t *)g_rndis_buf; + + cmd->MessageType = REMOTE_NDIS_QUERY_MSG; + cmd->MessageLength = query_len + sizeof(rndis_query_msg_t); + cmd->RequestId = rndis_class->request_id++; + cmd->Oid = oid; + cmd->InformationBufferLength = query_len; + cmd->InformationBufferOffset = 20; + cmd->DeviceVcHandle = 0; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_SEND_ENCAPSULATED_COMMAND; @@ -81,11 +89,8 @@ int usbh_rndis_query_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid, //ret = usbh_ep_intr_transfer() - resp = usb_iomalloc(sizeof(rndis_query_cmplt_t) + 512); - if (resp == NULL) { - USB_LOG_ERR("Fail to alloc resp\r\n"); - return -ENOMEM; - } + resp = (rndis_query_cmplt_t *)g_rndis_buf; + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE; setup->wValue = 0; @@ -95,16 +100,12 @@ int usbh_rndis_query_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid, ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)resp); if (ret < 0) { USB_LOG_ERR("oid:%08x recv error, ret: %d\r\n", (unsigned int)oid, ret); - goto error_out; + return ret; } memcpy(info, ((uint8_t *)resp + sizeof(rndis_query_cmplt_t)), resp->InformationBufferLength); *info_len = resp->InformationBufferLength; -error_out: - if (resp) { - usb_iofree(resp); - } return ret; } @@ -113,13 +114,10 @@ static int usbh_rndis_set_msg_transfer(struct usbh_rndis *rndis_class, uint32_t struct usb_setup_packet *setup = &rndis_class->hport->setup; int ret = 0; rndis_set_msg_t *cmd; - rndis_set_cmplt_t resp; + rndis_set_cmplt_t *resp; + + cmd = (rndis_set_msg_t *)g_rndis_buf; - cmd = usb_iomalloc(sizeof(rndis_set_msg_t) + info_len); - if (cmd == NULL) { - USB_LOG_ERR("Fail to alloc cmd\r\n"); - return -ENOMEM; - } cmd->MessageType = REMOTE_NDIS_SET_MSG; cmd->MessageLength = info_len + sizeof(rndis_set_msg_t); cmd->RequestId = rndis_class->request_id++; @@ -138,27 +136,25 @@ static int usbh_rndis_set_msg_transfer(struct usbh_rndis *rndis_class, uint32_t ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)cmd); if (ret < 0) { USB_LOG_ERR("oid:%08x send error, ret: %d\r\n", (unsigned int)oid, ret); - goto error_out; + return ret; } //ret = usbh_ep_intr_transfer(rndis_class->hport->intin,buf,len,500); + resp = (rndis_set_cmplt_t *)g_rndis_buf; + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE; setup->wValue = 0; setup->wIndex = 0; setup->wLength = 4096; - ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)&resp); + ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)resp); if (ret < 0) { USB_LOG_ERR("oid:%08x recv error, ret: %d\r\n", (unsigned int)oid, ret); - goto error_out; + return ret; } -error_out: - if (cmd) { - usb_iofree(cmd); - } return ret; } @@ -166,12 +162,14 @@ int usbh_rndis_keepalive(struct usbh_rndis *rndis_class) { struct usb_setup_packet *setup = &rndis_class->hport->setup; int ret = 0; - rndis_keepalive_msg_t cmd; - rndis_keepalive_cmplt_t resp; + rndis_keepalive_msg_t *cmd; + rndis_keepalive_cmplt_t *resp; - cmd.MessageType = REMOTE_NDIS_KEEPALIVE_MSG; - cmd.MessageLength = sizeof(rndis_keepalive_msg_t); - cmd.RequestId = rndis_class->request_id++; + cmd = (rndis_keepalive_msg_t *)g_rndis_buf; + + cmd->MessageType = REMOTE_NDIS_KEEPALIVE_MSG; + cmd->MessageLength = sizeof(rndis_keepalive_msg_t); + cmd->RequestId = rndis_class->request_id++; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_SEND_ENCAPSULATED_COMMAND; @@ -187,13 +185,15 @@ int usbh_rndis_keepalive(struct usbh_rndis *rndis_class) //ret = usbh_ep_intr_transfer(rndis_class->hport->intin,buf,len,500); + resp = (rndis_keepalive_cmplt_t *)g_rndis_buf; + setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE; setup->wValue = 0; setup->wIndex = 0; setup->wLength = 4096; - ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)&resp); + ret = usbh_control_transfer(rndis_class->hport->ep0, setup, (uint8_t *)resp); if (ret < 0) { USB_LOG_ERR("keepalive recv error, ret: %d\r\n", ret); return ret; @@ -211,6 +211,8 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) unsigned int oid = 0; unsigned int oid_num = 0; uint32_t data_len; + uint8_t tmp_buffer[512]; + uint8_t data[32]; struct usbh_rndis *rndis_class = usb_malloc(sizeof(struct usbh_rndis)); if (rndis_class == NULL) { @@ -231,7 +233,8 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc; ep_cfg.ep_addr = ep_desc->bEndpointAddress; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; - ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK;; + ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; + ; ep_cfg.ep_interval = ep_desc->bInterval; ep_cfg.hport = hport; usbh_pipe_alloc(&rndis_class->intin, &ep_cfg); @@ -240,15 +243,10 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) for (uint8_t i = 0; i < hport->config.intf[intf + 1].altsetting[0].intf_desc.bNumEndpoints; i++) { ep_desc = &hport->config.intf[intf + 1].altsetting[0].ep[i].ep_desc; - ep_cfg.ep_addr = ep_desc->bEndpointAddress; - ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; - ep_cfg.ep_mps = ep_desc->wMaxPacketSize; - ep_cfg.ep_interval = ep_desc->bInterval; - ep_cfg.hport = hport; if (ep_desc->bEndpointAddress & 0x80) { - usbh_pipe_alloc(&rndis_class->bulkin, &ep_cfg); + usbh_hport_activate_epx(&rndis_class->bulkin, hport, ep_desc); } else { - usbh_pipe_alloc(&rndis_class->bulkout, &ep_cfg); + usbh_hport_activate_epx(&rndis_class->bulkout, hport, ep_desc); } } @@ -258,12 +256,9 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) } USB_LOG_INFO("rndis init success\r\n"); - uint8_t *tmp_buffer = usb_iomalloc(512); - uint8_t data[32]; - ret = usbh_rndis_query_msg_transfer(rndis_class, OID_GEN_SUPPORTED_LIST, 0, tmp_buffer, &data_len); if (ret < 0) { - goto query_errorout; + return ret; } oid_num = (data_len / 4); USB_LOG_INFO("rndis query OID_GEN_SUPPORTED_LIST success,oid num :%d\r\n", oid_num); @@ -321,7 +316,6 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) } USB_LOG_INFO("rndis query iod:%08x success\r\n", oid); } - usb_iofree(tmp_buffer); uint32_t packet_filter = 0x0f; usbh_rndis_set_msg_transfer(rndis_class, OID_GEN_CURRENT_PACKET_FILTER, (uint8_t *)&packet_filter, 4); @@ -343,7 +337,6 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) return ret; query_errorout: USB_LOG_ERR("rndis query iod:%08x error\r\n", oid); - usb_iofree(tmp_buffer); return ret; } @@ -361,16 +354,11 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf) if (rndis_class->bulkout) { usbh_pipe_free(rndis_class->bulkout); } - + memset(rndis_class, 0, sizeof(struct usbh_rndis)); usb_free(rndis_class); - if (hport->config.intf[intf].devname[0] != '\0'){ + if (hport->config.intf[intf].devname[0] != '\0') USB_LOG_INFO("Unregister RNDIS Class:%s\r\n", hport->config.intf[intf].devname); - } - memset(hport->config.intf[intf].devname, 0, CONFIG_USBHOST_DEV_NAMELEN); - - hport->config.intf[intf].priv = NULL; - hport->config.intf[intf + 1].priv = NULL; } return ret; diff --git a/third-party/cherryusb-0.6.0/class/wireless/usbh_rndis.h b/third-party/cherryusb-0.7.0/class/wireless/usbh_rndis.h similarity index 100% rename from third-party/cherryusb-0.6.0/class/wireless/usbh_rndis.h rename to third-party/cherryusb-0.7.0/class/wireless/usbh_rndis.h diff --git a/third-party/cherryusb-0.6.0/common/usb_dc.h b/third-party/cherryusb-0.7.0/common/usb_dc.h similarity index 100% rename from third-party/cherryusb-0.6.0/common/usb_dc.h rename to third-party/cherryusb-0.7.0/common/usb_dc.h diff --git a/third-party/cherryusb-0.6.0/common/usb_def.h b/third-party/cherryusb-0.7.0/common/usb_def.h similarity index 100% rename from third-party/cherryusb-0.6.0/common/usb_def.h rename to third-party/cherryusb-0.7.0/common/usb_def.h diff --git a/third-party/cherryusb-0.6.0/common/usb_errno.h b/third-party/cherryusb-0.7.0/common/usb_errno.h similarity index 99% rename from third-party/cherryusb-0.6.0/common/usb_errno.h rename to third-party/cherryusb-0.7.0/common/usb_errno.h index aef08e518ba2411e1a72fe4ffb293effcdb717e7..f43a9896fb98c880a6caae95a2e374f65c9cb449 100644 --- a/third-party/cherryusb-0.6.0/common/usb_errno.h +++ b/third-party/cherryusb-0.7.0/common/usb_errno.h @@ -22,18 +22,10 @@ * environment as necessary to access the TLS-based errno variable. */ -#define errno *__errno() -#define set_errno(e) \ - do \ - { \ - errno = (int)(e); \ - } \ - while (0) -#define get_errno() errno - /* Definitions of error numbers and the string that would be * returned by strerror(). */ +#ifndef CONFIG_USB_ERROR_USE_SYSTEM #define EPERM 1 #define EPERM_STR "Operation not permitted" @@ -296,7 +288,9 @@ #define ESTRPIPE_STR "Streams pipe error" #define __ELASTERROR 2000 /* Users can add values starting here */ - +#else +#include +#endif /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/third-party/cherryusb-0.6.0/common/usb_hc.h b/third-party/cherryusb-0.7.0/common/usb_hc.h similarity index 100% rename from third-party/cherryusb-0.6.0/common/usb_hc.h rename to third-party/cherryusb-0.7.0/common/usb_hc.h diff --git a/third-party/cherryusb-0.6.0/common/usb_list.h b/third-party/cherryusb-0.7.0/common/usb_list.h similarity index 100% rename from third-party/cherryusb-0.6.0/common/usb_list.h rename to third-party/cherryusb-0.7.0/common/usb_list.h diff --git a/third-party/cherryusb-0.6.0/common/usb_log.h b/third-party/cherryusb-0.7.0/common/usb_log.h similarity index 91% rename from third-party/cherryusb-0.6.0/common/usb_log.h rename to third-party/cherryusb-0.7.0/common/usb_log.h index 45ad9e171a6588fca613add1bd799b9c1dd8d6a5..4d1eff84b6e0c15af0267652c97cd456208b8577 100644 --- a/third-party/cherryusb-0.6.0/common/usb_log.h +++ b/third-party/cherryusb-0.7.0/common/usb_log.h @@ -14,10 +14,6 @@ #define USB_DBG_INFO 2 #define USB_DBG_LOG 3 -#ifndef CONFIG_USB_DBG_LEVEL -#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO -#endif - #ifndef USB_DBG_TAG #define USB_DBG_TAG "USB" #endif @@ -32,9 +28,6 @@ * CYAN 36 * WHITE 37 */ -#ifndef CONFIG_USB_PRINTF -#define CONFIG_USB_PRINTF printf -#endif #ifdef CONFIG_USB_PRINTF_COLOR_ENABLE #define _USB_DBG_COLOR(n) CONFIG_USB_PRINTF("\033[" #n "m") @@ -80,7 +73,7 @@ #define USB_LOG_ERR(...) #endif -#define USB_LOG_RAW CONFIG_USB_PRINTF +#define USB_LOG_RAW(...) CONFIG_USB_PRINTF(__VA_ARGS__) void usb_assert(const char *filename, int linenum); #define USB_ASSERT(f) \ @@ -89,4 +82,4 @@ void usb_assert(const char *filename, int linenum); usb_assert(__FILE__, __LINE__); \ } while (0) -#endif /* USB_LOG_H */ +#endif /* USB_LOG_H */ \ No newline at end of file diff --git a/third-party/cherryusb-0.6.0/common/usb_mem.h b/third-party/cherryusb-0.7.0/common/usb_mem.h similarity index 72% rename from third-party/cherryusb-0.6.0/common/usb_mem.h rename to third-party/cherryusb-0.7.0/common/usb_mem.h index 3377ba62829b392c161b3a72ed93782368cd3f48..77a82bb8752ec988bf3df3b7e386329d97b33b5b 100644 --- a/third-party/cherryusb-0.6.0/common/usb_mem.h +++ b/third-party/cherryusb-0.7.0/common/usb_mem.h @@ -6,32 +6,6 @@ #ifndef USB_MEM_H #define USB_MEM_H -#include "usb_config.h" - -#ifdef CONFIG_USBHOST_XHCI - -void *usb_hc_malloc(size_t size); -void usb_hc_free(); -void *usb_hc_malloc_align(size_t align, size_t size); - -#define usb_malloc(size) usb_hc_malloc(size) -#define usb_free(ptr) usb_hc_free(ptr) -#define usb_align(align, size) usb_hc_malloc_align(align, size) - -#else - -#define usb_malloc(size) malloc(size) -#define usb_free(ptr) free(ptr) - -#endif - -#ifndef CONFIG_USB_ALIGN_SIZE -#define CONFIG_USB_ALIGN_SIZE 4 -#endif - -#ifndef USB_NOCACHE_RAM_SECTION -#define USB_NOCACHE_RAM_SECTION -#endif #define USB_MEM_ALIGNX __attribute__((aligned(CONFIG_USB_ALIGN_SIZE))) #if (CONFIG_USB_ALIGN_SIZE > 4) diff --git a/third-party/cherryusb-0.6.0/common/usb_util.h b/third-party/cherryusb-0.7.0/common/usb_util.h similarity index 100% rename from third-party/cherryusb-0.6.0/common/usb_util.h rename to third-party/cherryusb-0.7.0/common/usb_util.h diff --git a/third-party/cherryusb-0.6.0/core/usbd_core.c b/third-party/cherryusb-0.7.0/core/usbd_core.c similarity index 100% rename from third-party/cherryusb-0.6.0/core/usbd_core.c rename to third-party/cherryusb-0.7.0/core/usbd_core.c diff --git a/third-party/cherryusb-0.6.0/core/usbd_core.h b/third-party/cherryusb-0.7.0/core/usbd_core.h similarity index 100% rename from third-party/cherryusb-0.6.0/core/usbd_core.h rename to third-party/cherryusb-0.7.0/core/usbd_core.h diff --git a/third-party/cherryusb-0.6.0/core/usbh_core.c b/third-party/cherryusb-0.7.0/core/usbh_core.c similarity index 99% rename from third-party/cherryusb-0.6.0/core/usbh_core.c rename to third-party/cherryusb-0.7.0/core/usbh_core.c index afb0e8850d32f3e028088513924686579a83744c..b90eb2f5855fcf8ff4e3cacecb29eb06d43778c8 100644 --- a/third-party/cherryusb-0.6.0/core/usbh_core.c +++ b/third-party/cherryusb-0.7.0/core/usbh_core.c @@ -441,7 +441,7 @@ int usbh_enumerate(struct usbh_hubport *hport) #ifdef CONFIG_USBHOST_XHCI extern int usbh_get_xhci_devaddr(usbh_pipe_t * pipe); - /* for XHCI, dev address is allocated by xHc instead of SW */ + /* Assign a function address to the device connected to this port */ dev_addr = usbh_get_xhci_devaddr(hport->ep0); if (dev_addr < 0) { USB_LOG_ERR("Failed to allocate devaddr,errorcode:%d\r\n", ret); diff --git a/third-party/cherryusb-0.6.0/core/usbh_core.h b/third-party/cherryusb-0.7.0/core/usbh_core.h similarity index 99% rename from third-party/cherryusb-0.6.0/core/usbh_core.h rename to third-party/cherryusb-0.7.0/core/usbh_core.h index ff2c0fc3f16423d7c68b82578c94b3b1def147de..ce5090e71289dcbe27937cd8c63830e668b9faed 100644 --- a/third-party/cherryusb-0.6.0/core/usbh_core.h +++ b/third-party/cherryusb-0.7.0/core/usbh_core.h @@ -166,7 +166,7 @@ struct usbh_hub { int usbh_hport_activate_epx(usbh_pipe_t *pipe, struct usbh_hubport *hport, struct usb_endpoint_descriptor *ep_desc); /** - * @brief Submit an bulk transfer to an endpoint. + * @brief Submit an control transfer to an endpoint. * This is a blocking method; this method will not return until the transfer has completed. * Default timeout is 500ms. * diff --git a/third-party/cherryusb-0.6.0/makefile b/third-party/cherryusb-0.7.0/makefile similarity index 96% rename from third-party/cherryusb-0.6.0/makefile rename to third-party/cherryusb-0.7.0/makefile index a494e7aaf29e2558d14cc05456e8bb1b9d752a3e..dfc8f8c18e20f71545e1083a6092e6d8d96d5f82 100644 --- a/third-party/cherryusb-0.6.0/makefile +++ b/third-party/cherryusb-0.7.0/makefile @@ -1,5 +1,5 @@ -CHERRY_USB_DIR := $(THIRD_PARTY_CUR_DIR)/cherryusb-0.6.0 +CHERRY_USB_DIR := $(THIRD_PARTY_CUR_DIR)/cherryusb-0.7.0 INC_DIR += $(CHERRY_USB_DIR)/core \ $(CHERRY_USB_DIR)/common \ diff --git a/third-party/cherryusb-0.6.0/osal/usb_osal.h b/third-party/cherryusb-0.7.0/osal/usb_osal.h similarity index 100% rename from third-party/cherryusb-0.6.0/osal/usb_osal.h rename to third-party/cherryusb-0.7.0/osal/usb_osal.h diff --git a/third-party/cherryusb-0.6.0/osal/usb_osal_freertos.c b/third-party/cherryusb-0.7.0/osal/usb_osal_freertos.c similarity index 100% rename from third-party/cherryusb-0.6.0/osal/usb_osal_freertos.c rename to third-party/cherryusb-0.7.0/osal/usb_osal_freertos.c diff --git a/third-party/cherryusb-0.6.0/port/xhci/usb_hc_xhci.c b/third-party/cherryusb-0.7.0/port/xhci/usb_hc_xhci.c similarity index 99% rename from third-party/cherryusb-0.6.0/port/xhci/usb_hc_xhci.c rename to third-party/cherryusb-0.7.0/port/xhci/usb_hc_xhci.c index d153b5bf18038ddb3b2a1f0cb12bd6a5d3809bdb..e45dd2338863e50487524895c819c793431f2cf5 100644 --- a/third-party/cherryusb-0.6.0/port/xhci/usb_hc_xhci.c +++ b/third-party/cherryusb-0.7.0/port/xhci/usb_hc_xhci.c @@ -14,7 +14,7 @@ * FilePath: usb_hc_xhci.c * Date: 2022-09-19 17:24:36 * LastEditTime: 2022-09-19 17:24:36 - * Description:  This files is for xhci function implementation + * Description:  This file is for xhci function implementation. * * Modify History: * Ver   Who        Date         Changes @@ -209,7 +209,7 @@ static void xhci_setup_mmio(struct xhci_s *xhci, unsigned long base_addr) the following effective address of the first extended capability: 1000h + (0068h << 2) -> 1000h + 01A0h -> 11A0h */ xhci->xcap = XHCI_REG_CAP_HCC_XECP_GET(xhci->hcc) << 2; /* bit[31:16] xHCI extended cap pointer */ - xhci->context64 = (XHCI_REG_CAP_HCC_CSZ & xhci->hcc) ? true : false; + xhci->context64 = (XHCI_REG_CAP_HCC_CSZ & xhci->hcc) ? true : false; /* use context64 or not */ USB_LOG_INFO(" hc version: 0x%x\n", xhci->version); USB_LOG_INFO(" mmio base: 0x%x\n", xhci->base); @@ -477,6 +477,7 @@ static int xhci_cmd_reset_endpoint(struct xhci_s *xhci, struct xhci_pipe *pipe) TRB_CR_EPID_SET(pipe->epid)); } +/* xhci controller configure operation */ static int xhci_controller_configure(struct xhci_s *xhci) { uint32_t reg; @@ -996,9 +997,10 @@ __WEAK unsigned long usb_hc_get_register_base(void) return 0U; } +/* xhci hardware init */ int usb_hc_init(void) { - usb_hc_low_level_init(); + usb_hc_low_level_init(); /* set gic and memp */ memset(&xhci_host, 0, sizeof(xhci_host)); if (xhci_controller_setup(&xhci_host, usb_hc_get_register_base())) @@ -1009,6 +1011,7 @@ int usb_hc_init(void) return 0; } +/* turn usb para into xhci para */ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf) { uint8_t nports; diff --git a/third-party/cherryusb-0.6.0/port/xhci/usb_hc_xhci.h b/third-party/cherryusb-0.7.0/port/xhci/usb_hc_xhci.h similarity index 98% rename from third-party/cherryusb-0.6.0/port/xhci/usb_hc_xhci.h rename to third-party/cherryusb-0.7.0/port/xhci/usb_hc_xhci.h index a3036766a8b07c4cc436748ebc79396636d57409..869944a584c222609658454e796bb31bc6a64d3d 100644 --- a/third-party/cherryusb-0.6.0/port/xhci/usb_hc_xhci.h +++ b/third-party/cherryusb-0.7.0/port/xhci/usb_hc_xhci.h @@ -14,7 +14,7 @@ * FilePath: usb_hc_xhci.h * Date: 2022-07-19 09:26:25 * LastEditTime: 2022-07-19 09:26:25 - * Description:  This files is for xhci data structure definition + * Description:  This file is for xhci data structure definition. * * Modify History: * Ver   Who        Date         Changes diff --git a/third-party/cherryusb-0.6.0/port/xhci/xhci_reg.h b/third-party/cherryusb-0.7.0/port/xhci/xhci_reg.h similarity index 99% rename from third-party/cherryusb-0.6.0/port/xhci/xhci_reg.h rename to third-party/cherryusb-0.7.0/port/xhci/xhci_reg.h index d45ba1fe2fb6f3afe9f9ec4a6f3fb9c0e490d443..dc87d87df6adc4d17b0faa5839f4a5b733589b1c 100644 --- a/third-party/cherryusb-0.6.0/port/xhci/xhci_reg.h +++ b/third-party/cherryusb-0.7.0/port/xhci/xhci_reg.h @@ -14,7 +14,7 @@ * FilePath: xhci_reg.h * Date: 2022-07-19 09:26:25 * LastEditTime: 2022-07-19 09:26:25 - * Description:  This files is for xhci register definition + * Description:  This file is for xhci register definition. * * Modify History: * Ver   Who        Date         Changes diff --git a/third-party/freertos/portable/GCC/ft_platform/aarch32/port.c b/third-party/freertos/portable/GCC/ft_platform/aarch32/port.c index 3b5e1c13c0262724d51185fedbd1b8101af80676..091d3d171f76dc5d0568f32fc2105ba57398de09 100644 --- a/third-party/freertos/portable/GCC/ft_platform/aarch32/port.c +++ b/third-party/freertos/portable/GCC/ft_platform/aarch32/port.c @@ -112,6 +112,8 @@ point is zero. */ mode. */ #define portAPSR_USER_MODE (0x10) +static void vPortSetPriorityMask(uint32_t value); + /* The critical section macros only mask interrupts up to an application determined priority level. Sometimes it is necessary to turn interrupt off in the CPU itself before modifying certain hardware registers. */ @@ -131,7 +133,7 @@ the CPU itself before modifying certain hardware registers. */ #define portCLEAR_INTERRUPT_MASK() \ { \ portCPU_IRQ_DISABLE(); \ - sys_icc_pmr_set(portUNMASK_VALUE); \ + vPortSetPriorityMask(portUNMASK_VALUE); \ __asm volatile("DSB \n" \ "ISB \n"); \ portCPU_IRQ_ENABLE(); \ @@ -168,6 +170,8 @@ extern void vPortRestoreTaskContext(void); */ static void prvTaskExitError(void); + + /* * If the application provides an implementation of vApplicationIRQHandler(), * then it will get called directly without saving the FPU registers on @@ -431,21 +435,23 @@ void FreeRTOS_Tick_Handler(void) so there is no need to save and restore the current mask value. It is necessary to turn off interrupts in the CPU itself while the ICCPMR is being updated. */ - portCPU_IRQ_DISABLE(); - sys_icc_pmr_set((uint32_t)(configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT)); - // portICCPMR_PRIORITY_MASK_REGISTER = (uint32_t)(configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT); + + vPortSetPriorityMask((uint32_t)(configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT)); + __asm volatile("dsb \n" "isb \n" :: : "memory"); - portCPU_IRQ_ENABLE(); + /* Increment the RTOS tick. */ if (xTaskIncrementTick() != pdFALSE) { ulPortYieldRequired = pdTRUE; } - /* Ensure all interrupt priorities are active again. */ - portCLEAR_INTERRUPT_MASK(); + /* unmask all interrupt priorities. */ + vPortSetPriorityMask(portUNMASK_VALUE); + + /* interrupt clear. */ configCLEAR_TICK_INTERRUPT(); } /*-----------------------------------------------------------*/ @@ -483,26 +489,25 @@ Set current interrupt priority mask and translate, ICC_PMR • The value is right-shifted by one bit. • Bit [7] of the value is set to 1. */ -void vPortSetPriorityMask(uint32_t value) +static void vPortSetPriorityMask(uint32_t value) { uint32_t priority = PRIORITY_TRANSLATE_SET(value); sys_icc_pmr_set(priority); } /* Get current interrupt priority mask and translate, ICC_PMR, priority << portPRIORITY_SHIFT */ -uint32_t vPortGetPriorityMask(void) +static uint32_t vPortGetPriorityMask(void) { return PRIORITY_TRANSLATE_GET(sys_icc_pmr_get()); } /* Get current interrupt priority and translate, ICC_RPR, priority << portPRIORITY_SHIFT */ -uint32_t vPortGetCurrentPriority(void) +static uint32_t vPortGetCurrentPriority(void) { return PRIORITY_TRANSLATE_GET(sys_icc_rpr_get()); } - uint32_t ulPortSetInterruptMask(void) { uint32_t ulReturn; diff --git a/third-party/freertos/portable/GCC/ft_platform/aarch32/portASM.S b/third-party/freertos/portable/GCC/ft_platform/aarch32/portASM.S index 77bf3a9eadb4ce8b2743f209199d05e8c22df23b..64c0ce1c7a2ddfa810e81c254d41d4bd6372c93f 100644 --- a/third-party/freertos/portable/GCC/ft_platform/aarch32/portASM.S +++ b/third-party/freertos/portable/GCC/ft_platform/aarch32/portASM.S @@ -172,9 +172,6 @@ FreeRTOS_IRQ_Handler: MRS lr, SPSR PUSH {lr} - /* Change to supervisor mode to allow reentry. */ - CPS #SVC_MODE - /* Push used registers. */ PUSH {r0-r4, r12} @@ -188,7 +185,6 @@ FreeRTOS_IRQ_Handler: /* Read value from the interrupt acknowledge register, which is stored in r0 for future parameter and interrupt clearing use. */ - mrc p15, 0, r0, c12, c12, 0 isb @@ -206,12 +202,7 @@ FreeRTOS_IRQ_Handler: POP {r0-r4, lr} ADD sp, sp, r2 - CPSID i - DSB - ISB - /* Write the value read from ICCIAR to ICCEOIR.*/ - mcr p15, 0, r0, c12, c12, 1 isb @@ -234,7 +225,7 @@ exit_without_switch: /* No context switch. Restore used registers, LR_irq and SPSR before returning. */ POP {r0-r4, r12} - CPS #IRQ_MODE + POP {LR} MSR SPSR_cxsf, LR POP {LR} @@ -249,7 +240,7 @@ switch_before_exit: /* Restore used registers, LR-irq and SPSR before saving the context to the task stack. */ POP {r0-r4, r12} - CPS #IRQ_MODE + POP {LR} MSR SPSR_cxsf, LR POP {LR} diff --git a/third-party/freertos/portable/GCC/ft_platform/aarch64/port.c b/third-party/freertos/portable/GCC/ft_platform/aarch64/port.c index 30d55b892e0e3839ab904d9ec0179d4134ed376f..8bd92c7172ec1e2c3261e9c83061e01cac7658df 100644 --- a/third-party/freertos/portable/GCC/ft_platform/aarch64/port.c +++ b/third-party/freertos/portable/GCC/ft_platform/aarch64/port.c @@ -111,11 +111,13 @@ point is zero. */ /* The I bit in the DAIF bits. */ #define portDAIF_I (0x80) +static void vPortSetPriorityMask(uint32_t value); + /* Macro to unmask all interrupt priorities. */ #define portCLEAR_INTERRUPT_MASK() \ { \ portDISABLE_INTERRUPTS(); \ - InterruptSetPriorityMask(portUNMASK_VALUE); \ + vPortSetPriorityMask(portUNMASK_VALUE); \ __asm volatile("DSB SY \n" \ "ISB SY \n"); \ portENABLE_INTERRUPTS(); \ @@ -432,23 +434,23 @@ void FreeRTOS_Tick_Handler(void) necessary to turn off interrupts in the CPU itself while the ICCPMR is being updated. */ - InterruptSetPriorityMask(configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT); + vPortSetPriorityMask(configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT); __asm volatile("dsb sy \n" "isb sy \n" :: : "memory"); - /* Ok to enable interrupts after the interrupt source has been cleared. */ - configCLEAR_TICK_INTERRUPT(); - portENABLE_INTERRUPTS(); - /* Increment the RTOS tick. */ if (xTaskIncrementTick() != pdFALSE) { ullPortYieldRequired = pdTRUE; } - /* Ensure all interrupt priorities are active again. */ - portCLEAR_INTERRUPT_MASK(); + /* unmask all interrupt priorities. */ + vPortSetPriorityMask(portUNMASK_VALUE); + + /* interrupt clear. */ + configCLEAR_TICK_INTERRUPT(); + } /*-----------------------------------------------------------*/ @@ -475,20 +477,20 @@ Set current interrupt priority mask and translate, ICC_PMR • The value is right-shifted by one bit. • Bit [7] of the value is set to 1. */ -void vPortSetPriorityMask(uint32_t value) +static void vPortSetPriorityMask(uint32_t value) { uint32_t priority = PRIORITY_TRANSLATE_SET(value); InterruptSetPriorityMask(priority); } /* Get current interrupt priority mask and translate, ICC_PMR, priority << portPRIORITY_SHIFT */ -uint32_t vPortGetPriorityMask(void) +static uint32_t vPortGetPriorityMask(void) { return PRIORITY_TRANSLATE_GET(InterruptGetPriorityMask()); } /* Get current interrupt priority and translate, ICC_RPR, priority << portPRIORITY_SHIFT */ -uint32_t vPortGetCurrentPriority(void) +static uint32_t vPortGetCurrentPriority(void) { return PRIORITY_TRANSLATE_GET(FGicGetICC_RPR()); } diff --git a/third-party/freertos/portable/GCC/ft_platform/aarch64/portASM.S b/third-party/freertos/portable/GCC/ft_platform/aarch64/portASM.S index 834fffc9e243870b9f2f3bb16655e93d96f11d10..878a1c1d3dbb44b8027d9ea67828be1a229f5724 100644 --- a/third-party/freertos/portable/GCC/ft_platform/aarch64/portASM.S +++ b/third-party/freertos/portable/GCC/ft_platform/aarch64/portASM.S @@ -314,7 +314,6 @@ FreeRTOS_IRQ_Handler: /* Maintain the interrupt nesting information across the function call. */ STP X1, X5, [SP, #-0x10]! - /* Read value from the interrupt acknowledge register, which is stored in W0 for future parameter and interrupt clearing use. */ @@ -335,10 +334,8 @@ FreeRTOS_IRQ_Handler: LDP X0, X1, [SP], #0x10 /* End IRQ processing by writing ICCIAR to the EOI register. */ - MSR ICC_EOIR1_EL1, x0 - /* Restore the critical nesting count. */ LDP X1, X5, [SP], #0x10 STR X1, [X5] diff --git a/third-party/letter-shell-3.1/port/cmd/cmd_ps.c b/third-party/letter-shell-3.1/port/cmd/cmd_ps.c index f165834b749eb23047afeebbb77cbb0cc825ec59..1828cd14927535ca5ceee5f3b5eb43865a919002 100644 --- a/third-party/letter-shell-3.1/port/cmd/cmd_ps.c +++ b/third-party/letter-shell-3.1/port/cmd/cmd_ps.c @@ -11,7 +11,7 @@ * See the Phytium Public License for more details. * * - * FilePath: cmd_os_stats.c + * FilePath: cmd_ps.c * Date: 2022-02-25 08:34:53 * LastEditTime: 2022-02-25 08:34:53 * Description:  This file is for the ps command functions @@ -37,7 +37,7 @@ static int DisplayTaskStats(int argc, char *argv[]) vTaskList((char *)&CPU_RunInfo); //获取任务运行时间信息 printf("---------------------------------------------\r\n"); - printf("task_name\ttask_state\tpriority\tstack\ttask_num\r\n"); + printf("task_name\t\t task_state priority stack task_num\r\n"); printf("%s", CPU_RunInfo); printf("---------------------------------------------\r\n"); @@ -45,7 +45,7 @@ static int DisplayTaskStats(int argc, char *argv[]) vTaskGetRunTimeStats((char *)&CPU_RunInfo); - printf("task_name\trun_time_count\tusage_rate\r\n"); + printf("task_name\t\t\trun_time_count\tusage_rate\r\n"); printf("%s", CPU_RunInfo); printf("---------------------------------------------\r\n\n"); diff --git a/third-party/lwip-2.1.2/Kconfig b/third-party/lwip-2.1.2/Kconfig index da1139961ad702d8e524699c0bec85b525b4a0b5..698ce5d5ed41849209944c9bb3eb060957951468 100644 --- a/third-party/lwip-2.1.2/Kconfig +++ b/third-party/lwip-2.1.2/Kconfig @@ -57,7 +57,7 @@ menu "LWIP Freertos Port Configuration" default 2048 if TARGET_ARMV8_AARCH64 default 1024 config LWIP_PORT_RECEIVE_THREAD_PRIORITY - int "the stack priority of the receive thread" + int "the priority of the receive thread" default 5 endif @@ -71,7 +71,7 @@ menu "LWIP Freertos Port Configuration" default 2048 if TARGET_ARMV8_AARCH64 default 1024 config LWIP_PORT_LINK_DETECT_PRIORITY - int "the stack priority of the mac link detect thread" + int "the priority of the mac link detect thread" default 5 endif @@ -85,7 +85,7 @@ menu "LWIP Freertos Port Configuration" default 4096 if TARGET_ARMV8_AARCH64 default 2048 config LWIP_PORT_DHCP_PRIORITY - int "the stack priority of the dhcp thread" + int "the priority of the dhcp thread" default 5 endif diff --git a/third-party/lwip-2.1.2/ports/arch/sys_arch.c b/third-party/lwip-2.1.2/ports/arch/sys_arch.c index 4ef6014ab85e5797daa3c315f3a3d228963be4e5..ecee4fb2f189161fe2a4c7fec5b6fc6b7786c54e 100644 --- a/third-party/lwip-2.1.2/ports/arch/sys_arch.c +++ b/third-party/lwip-2.1.2/ports/arch/sys_arch.c @@ -43,7 +43,7 @@ #define SYSTEM_ARCH_PRINT_D(format, ...) FT_DEBUG_PRINT_D(SYSTEM_ARCH_DEBUG_TAG, format, ##__VA_ARGS__) #define SYSTEM_ARCH_PRINT_W(format, ...) FT_DEBUG_PRINT_W(SYSTEM_ARCH_DEBUG_TAG, format, ##__VA_ARGS__) -#if !NO_SYS + #include "FreeRTOS.h" #include "task.h" @@ -741,4 +741,4 @@ void sys_arch_delay(const unsigned int msec) vTaskDelay(msec / portTICK_RATE_MS); } -#endif /* !NO_SYS */ + diff --git a/third-party/lwip-2.1.2/ports/arch/sys_arch.h b/third-party/lwip-2.1.2/ports/arch/sys_arch.h index e2895989fdd17adffa056f5213fe0a1de67ebbe2..9402e47a1a00cf5ccd46c57a9024323eca391e6f 100644 --- a/third-party/lwip-2.1.2/ports/arch/sys_arch.h +++ b/third-party/lwip-2.1.2/ports/arch/sys_arch.h @@ -28,13 +28,12 @@ #include "sdkconfig.h" #include "lwipopts.h" -#if !NO_SYS - #include "FreeRTOS.h" - #include "task.h" - #include "queue.h" - #include "semphr.h" - #include "cc.h" -#endif +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" +#include "cc.h" + #ifdef __cplusplus extern "C" @@ -44,7 +43,7 @@ extern "C" #define SYS_MBOX_NULL (xQueueHandle)0 #define SYS_SEM_NULL (xSemaphoreHandle)0 #define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE -#if !NO_SYS + typedef xSemaphoreHandle sys_sem_t; typedef xSemaphoreHandle sys_mutex_t; typedef xQueueHandle sys_mbox_t; @@ -61,7 +60,7 @@ typedef struct _sys_arch_state_t /* Message queue constants. */ void sys_thread_delete(sys_thread_t handle); void sys_arch_delay(const unsigned int msec); -#endif + sys_prot_t sys_arch_protect(void); void sys_arch_unprotect(sys_prot_t pval); diff --git a/third-party/lwip-2.1.2/ports/fgmac/ethernetif.c b/third-party/lwip-2.1.2/ports/fgmac/ethernetif.c index 6f54f08ce30a0e2406db7b095db1a7a37349d284..7afe7c69df6f8afb087557097ffb8ea55d400ab2 100644 --- a/third-party/lwip-2.1.2/ports/fgmac/ethernetif.c +++ b/third-party/lwip-2.1.2/ports/fgmac/ethernetif.c @@ -134,9 +134,9 @@ static void ethernetif_input(struct netif *netif) struct pbuf *p; SYS_ARCH_DECL_PROTECT(lev); -#if !NO_SYS + while (1) -#endif + { /* move received packet into a new pbuf */ SYS_ARCH_PROTECT(lev); @@ -339,9 +339,9 @@ static err_t low_level_output_arp_off(struct netif *netif, struct pbuf *q, const -err_t ethernetif_init(struct netif *netif) +err_t ethernetif_gmac_init(struct netif *netif) { - LWIP_DEBUGF(NETIF_DEBUG, ("*******start init eth\n")); + LWIP_DEBUGF(NETIF_DEBUG, ("*******Start init eth\n")); #if LWIP_NETIF_HOSTNAME /* Initialize interface hostname */ diff --git a/third-party/lwip-2.1.2/ports/fxmac/ethernetif.c b/third-party/lwip-2.1.2/ports/fxmac/ethernetif.c index cd9ab8931d7bb24f112209981a373d7869309d0d..01dd18b01a0dd093dfe00e0c4b4ba2cf12f0fe90 100644 --- a/third-party/lwip-2.1.2/ports/fxmac/ethernetif.c +++ b/third-party/lwip-2.1.2/ports/fxmac/ethernetif.c @@ -173,9 +173,9 @@ static void ethernetif_input(struct netif *netif) struct pbuf *p; SYS_ARCH_DECL_PROTECT(lev); -#if !NO_SYS + while (1) -#endif + { /* move received packet into a new pbuf */ SYS_ARCH_PROTECT(lev); @@ -249,9 +249,9 @@ static err_t low_level_init(struct netif *netif) return ERR_MEM; } -#if !NO_SYS + sys_sem_new(&xmac_netif_p->sem_rx_data_available, 0); -#endif + /* obtain config of this emac */ FXMAC_LWIP_NET_PRINT_I("netif->state is %p \r\n ", netif->state); @@ -354,7 +354,7 @@ static err_t low_level_output_arp_off(struct netif *netif, struct pbuf *q, const #endif /* LWIP_ARP */ /* - * ethernetif_init(): + * ethernetif_xmac_init(): * * Should be called at the beginning of the program to set up the * network interface. It calls the function low_level_init() to do the @@ -362,7 +362,7 @@ static err_t low_level_output_arp_off(struct netif *netif, struct pbuf *q, const * */ -err_t ethernetif_init(struct netif *netif) +err_t ethernetif_xmac_init(struct netif *netif) { LWIP_DEBUGF(NETIF_DEBUG, ("*******Start init eth\n")); diff --git a/third-party/sfud-1.1.0/Kconfig b/third-party/sfud-1.1.0/Kconfig index 3d55088f96ba1de8c8fe142a44c5608ec5cf5d76..05c935222a196f8170149fd671963ef80377c6a1 100644 --- a/third-party/sfud-1.1.0/Kconfig +++ b/third-party/sfud-1.1.0/Kconfig @@ -1,34 +1 @@ -menu "SFUD Configuration" - - config SFUD_CTRL_FSPIM - bool - prompt "Use FSPIM" - select USE_SPI - select USE_FSPIM - default n - - config SFUD_CTRL_FQSPI - bool - prompt "Use FQSPI" - select USE_QSPI - select USE_NOR_QSPI - default n - if SFUD_CTRL_FQSPI - choice SFUD_QSPI_READ_MODE - prompt "QSPI Read Mode" - default SFUD_QSPI_READ_MODE_QUAD_READ - help - Select QSPI Read Mode as Read or Dual or Quad - - config SFUD_QSPI_READ_MODE_READ - bool "Read" - - config SFUD_QSPI_READ_MODE_DUAL_READ - bool "Dual Read" - - config SFUD_QSPI_READ_MODE_QUAD_READ - bool "Quad Read" - - endchoice #SFUD_QSPI_READ_MODE - endif -endmenu \ No newline at end of file +source "$STANDALONE_DIR/third-party/sfud-1.1.0/Kconfig" \ No newline at end of file diff --git a/third-party/sfud-1.1.0/LICENSE b/third-party/sfud-1.1.0/LICENSE deleted file mode 100644 index 14b97461499c04854209cc6e2e8164c234a67e03..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016-2018 Armink (armink.ztl@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/third-party/sfud-1.1.0/README.md b/third-party/sfud-1.1.0/README.md deleted file mode 100644 index 42ac6c93ad161abcef8d9e4e1705930ab25784bf..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/README.md +++ /dev/null @@ -1,298 +0,0 @@ -# SFUD (Serial Flash Universal Driver) 串行 Flash 通用驱动库 - ---- - -## 0、SFUD 是什么 - -[SFUD](https://github.com/armink/SFUD) 是一款开源的串行 SPI Flash 通用驱动库。由于现有市面的串行 Flash 种类居多,各个 Flash 的规格及命令存在差异, SFUD 就是为了解决这些 Flash 的差异现状而设计,让我们的产品能够支持不同品牌及规格的 Flash,提高了涉及到 Flash 功能的软件的可重用性及可扩展性,同时也可以规避 Flash 缺货或停产给产品所带来的风险。 - -- 主要特点:支持 SPI/QSPI 接口、面向对象(同时支持多个 Flash 对象)、可灵活裁剪、扩展性强、支持 4 字节地址 -- 资源占用 - - 标准占用:RAM:0.2KB ROM:5.5KB - - 最小占用:RAM:0.1KB ROM:3.6KB -- 设计思路: - - **什么是 SFDP** :它是 JEDEC (固态技术协会)制定的串行 Flash 功能的参数表标准,最新版 V1.6B ([点击这里查看](https://www.jedec.org/standards-documents/docs/jesd216b))。该标准规定了,每个 Flash 中会存在一个参数表,该表中会存放 Flash 容量、写粒度、擦除命令、地址模式等 Flash 规格参数。目前,除了部分厂家旧款 Flash 型号会不支持该标准,其他绝大多数新出厂的 Flash 均已支持 SFDP 标准。所以该库在初始化时会优先读取 SFDP 表参数。 - - **不支持 SFDP 怎么办** :如果该 Flash 不支持 SFDP 标准,SFUD 会查询配置文件 ( [`/sfud/inc/sfud_flash_def.h`](https://github.com/armink/SFUD/blob/4bee2d0417a7ce853cc7aa3639b03fe825611fd9/sfud/inc/sfud_flash_def.h#L116-L142) ) 中提供的 **Flash 参数信息表** 中是否支持该款 Flash。如果不支持,则可以在配置文件中添加该款 Flash 的参数信息(添加方法详细见 [2.5 添加库目前不支持的 Flash](#25-添加库目前不支持的-flash))。获取到了 Flash 的规格参数后,就可以实现对 Flash 的全部操作。 - -## 1、为什么选择 SFUD - -- 避免项目因 Flash 缺货、Flash 停产或产品扩容而带来的风险; -- 越来越多的项目将固件存储到串行 Flash 中,例如:ESP8266 的固件、主板中的 BIOS 及其他常见电子产品中的固件等等,但是各种 Flash 规格及命令不统一。使用 SFUD 即可避免,在相同功能的软件平台基础下,无法适配不同 Flash 种类的硬件平台的问题,提高软件的可重用性; -- 简化软件流程,降低开发难度。现在只需要配置好 SPI 通信,即可畅快的开始玩串行 Flash 了; -- 可以用来制作 Flash 编程器/烧写器 - -## 2、SFUD 如何使用 - -### 2.1 已支持 Flash - -下表为所有已在 Demo 平台上进行过真机测试过的 Flash。显示为 **不支持** SFDP 标准的 Flash 已经在 Flash 参数信息表中定义,更多不支持 SFDP 标准的 Flash 需要大家以后 **共同来完善和维护** **([Github](https://github.com/armink/SFUD)|[OSChina](http://git.oschina.net/armink/SFUD)|[Coding](https://coding.net/u/armink/p/SFUD/git))** 。 - -如果觉得这个开源项目很赞,可以点击 [项目主页](https://github.com/armink/SFUD) 右上角的 **Star** ,同时把它推荐给更多有需要的朋友。 - -|型号|制造商|容量|最高速度|SFDP 标准|QSPI 模式|备注| -|:--:|:----:|:--:|:--:|:--:|:--:|----| -|[W25Q40BV](http://microchip.ua/esp8266/W25Q40BV(EOL).pdf)|Winbond|4Mb|50Mhz|不支持|双线|已停产| -|[W25Q80DV](http://www.winbond.com/resource-files/w25q80dv_revg_07212015.pdf)|Winbond|8Mb|104Mhz|支持|双线|| -|[W25Q16BV](https://media.digikey.com/pdf/Data%20Sheets/Winbond%20PDFs/W25Q16BV.pdf)|Winbond|16Mb|104Mhz|不支持|双线| by [slipperstree](https://github.com/slipperstree)| -|[W25Q16CV](http://www.winbond.com/resource-files/da00-w25q16cvf1.pdf)|Winbond|16Mb|104Mhz|支持|未测试|| -|[W25Q16DV](http://www.winbond.com/resource-files/w25q16dv%20revk%2005232016%20doc.pdf)|Winbond|16Mb|104Mhz|支持|未测试| by [slipperstree](https://github.com/slipperstree)| -|[W25Q32BV](http://www.winbond.com/resource-files/w25q32bv_revi_100413_wo_automotive.pdf)|Winbond|32Mb|104Mhz|支持|双线|| -|[W25Q64CV](http://www.winbond.com/resource-files/w25q64cv_revh_052214[2].pdf)|Winbond|64Mb|80Mhz|支持|四线|| -|[W25Q128BV](http://www.winbond.com/resource-files/w25q128bv_revh_100313_wo_automotive.pdf)|Winbond|128Mb|104Mhz|支持|四线|| -|[W25Q256FV](http://www.winbond.com/resource-files/w25q256fv%20revi%2002262016%20kms.pdf)|Winbond|256Mb|104Mhz|支持|四线|| -|[MX25L3206E](http://www.macronix.com/Lists/DataSheet/Attachments/3199/MX25L3206E,%203V,%2032Mb,%20v1.5.pdf)|Macronix|32Mb|86MHz|支持|双线|| -|[KH25L4006E](http://www.macronix.com.hk/Lists/Datasheet/Attachments/117/KH25L4006E.pdf)|Macronix|4Mb|86Mhz|支持|未测试| by [JiapengLi](https://github.com/JiapengLi)| -|[KH25L3206E](http://www.macronix.com.hk/Lists/Datasheet/Attachments/131/KH25L3206E.pdf)|Macronix|32Mb|86Mhz|支持|双线|| -|[SST25VF016B](http://ww1.microchip.com/downloads/en/DeviceDoc/20005044C.pdf)|Microchip|16Mb|50MHz|不支持|不支持| SST 已被 Microchip 收购| -|[M25P40](https://www.micron.com/~/media/documents/products/data-sheet/nor-flash/serial-nor/m25p/m25p40.pdf)|Micron|4Mb|75Mhz|不支持|未测试| by [redocCheng](https://github.com/redocCheng)| -|[M25P80](https://www.micron.com/~/media/documents/products/data-sheet/nor-flash/serial-nor/m25p/m25p80.pdf)|Micron|8Mb|75Mhz|不支持|未测试| by [redocCheng](https://github.com/redocCheng)| -|[M25P32](https://www.micron.com/~/media/documents/products/data-sheet/nor-flash/serial-nor/m25p/m25p32.pdf)|Micron|32Mb|75Mhz|不支持|不支持|| -|[EN25Q32B](http://www.kean.com.au/oshw/WR703N/teardown/EN25Q32B%2032Mbit%20SPI%20Flash.pdf)|EON|32Mb|104MHz|不支持|未测试|| -|[GD25Q16B](http://www.gigadevice.com/product/detail/5/410.html)|GigaDevice|16Mb|120Mhz|不支持|未测试| by [TanekLiang](https://github.com/TanekLiang) | -|[GD25Q32C](http://www.gigadevice.com/product/detail/5/410.html)|GigaDevice|32Mb|120Mhz|不支持|未测试| by [gaupen1186](https://github.com/gaupen1186) | -|[GD25Q64B](http://www.gigadevice.com/product/detail/5/364.html)|GigaDevice|64Mb|120Mhz|不支持|双线|| -|[S25FL216K](http://www.cypress.com/file/197346/download)|Cypress|16Mb|65Mhz|不支持|双线|| -|[S25FL032P](http://www.cypress.com/file/196861/download)|Cypress|32Mb|104Mhz|不支持|未测试| by [yc_911](https://gitee.com/yc_911) | -|[S25FL164K](http://www.cypress.com/file/196886/download)|Cypress|64Mb|108Mhz|支持|未测试|| -|[A25L080](http://www.amictechnology.com/datasheets/A25L080.pdf)|AMIC|8Mb|100Mhz|不支持|双线|| -|[A25LQ64](http://www.amictechnology.com/datasheets/A25LQ64.pdf)|AMIC|64Mb|104Mhz|支持|支持|| -|[F25L004](http://www.esmt.com.tw/db/manager/upload/f25l004.pdf)|ESMT|4Mb|100Mhz|不支持|不支持|| -|[PCT25VF016B](http://pctgroup.com.tw/attachments/files/files/248_25VF016B-P.pdf)|PCT|16Mb|80Mhz|不支持|不支持|SST 授权许可,会被识别为 SST25VF016B| -|[AT45DB161E](http://www.adestotech.com/wp-content/uploads/doc8782.pdf)|ADESTO|16Mb|85MHz|不支持|不支持|ADESTO 收购 Atmel 串行闪存产品线| -|[NM25Q128EV](http://www.normem.com/product/278082170)|Nor_Mem|128Mb|未测试|不支持|未测试|SFDP可能会读取到信息后识别为超过32Gb| - -> 注:QSPI 模式中,双线表示支持双线快读,四线表示支持四线快读。 -> -> 一般情况下,支持四线快读的 FLASH 也支持两线快读。 - -### 2.2 API 说明 - -先说明下本库主要使用的一个结构体 `sfud_flash` 。其定义位于 `/sfud/inc/sfud_def.h`。每个 SPI Flash 会对应一个该结构体,该结构体指针下面统称为 Flash 设备对象。初始化成功后在 `sfud_flash->chip` 结构体中会存放 SPI Flash 的常见参数。如果 SPI Flash 还支持 SFDP ,还可以通过 `sfud_flash->sfdp` 看到更加全面的参数信息。以下很多函数都将使用 Flash 设备对象作为第一个入参,实现对指定 SPI Flash 的操作。 - -#### 2.2.1 初始化 SFUD 库 - -将会调用 `sfud_device_init` ,初始化 Flash 设备表中的全部设备。如果只有一个 Flash 也可以只使用 `sfud_device_init` 进行单一初始化。 - -> **注意**:初始化完的 SPI Flash 默认都 **已取消写保护** 状态,如需开启写保护,请使用 sfud_write_status 函数修改 SPI Flash 状态。 - -```C -sfud_err sfud_init(void) -``` - -#### 2.2.2 初始化指定的 Flash 设备 - -```C -sfud_err sfud_device_init(sfud_flash *flash) -``` - -|参数 |描述| -|:----- |:----| -|flash |待初始化的 Flash 设备| - -#### 2.2.3 使能快速读模式(仅当 SFUD 开启 QSPI 模式后可用) - -当 SFUD 开启 QSPI 模式后,SFUD 中的 Flash 驱动支持使用 QSPI 总线进行通信。相比传统的 SPI 模式,使用 QSPI 能够加速 Flash 数据的读取,但当数据需要写入时,由于 Flash 本身的数据写入速度慢于 SPI 传输速度,所以 QSPI 模式下的数据写入速度提升并不明显。 - -所以 SFUD 对于 QSPI 模式的支持仅限于快速读命令。通过该函数可以配置 Flash 所使用的 QSPI 总线的实际支持的数据线最大宽度,例如:1 线(默认值,即传统的 SPI 模式)、2 线、4 线。 - -设置后,SFUD 会去结合当前设定的 QSPI 总线数据线宽度,去 [QSPI Flash 扩展信息表](https://github.com/armink/SFUD/blob/069d2b409ec239f84d675b2c3d37894e908829e6/sfud/inc/sfud_flash_def.h#L149-L177) 中匹配最合适的、速度最快的快速读命令,之后用户在调用 sfud_read() 时,会使用 QSPI 模式的传输函数发送该命令。 - -```C -sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width) -``` - -| 参数 | 描述 | -| :-------------- | :------------------------------------------- | -| flash | Flash 设备 | -| data_line_width | QSPI 总线支持的数据线最大宽度,例如:1、2、4 | - -#### 2.2.4 获取 Flash 设备对象 - -在 SFUD 配置文件中会定义 Flash 设备表,负责存放所有将要使用的 Flash 设备对象,所以 SFUD 支持多个 Flash 设备同时驱动。设备表的配置在 `/sfud/inc/sfud_cfg.h` 中 `SFUD_FLASH_DEVICE_TABLE` 宏定义,详细配置方法参照 [2.3 配置方法 Flash](#23-配置方法))。本方法通过 Flash 设备位于设备表中索引值来返回 Flash 设备对象,超出设备表范围返回 `NULL` 。 - -```C -sfud_flash *sfud_get_device(size_t index) -``` - -|参数 |描述| -|:----- |:----| -|index |Flash 设备位于 FLash 设备表中的索引值| - -#### 2.2.5 读取 Flash 数据 - -```C -sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| -|addr |起始地址| -|size |从起始地址开始读取数据的总大小| -|data |读取到的数据| - -#### 2.2.6 擦除 Flash 数据 - -> 注意:擦除操作将会按照 Flash 芯片的擦除粒度(详见 Flash 数据手册,一般为 block 大小。初始化完成后,可以通过 `sfud_flash->chip.erase_gran` 查看)对齐,请注意保证起始地址和擦除数据大小按照 Flash 芯片的擦除粒度对齐,否则执行擦除操作后,将会导致其他数据丢失。 - -```C -sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| -|addr |起始地址| -|size |从起始地址开始擦除数据的总大小| - -#### 2.2.7 擦除 Flash 全部数据 - -```C -sfud_err sfud_chip_erase(const sfud_flash *flash) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| - -#### 2.2.8 往 Flash 写数据 - -```C -sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| -|addr |起始地址| -|size |从起始地址开始写入数据的总大小| -|data |待写入的数据| - -#### 2.2.9 先擦除再往 Flash 写数据 - -> 注意:擦除操作将会按照 Flash 芯片的擦除粒度(详见 Flash 数据手册,一般为 block 大小。初始化完成后,可以通过 `sfud_flash->chip.erase_gran` 查看)对齐,请注意保证起始地址和擦除数据大小按照 Flash 芯片的擦除粒度对齐,否则执行擦除操作后,将会导致其他数据丢失。 - -```C -sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| -|addr |起始地址| -|size |从起始地址开始写入数据的总大小| -|data |待写入的数据| - -#### 2.2.10 读取 Flash 状态 - -```C -sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| -|status |当前状态寄存器值| - -#### 2.2.11 写(修改) Flash 状态 - -```C -sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status) -``` - -|参数 |描述| -|:----- |:----| -|flash |Flash 设备对象| -|is_volatile |是否为易闪失的,true: 易闪失的,及断电后会丢失| -|status |当前状态寄存器值| - -### 2.3 配置方法 - -所有配置位于 `/sfud/inc/sfud_cfg.h` ,请参考下面的配置介绍,选择适合自己项目的配置。 - -#### 2.3.1 调试模式 - -打开/关闭 `SFUD_DEBUG_MODE` 宏定义 - -#### 2.3.2 是否使用 SFDP 参数功能 - -打开/关闭 `SFUD_USING_SFDP` 宏定义 - -> 注意:关闭后只会查询该库在 `/sfud/inc/sfud_flash_def.h` 中提供的 Flash 信息表。这样虽然会降低软件的适配性,但减少代码量。 - -#### 2.3.3 是否使用该库自带的 Flash 参数信息表 - -打开/关闭 `SFUD_USING_FLASH_INFO_TABLE` 宏定义 - -> 注意:关闭后该库只驱动支持 SFDP 规范的 Flash,也会适当的降低部分代码量。另外 2.3.2 及 2.3.3 这两个宏定义至少定义一种,也可以两种方式都选择。 - -#### 2.3.4 既不使用 SFDP ,也不使用 Flash 参数信息表 - -为了进一步降低代码量,`SFUD_USING_SFDP` 与 `SFUD_USING_FLASH_INFO_TABLE` 也可以 **都不定义** 。 - -此时,只要在定义 Flash 设备时,指定好 Flash 参数,之后再调用 `sfud_device_init` 对该设备进行初始化。参考如下代码: - -```C -sfud_flash sfud_norflash0 = { - .name = "norflash0", - .spi.name = "SPI1", - .chip = { "W25Q64FV", SFUD_MF_ID_WINBOND, 0x40, 0x17, 8L * 1024L * 1024L, SFUD_WM_PAGE_256B, 4096, 0x20 } }; -...... -sfud_device_init(&sfud_norflash0); -...... -``` - -#### 2.3.5 Flash 设备表 - -如果产品中存在多个 Flash ,可以添加 Flash 设备表。修改 `SFUD_FLASH_DEVICE_TABLE` 这个宏定义,示例如下: - -```C -enum { - SFUD_W25Q64CV_DEVICE_INDEX = 0, - SFUD_GD25Q64B_DEVICE_INDEX = 1, -}; - -#define SFUD_FLASH_DEVICE_TABLE \ -{ \ - [SFUD_W25Q64CV_DEVICE_INDEX] = {.name = "W25Q64CV", .spi.name = "SPI1"}, \ - [SFUD_GD25Q64B_DEVICE_INDEX] = {.name = "GD25Q64B", .spi.name = "SPI3"}, \ -} -``` - -上面定义了两个 Flash 设备(大部分产品一个足以),两个设备的名称为 `"W25Q64CV"` 及 `"GD25Q64B"` ,分别对应 `"SPI1"` 及 `"SPI3"` 这两个 SPI 设备名称(在移植 SPI 接口时会用到,位于 `/sfud/port/sfud_port.c` ), `SFUD_W25Q16CV_DEVICE_INDEX` 与 `SFUD_GD25Q64B_DEVICE_INDEX` 这两个枚举定义了两个设备位于设备表中的索引,可以通过 `sfud_get_device_table()` 方法获取到设备表,再配合这个索引值来访问指定的设备。 - -#### 2.3.6 QSPI 模式 - -打开/关闭 `SFUD_USING_QSPI` 宏定义 - -开启后,SFUD 也将支持使用 QSPI 总线连接的 Flash。 - -### 2.4 移植说明 - -移植文件位于 `/sfud/port/sfud_port.c` ,文件中的 `sfud_err sfud_spi_port_init(sfud_flash *flash)` 方法是库提供的移植方法,在里面完成各个设备 SPI 读写驱动(必选)、重试次数(必选)、重试接口(可选)及 SPI 锁(可选)的配置。更加详细的移植内容,可以参考 demo 中的各个平台的移植文件。 - -### 2.5 添加库目前不支持的 Flash - -这里需要修改 `/sfud/inc/sfdu_flash_def.h` ,所有已经支持的 Flash 见 `SFUD_FLASH_CHIP_TABLE` 宏定义,需要提前准备的 Flash 参数内容分别为:| 名称 | 制造商 ID | 类型 ID | 容量 ID | 容量 | 写模式 | 擦除粒度(擦除的最小单位) | 擦除粒度对应的命令 | 。这里以添加 兆易创新 ( GigaDevice ) 的 `GD25Q64B` Flash 来举例。 - -此款 Flash 为兆易创新的早期生产的型号,所以不支持 SFDP 标准。首先需要下载其数据手册,找到 0x9F 命令返回的 3 种 ID, 这里需要最后面两字节 ID ,即 `type id` 及 `capacity id` 。 `GD25Q64B` 对应这两个 ID 分别为 `0x40` 及 `0x17` 。上面要求的其他 Flash 参数都可以在数据手册中找到,这里要重点说明下 **写模式** 这个参数,库本身提供的写模式共计有 4 种,详见文件顶部的 `sfud_write_mode` 枚举类型,同一款 Flash 可以同时支持多种写模式,视情况而定。对于 `GD25Q64B` 而言,其支持的写模式应该为 `SFUD_WM_PAGE_256B` ,即写 1-256 字节每页。结合上述 `GD25Q64B` 的 Flash 参数应如下: - -``` - {"GD25Q64B", SFUD_MF_ID_GIGADEVICE, 0x40, 0x17, 8*1024*1024, SFUD_WM_PAGE_256B, 4096, 0x20}, -``` - -再将其增加到 `SFUD_FLASH_CHIP_TABLE` 宏定义末尾,即可完成该库对 `GD25Q64B` 的支持。 - -### 2.6 Demo - -目前已支持如下平台下的 Demo - -|路径 |平台描述| -|:----- |:----| -|[/demo/stm32f10x_non_os](https://github.com/armink/SFUD/tree/master/demo/stm32f10x_non_os) |STM32F10X 裸机平台| -|[/demo/stm32f2xx_rtt](https://github.com/armink/SFUD/tree/master/demo/stm32f2xx_rtt) |STM32F2XX + [RT-Thread](http://www.rt-thread.org/) 操作系统平台| -|[/demo/stm32l475_non_os_qspi](https://github.com/armink/SFUD/tree/master/demo/stm32l475_non_os_qspi) |STM32L475 + QSPI 模式 裸机平台| - -### 2.7 许可 - -采用 MIT 开源协议,细节请阅读项目中的 LICENSE 文件内容。 diff --git a/third-party/sfud-1.1.0/docs/readme.md b/third-party/sfud-1.1.0/docs/readme.md deleted file mode 100644 index da9229a0bf41c4c4ad48d4d4e863c7f5d68a63c4..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/docs/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -|File or folder name |Description| -|:----- |:----| -|en |English documents| -|zh |中文文档(简体)| \ No newline at end of file diff --git a/third-party/sfud-1.1.0/docs/zh/benchmark.txt b/third-party/sfud-1.1.0/docs/zh/benchmark.txt deleted file mode 100644 index 28e60c50f4c21e86b0bc5a6f2f9b4f926444fe0e..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/docs/zh/benchmark.txt +++ /dev/null @@ -1,151 +0,0 @@ -msh >sf bench -Erasing the W25Q40 524288 bytes data, waiting... -Erase benchmark success, total time: 4.712S. -Writing the W25Q40 524288 bytes data, waiting... -Write benchmark success, total time: 3.072S. -Reading the W25Q40 524288 bytes data, waiting... -Read benchmark success, total time: 1.634S. - -msh >sf bench -Erasing the W25Q80 1048576 bytes data, waiting... -Erase benchmark success, total time: 1.818S. -Writing the W25Q80 1048576 bytes data, waiting... -Write benchmark success, total time: 6.553S. -Reading the W25Q80 1048576 bytes data, waiting... -Read benchmark success, total time: 3.266S. - -msh >sf bench -Erasing the W25Q16 2097152 bytes data, waiting... -Erase benchmark success, total time: 3.642S. -Writing the W25Q16 2097152 bytes data, waiting... -Write benchmark success, total time: 13.107S. -Reading the W25Q16 2097152 bytes data, waiting... -Read benchmark success, total time: 6.534S. - -msh >sf bench -Erasing the W25Q32 4194304 bytes data, waiting... -Erase benchmark success, total time: 7.166S. -Writing the W25Q32 4194304 bytes data, waiting... -Write benchmark success, total time: 26.214S. -Reading the W25Q32 4194304 bytes data, waiting... -Read benchmark success, total time: 13.066S. - -msh >sf bench -Erasing the W25Q64 8388608 bytes data, waiting... -Erase benchmark success, total time: 20.591S. -Writing the W25Q64 8388608 bytes data, waiting... -Write benchmark success, total time: 32.768S. -Reading the W25Q64 8388608 bytes data, waiting... -Read benchmark success, total time: 16.129S. - -msh >sf bench -Erasing the W25Q64 8388608 bytes data, waiting... -Erase benchmark success, total time: 20.000S. -Writing the W25Q64 8388608 bytes data, waiting... -Write benchmark success, total time: 42.598S. -Reading the W25Q64 8388608 bytes data, waiting... -Read benchmark success, total time: 26.132S. - -msh >sf bench -Erasing the W25Q128 16777216 bytes data, waiting... -Erase benchmark success, total time: 48.424S. -Writing the W25Q128 16777216 bytes data, waiting... -Write benchmark success, total time: 78.651S. -Reading the W25Q128 16777216 bytes data, waiting... -Read benchmark success, total time: 52.240S. - -msh >sf bench -Erasing the W25Q256 33554432 bytes data, waiting... -Erase benchmark success, total time: 79.629S. -Writing the W25Q256 33554432 bytes data, waiting... -Write benchmark success, total time: 131.073S. -Reading the W25Q256 33554432 bytes data, waiting... -Read benchmark success, total time: 29.556S. - -msh >sf bench -Erasing the MX25L3206E 4194304 bytes data, waiting... -Erase benchmark success, total time: 24.818S. -Writing the MX25L3206E 4194304 bytes data, waiting... -Write benchmark success, total time: 24.576S. -Reading the MX25L3206E 4194304 bytes data, waiting... -Read benchmark success, total time: 13.068S. - -msh >sf bench -Erasing the KH25L3206E 4194304 bytes data, waiting... -Erase benchmark success, total time: 26.983S. -Writing the KH25L3206E 4194304 bytes data, waiting... -Write benchmark success, total time: 24.576S. -Reading the KH25L3206E 4194304 bytes data, waiting... -Read benchmark success, total time: 12.642S. - -msh >sf bench -Erasing the SST25VF016B 2097152 bytes data, waiting... -Erase benchmark success, total time: 9.590S. -Writing the SST25VF016B 2097152 bytes data, waiting... -Write benchmark success, total time: 27.809S. -Reading the SST25VF016B 2097152 bytes data, waiting... -Read benchmark success, total time: 6.320S. - -msh >sf bench -Erasing the M25P32 4194304 bytes data, waiting... -Erase benchmark success, total time: 28.323S. -Writing the M25P32 4194304 bytes data, waiting... -Write benchmark success, total time: 24.576S. -Reading the M25P32 4194304 bytes data, waiting... -Read benchmark success, total time: 12.641S. - -msh >sf bench -Erasing the EN25Q32B 4194304 bytes data, waiting... -Erase benchmark success, total time: 13.493S. -Writing the EN25Q32B 4194304 bytes data, waiting... -Write benchmark success, total time: 22.937S. -Reading the EN25Q32B 4194304 bytes data, waiting... -Read benchmark success, total time: 12.642S. - -msh >sf bench -Erasing the GD25Q64B 8388608 bytes data, waiting... -Erase benchmark success, total time: 27.745S. -Writing the GD25Q64B 8388608 bytes data, waiting... -Write benchmark success, total time: 39.321S. -Reading the GD25Q64B 8388608 bytes data, waiting... -Read benchmark success, total time: 25.284S. - -msh >sf bench -Erasing the S25FL216K 2097152 bytes data, waiting... -Erase benchmark success, total time: 13.354S. -Writing the S25FL216K 2097152 bytes data, waiting... -Write benchmark success, total time: 19.669S. -Reading the S25FL216K 2097152 bytes data, waiting... -Read benchmark success, total time: 6.322S. - -msh >sf bench -Erasing the A25LQ64 8388608 bytes data, waiting... -Erase benchmark success, total time: 8.725S. -Writing the A25LQ64 8388608 bytes data, waiting... -Write benchmark success, total time: 36.044S. -Reading the A25LQ64 8388608 bytes data, waiting... -Read benchmark success, total time: 25.284S. - -msh >sf bench -Erasing the A25L080 1048576 bytes data, waiting... -Erase benchmark success, total time: 3.673S. -Writing the A25L080 1048576 bytes data, waiting... -Write benchmark success, total time: 6.144S. -Reading the A25L080 1048576 bytes data, waiting... -Read benchmark success, total time: 3.160S. - -msh >sf bench -Erasing the F25L004 524288 bytes data, waiting... -Erase benchmark success, total time: 2.689S. -Writing the F25L004 524288 bytes data, waiting... -Write benchmark success, total time: 6.969S. -Reading the F25L004 524288 bytes data, waiting... -Read benchmark success, total time: 1.580S. - -msh >sf bench -Erasing the PCT25VF016B 2097152 bytes data, waiting... -Erase benchmark success, total time: 0.036S. -Writing the PCT25VF016B 2097152 bytes data, waiting... -Write benchmark success, total time: 26.714S. -Reading the PCT25VF016B 2097152 bytes data, waiting... -Read benchmark success, total time: 6.320S. diff --git a/third-party/sfud-1.1.0/docs/zh/images/RTT_ART_WiFi.jpg b/third-party/sfud-1.1.0/docs/zh/images/RTT_ART_WiFi.jpg deleted file mode 100644 index 0906db0d6596e89c25dafec84b2a35922fbedd73..0000000000000000000000000000000000000000 Binary files a/third-party/sfud-1.1.0/docs/zh/images/RTT_ART_WiFi.jpg and /dev/null differ diff --git a/third-party/sfud-1.1.0/docs/zh/readme.md b/third-party/sfud-1.1.0/docs/zh/readme.md deleted file mode 100644 index e587388f66e9c2c60cecff734c2a009ae615b546..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/docs/zh/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -|文件名 |描述| -|:----- |:----| -|benchmark.txt |性能测试报告| \ No newline at end of file diff --git a/third-party/sfud-1.1.0/inc/sfud.h b/third-party/sfud-1.1.0/inc/sfud.h deleted file mode 100644 index 2b68c38216f707f8d20ae007529ec74c4e769ef4..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/inc/sfud.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * This file is part of the Serial Flash Universal Driver Library. - * - * Copyright (c) 2016-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is an head file for this library. You can see all of the functions which can be called by user. - * Created on: 2016-04-23 - */ - -#ifndef _SFUD_H_ -#define _SFUD_H_ - -#include "sfud_def.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ../src/sfup.c */ -/** - * SFUD library initialize. - * - * @return result - */ -sfud_err sfud_init(void); - -/** - * SFUD initialize by flash device - * - * @param flash flash device - * - * @return result - */ -sfud_err sfud_device_init(sfud_flash *flash); - -/** - * get flash device by its index which in the flash information table - * - * @param index the index which in the flash information table @see flash_table - * - * @return flash device - */ -sfud_flash *sfud_get_device(size_t index); - -/** - * get flash device total number on flash device information table @see flash_table - * - * @return flash device total number - */ -size_t sfud_get_device_num(void); - -/** - * get flash device information table @see flash_table - * - * @return flash device table pointer - */ -const sfud_flash *sfud_get_device_table(void); - -#ifdef SFUD_USING_QSPI -/** - * Enbale the fast read mode in QSPI flash mode. Default read mode is normal SPI mode. - * - * it will find the appropriate fast-read instruction to replace the read instruction(0x03) - * fast-read instruction @see SFUD_FLASH_EXT_INFO_TABLE - * - * @note When Flash is in QSPI mode, the method must be called after sfud_device_init(). - * - * @param flash flash device - * @param data_line_width the data lines max width which QSPI bus supported, such as 1, 2, 4 - * - * @return result - */ -sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width); -#endif /* SFUD_USING_QSPI */ - -/** - * read flash data - * - * @param flash flash device - * @param addr start address - * @param size read size - * @param data read data pointer - * - * @return result - */ -sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data); - -/** - * erase flash data - * - * @note It will erase align by erase granularity. - * - * @param flash flash device - * @param addr start address - * @param size erase size - * - * @return result - */ -sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size); - -/** - * write flash data (no erase operate) - * - * @param flash flash device - * @param addr start address - * @param data write data - * @param size write size - * - * @return result - */ -sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data); - -/** - * erase and write flash data - * - * @param flash flash device - * @param addr start address - * @param size write size - * @param data write data - * - * @return result - */ -sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data); - -/** - * erase all flash data - * - * @param flash flash device - * - * @return result - */ -sfud_err sfud_chip_erase(const sfud_flash *flash); - -/** - * read flash register status - * - * @param flash flash device - * @param status register status - * - * @return result - */ -sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status); - -/** - * write status register - * - * @param flash flash device - * @param is_volatile true: volatile mode, false: non-volatile mode - * @param status register status - * - * @return result - */ -sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status); - -#ifdef __cplusplus -} -#endif - -#endif /* _SFUD_H_ */ diff --git a/third-party/sfud-1.1.0/inc/sfud_cfg.h b/third-party/sfud-1.1.0/inc/sfud_cfg.h deleted file mode 100644 index 6d21185c3c25f1b2d3642b0255b8dbf55e64868e..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/inc/sfud_cfg.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of the Serial Flash Universal Driver Library. - * - * Copyright (c) 2016-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is the configure head file for this library. - * Created on: 2016-04-23 - */ - -#ifndef _SFUD_CFG_H_ -#define _SFUD_CFG_H_ - - -#include "sdkconfig.h" -#ifndef SDK_CONFIG_H__ - #warning "Please include sdkconfig.h" -#endif - -#define SFUD_DEBUG_MODE - -#define SFUD_USING_SFDP - -#define SFUD_USING_FLASH_INFO_TABLE - -#ifdef CONFIG_SFUD_CTRL_FQSPI -#define SFUD_USING_QSPI -#endif - - -enum { - SFUD_FSPIM0_INDEX = 0, - SFUD_FSPIM1_INDEX = 1, - SFUD_FSPIM2_INDEX = 2, - SFUD_FSPIM3_INDEX = 3, - SFUD_FQSPI0_INDEX = 4, - SFUF_DEVICE_INDEX -}; - -#define FSPIM0_SFUD_NAME "FSPIM0" -#define FSPIM1_SFUD_NAME "FSPIM1" -#define FSPIM2_SFUD_NAME "FSPIM2" -#define FSPIM3_SFUD_NAME "FSPIM3" -#define FQSPI0_SFUD_NAME "FQSPI0" - -#define SFUD_FLASH_DEVICE_TABLE \ -{ \ - [SFUD_FSPIM0_INDEX] = {.name = "SPI0-FLASH", .spi.name = FSPIM0_SFUD_NAME}, \ - [SFUD_FSPIM1_INDEX] = {.name = "SPI1-FLASH", .spi.name = FSPIM1_SFUD_NAME}, \ - [SFUD_FSPIM2_INDEX] = {.name = "SPI2-FLASH", .spi.name = FSPIM2_SFUD_NAME}, \ - [SFUD_FSPIM3_INDEX] = {.name = "SPI3-FLASH", .spi.name = FSPIM3_SFUD_NAME}, \ - [SFUD_FQSPI0_INDEX] = {.name = "QSPI0-FLASH", .spi.name = FQSPI0_SFUD_NAME} \ -} -#endif /* _SFUD_CFG_H_ */ diff --git a/third-party/sfud-1.1.0/inc/sfud_def.h b/third-party/sfud-1.1.0/inc/sfud_def.h deleted file mode 100644 index 914b330e6994f71f1e2d9b4f588d06b9eaa45237..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/inc/sfud_def.h +++ /dev/null @@ -1,309 +0,0 @@ -/* - * This file is part of the Serial Flash Universal Driver Library. - * - * Copyright (c) 2016-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is the macro definition head file for this library. - * Created on: 2016-04-23 - */ - -#ifndef _SFUD_DEF_H_ -#define _SFUD_DEF_H_ - -#include -#include -#include -#include -#include "fdebug.h" -#include -#include "sfud_flash_def.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* debug print function. Must be implement by user. */ -#ifdef SFUD_DEBUG_MODE -#ifndef SFUD_DEBUG -#define SFUD_DEBUG(...) FT_DEBUG_PRINT_D("[SFUD]", __VA_ARGS__) -#endif /* SFUD_DEBUG */ -#else -#define SFUD_DEBUG(...) -#endif /* SFUD_DEBUG_MODE */ - -#ifndef SFUD_INFO -#define SFUD_INFO(...) FT_DEBUG_PRINT_I("[SFUD]", __VA_ARGS__) -#endif -#ifndef SFUD_WARN -#define SFUD_WARN(...) FT_DEBUG_PRINT_W("[SFUD]", __VA_ARGS__) -#endif -#ifndef SFUD_ERROR -#define SFUD_ERROR(...) FT_DEBUG_PRINT_E("[SFUD]", __VA_ARGS__) -#endif - -/* assert for developer. */ -#ifdef SFUD_DEBUG_MODE -#define SFUD_ASSERT(EXPR) \ -if (!(EXPR)) \ -{ \ - SFUD_DEBUG("(%s) has assert failed at %s.", #EXPR, __FUNCTION__); \ - while (1); \ -} -#else -#define SFUD_ASSERT(EXPR) -#endif - -/** - * retry process - * - * @param delay delay function for every retry. NULL will not delay for every retry. - * @param retry retry counts - * @param result SFUD_ERR_TIMEOUT: retry timeout - */ -#define SFUD_RETRY_PROCESS(delay, retry, result) \ - void (*__delay_temp)(void) = (void (*)(void))delay; \ - if (retry == 0) {result = SFUD_ERR_TIMEOUT;break;} \ - else {if (__delay_temp) {__delay_temp();} retry --;} - -/* software version number */ -#define SFUD_SW_VERSION "1.1.0" -/* - * all defined supported command - */ -#ifndef SFUD_CMD_WRITE_ENABLE -#define SFUD_CMD_WRITE_ENABLE 0x06 -#endif - -#ifndef SFUD_CMD_WRITE_DISABLE -#define SFUD_CMD_WRITE_DISABLE 0x04 -#endif - -#ifndef SFUD_CMD_READ_STATUS_REGISTER -#define SFUD_CMD_READ_STATUS_REGISTER 0x05 -#endif - -#ifndef SFUD_VOLATILE_SR_WRITE_ENABLE -#define SFUD_VOLATILE_SR_WRITE_ENABLE 0x50 -#endif - -#ifndef SFUD_CMD_WRITE_STATUS_REGISTER -#define SFUD_CMD_WRITE_STATUS_REGISTER 0x01 -#endif - -#ifndef SFUD_CMD_PAGE_PROGRAM -#define SFUD_CMD_PAGE_PROGRAM 0x02 -#endif - -#ifndef SFUD_CMD_AAI_WORD_PROGRAM -#define SFUD_CMD_AAI_WORD_PROGRAM 0xAD -#endif - -#ifndef SFUD_CMD_ERASE_CHIP -#define SFUD_CMD_ERASE_CHIP 0xC7 -#endif - -#ifndef SFUD_CMD_READ_DATA -#define SFUD_CMD_READ_DATA 0x03 -#endif - -#ifndef SFUD_CMD_DUAL_OUTPUT_READ_DATA -#define SFUD_CMD_DUAL_OUTPUT_READ_DATA 0x3B -#endif - -#ifndef SFUD_CMD_DUAL_IO_READ_DATA -#define SFUD_CMD_DUAL_IO_READ_DATA 0xBB -#endif - -#ifndef SFUD_CMD_QUAD_IO_READ_DATA -#define SFUD_CMD_QUAD_IO_READ_DATA 0xEB -#endif - -#ifndef SFUD_CMD_QUAD_OUTPUT_READ_DATA -#define SFUD_CMD_QUAD_OUTPUT_READ_DATA 0x6B -#endif - -#ifndef SFUD_CMD_MANUFACTURER_DEVICE_ID -#define SFUD_CMD_MANUFACTURER_DEVICE_ID 0x90 -#endif - -#ifndef SFUD_CMD_JEDEC_ID -#define SFUD_CMD_JEDEC_ID 0x9F -#endif - -#ifndef SFUD_CMD_READ_UNIQUE_ID -#define SFUD_CMD_READ_UNIQUE_ID 0x4B -#endif - -#ifndef SFUD_CMD_READ_SFDP_REGISTER -#define SFUD_CMD_READ_SFDP_REGISTER 0x5A -#endif - -#ifndef SFUD_CMD_ENABLE_RESET -#define SFUD_CMD_ENABLE_RESET 0x66 -#endif - -#ifndef SFUD_CMD_RESET -#define SFUD_CMD_RESET 0x99 -#endif - -#ifndef SFUD_CMD_ENTER_4B_ADDRESS_MODE -#define SFUD_CMD_ENTER_4B_ADDRESS_MODE 0xB7 -#endif - -#ifndef SFUD_CMD_EXIT_4B_ADDRESS_MODE -#define SFUD_CMD_EXIT_4B_ADDRESS_MODE 0xE9 -#endif - -#ifndef SFUD_WRITE_MAX_PAGE_SIZE -#define SFUD_WRITE_MAX_PAGE_SIZE 256 -#endif - -#ifndef SFUD_CMD_ERASE_SECTOR -#define SFUD_CMD_ERASE_SECTOR 0xD8 -#endif - -/* send dummy data for read data */ -#ifndef SFUD_DUMMY_DATA -#define SFUD_DUMMY_DATA 0xFF -#endif - -/* maximum number of erase type support on JESD216 (V1.0) */ -#define SFUD_SFDP_ERASE_TYPE_MAX_NUM 4 - -/** - * status register bits - */ -enum { - SFUD_STATUS_REGISTER_BUSY = (1 << 0), /**< busing */ - SFUD_STATUS_REGISTER_WEL = (1 << 1), /**< write enable latch */ - SFUD_STATUS_REGISTER_SRP = (1 << 7), /**< status register protect */ -}; - -/** - * error code - */ -typedef enum { - SFUD_SUCCESS = 0, /**< success */ - SFUD_ERR_NOT_FOUND = 1, /**< not found or not supported */ - SFUD_ERR_WRITE = 2, /**< write error */ - SFUD_ERR_READ = 3, /**< read error */ - SFUD_ERR_TIMEOUT = 4, /**< timeout error */ - SFUD_ERR_ADDR_OUT_OF_BOUND = 5, /**< address is out of flash bound */ - SFUD_ERR_INIT_FAILED = 6, /**< initialization is failed */ - SFUD_ERR_TX_BUF_OUT_OF_BOUND = 7 /**< transfer buff size is not enough */ -} sfud_err; - -#ifdef SFUD_USING_QSPI -/** - * QSPI flash read cmd format - */ -typedef struct { - uint8_t instruction; - uint8_t instruction_lines; - uint8_t address_size; - uint8_t address_lines; - uint8_t alternate_bytes_lines; - uint8_t dummy_cycles; - uint8_t data_lines; -} sfud_qspi_read_cmd_format; -#endif /* SFUD_USING_QSPI */ - -/* SPI bus write read data function type */ -typedef sfud_err (*spi_write_read_func)(const uint8_t *write_buf, size_t write_size, uint8_t *read_buf, size_t read_size); - -#ifdef SFUD_USING_SFDP -/** - * the SFDP (Serial Flash Discoverable Parameters) parameter info which used on this library - */ -typedef struct { - bool available; /**< available when read SFDP OK */ - uint8_t major_rev; /**< SFDP Major Revision */ - uint8_t minor_rev; /**< SFDP Minor Revision */ - uint16_t write_gran; /**< write granularity (bytes) */ - uint8_t erase_4k; /**< 4 kilobyte erase is supported throughout the device */ - uint8_t erase_4k_cmd; /**< 4 Kilobyte erase command */ - bool sr_is_non_vola; /**< status register is supports non-volatile */ - uint8_t vola_sr_we_cmd; /**< volatile status register write enable command */ - bool addr_3_byte; /**< supports 3-Byte addressing */ - bool addr_4_byte; /**< supports 4-Byte addressing */ - uint32_t capacity; /**< flash capacity (bytes) */ - struct { - uint32_t size; /**< erase sector size (bytes). 0x00: not available */ - uint8_t cmd; /**< erase command */ - } eraser[SFUD_SFDP_ERASE_TYPE_MAX_NUM]; /**< supported eraser types table */ - //TODO lots of fast read-related stuff (like modes supported and number of wait states/dummy cycles needed in each) -} sfud_sfdp, *sfud_sfdp_t; -#endif - -/** - * SPI device - */ -typedef struct __sfud_spi { - /* SPI device name */ - char *name; - /* SPI bus write read data function */ - sfud_err (*wr)(const struct __sfud_spi *spi, const uint8_t *write_buf, size_t write_size, uint8_t *read_buf, - size_t read_size); -#ifdef SFUD_USING_QSPI - /* QSPI fast read function */ - sfud_err (*qspi_read)(const struct __sfud_spi *spi, uint32_t addr, sfud_qspi_read_cmd_format *qspi_read_cmd_format, - uint8_t *read_buf, size_t read_size); -#endif - /* lock SPI bus */ - void (*lock)(const struct __sfud_spi *spi); - /* unlock SPI bus */ - void (*unlock)(const struct __sfud_spi *spi); - /* some user data */ - void *user_data; -} sfud_spi, *sfud_spi_t; - -/** - * serial flash device - */ -typedef struct { - char *name; /**< serial flash name */ - size_t index; /**< index of flash device information table @see flash_table */ - sfud_flash_chip chip; /**< flash chip information */ - sfud_spi spi; /**< SPI device */ - bool init_ok; /**< initialize OK flag */ - bool addr_in_4_byte; /**< flash is in 4-Byte addressing */ - struct { - void (*delay)(void); /**< every retry's delay */ - size_t times; /**< default times for error retry */ - } retry; - void *user_data; /**< some user data */ - -#ifdef SFUD_USING_QSPI - sfud_qspi_read_cmd_format read_cmd_format; /**< fast read cmd format */ -#endif - -#ifdef SFUD_USING_SFDP - sfud_sfdp sfdp; /**< serial flash discoverable parameters by JEDEC standard */ -#endif - -} sfud_flash, *sfud_flash_t; - -#ifdef __cplusplus -} -#endif - -#endif /* _SFUD_DEF_H_ */ diff --git a/third-party/sfud-1.1.0/inc/sfud_flash_def.h b/third-party/sfud-1.1.0/inc/sfud_flash_def.h deleted file mode 100644 index 3024442e501c14a6692ef45f7829f770e5c08fc1..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/inc/sfud_flash_def.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - * This file is part of the Serial Flash Universal Driver Library. - * - * Copyright (c) 2016-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is the flash types and specification macro definition head file for this library. - * Created on: 2016-06-09 - */ - -#ifndef _SFUD_FLASH_DEF_H_ -#define _SFUD_FLASH_DEF_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * flash program(write) data mode - */ -enum sfud_write_mode { - SFUD_WM_PAGE_256B = 1 << 0, /**< write 1 to 256 bytes per page */ - SFUD_WM_BYTE = 1 << 1, /**< byte write */ - SFUD_WM_AAI = 1 << 2, /**< auto address increment */ - SFUD_WM_DUAL_BUFFER = 1 << 3, /**< dual-buffer write, like AT45DB series */ -}; - -/* manufacturer information */ -typedef struct { - char *name; - uint8_t id; -} sfud_mf; - -/* flash chip information */ -typedef struct { - char *name; /**< flash chip name */ - uint8_t mf_id; /**< manufacturer ID */ - uint8_t type_id; /**< memory type ID */ - uint8_t capacity_id; /**< capacity ID */ - uint32_t capacity; /**< flash capacity (bytes) */ - uint16_t write_mode; /**< write mode @see sfud_write_mode */ - uint32_t erase_gran; /**< erase granularity (bytes) */ - uint8_t erase_gran_cmd; /**< erase granularity size block command */ -} sfud_flash_chip; - -#ifdef SFUD_USING_QSPI -/* QSPI flash chip's extended information compared with SPI flash */ -typedef struct { - uint8_t mf_id; /**< manufacturer ID */ - uint8_t type_id; /**< memory type ID */ - uint8_t capacity_id; /**< capacity ID */ - uint8_t read_mode; /**< supported read mode on this qspi flash chip */ -} sfud_qspi_flash_ext_info; -#endif - -/* SFUD support manufacturer JEDEC ID */ -#define SFUD_MF_ID_CYPRESS 0x01 -#define SFUD_MF_ID_FUJITSU 0x04 -#define SFUD_MF_ID_EON 0x1C -#define SFUD_MF_ID_ATMEL 0x1F -#define SFUD_MF_ID_MICRON 0x20 -#define SFUD_MF_ID_AMIC 0x37 -#define SFUD_MF_ID_NOR_MEM 0x52 -#define SFUD_MF_ID_SANYO 0x62 -#define SFUD_MF_ID_INTEL 0x89 -#define SFUD_MF_ID_ESMT 0x8C -#define SFUD_MF_ID_FUDAN 0xA1 -#define SFUD_MF_ID_HYUNDAI 0xAD -#define SFUD_MF_ID_SST 0xBF -#define SFUD_MF_ID_MICRONIX 0xC2 -#define SFUD_MF_ID_GIGADEVICE 0xC8 -#define SFUD_MF_ID_ISSI 0xD5 -#define SFUD_MF_ID_WINBOND 0xEF -#define SFUD_MF_ID_BOYA 0x68 - -/* SFUD supported manufacturer information table */ -#define SFUD_MF_TABLE \ -{ \ - {"Cypress", SFUD_MF_ID_CYPRESS}, \ - {"Fujitsu", SFUD_MF_ID_FUJITSU}, \ - {"EON", SFUD_MF_ID_EON}, \ - {"Atmel", SFUD_MF_ID_ATMEL}, \ - {"Micron", SFUD_MF_ID_MICRON}, \ - {"AMIC", SFUD_MF_ID_AMIC}, \ - {"Sanyo", SFUD_MF_ID_SANYO}, \ - {"Intel", SFUD_MF_ID_INTEL}, \ - {"ESMT", SFUD_MF_ID_ESMT}, \ - {"Fudan", SFUD_MF_ID_FUDAN}, \ - {"Hyundai", SFUD_MF_ID_HYUNDAI}, \ - {"SST", SFUD_MF_ID_SST}, \ - {"GigaDevice", SFUD_MF_ID_GIGADEVICE}, \ - {"ISSI", SFUD_MF_ID_ISSI}, \ - {"Winbond", SFUD_MF_ID_WINBOND}, \ - {"Micronix", SFUD_MF_ID_MICRONIX}, \ - {"Nor-Mem", SFUD_MF_ID_NOR_MEM}, \ - {"BoyaMicro", SFUD_MF_ID_BOYA}, \ -} - -#ifdef SFUD_USING_FLASH_INFO_TABLE -/* SFUD supported flash chip information table. If the flash not support JEDEC JESD216 standard, - * then the SFUD will find the flash chip information by this table. You can add other flash to here then - * notice me for update it. The configuration information name and index reference the sfud_flash_chip structure. - * | name | mf_id | type_id | capacity_id | capacity | write_mode | erase_gran | erase_gran_cmd | - */ -#define SFUD_FLASH_CHIP_TABLE \ -{ \ - {"AT45DB161E", SFUD_MF_ID_ATMEL, 0x26, 0x00, 2L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_DUAL_BUFFER, 512, 0x81}, \ - {"W25Q40BV", SFUD_MF_ID_WINBOND, 0x40, 0x13, 512L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"W25Q16BV", SFUD_MF_ID_WINBOND, 0x40, 0x15, 2L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"W25Q32BV", SFUD_MF_ID_WINBOND, 0x40, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"W25Q64CV", SFUD_MF_ID_WINBOND, 0x40, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"W25Q64DW", SFUD_MF_ID_WINBOND, 0x60, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"W25Q128BV", SFUD_MF_ID_WINBOND, 0x40, 0x18, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"W25Q256FV", SFUD_MF_ID_WINBOND, 0x40, 0x19, 32L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"SST25VF080B", SFUD_MF_ID_SST, 0x25, 0x8E, 1L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \ - {"SST25VF016B", SFUD_MF_ID_SST, 0x25, 0x41, 2L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \ - {"M25P32", SFUD_MF_ID_MICRON, 0x20, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 64L*1024L, 0xD8}, \ - {"M25P80", SFUD_MF_ID_MICRON, 0x20, 0x14, 1L*1024L*1024L, SFUD_WM_PAGE_256B, 64L*1024L, 0xD8}, \ - {"M25P40", SFUD_MF_ID_MICRON, 0x20, 0x13, 512L*1024L, SFUD_WM_PAGE_256B, 64L*1024L, 0xD8}, \ - {"EN25Q32B", SFUD_MF_ID_EON, 0x30, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"S25FL216K", SFUD_MF_ID_CYPRESS, 0x40, 0x15, 2L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"S25FL032P", SFUD_MF_ID_CYPRESS, 0x02, 0x15, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"A25L080", SFUD_MF_ID_AMIC, 0x30, 0x14, 1L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"F25L004", SFUD_MF_ID_ESMT, 0x20, 0x13, 512L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \ - {"PCT25VF016B", SFUD_MF_ID_SST, 0x25, 0x41, 2L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \ - {"NM25Q128EV", SFUD_MF_ID_NOR_MEM, 0x21, 0x18, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ - {"S25FS256S", SFUD_MF_ID_CYPRESS, 0x02, 0x19, 32L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25Q16B", SFUD_MF_ID_GIGADEVICE, 0x40, 0x15, 2L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25Q32C", SFUD_MF_ID_GIGADEVICE, 0x40, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25Q32E", SFUD_MF_ID_GIGADEVICE, 0x60, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25Q64B", SFUD_MF_ID_GIGADEVICE, 0x40, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25B257D", SFUD_MF_ID_GIGADEVICE, 0x40, 0x19, 32L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25LQ128E", SFUD_MF_ID_GIGADEVICE, 0x40, 0x18, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"GD25QL256D", SFUD_MF_ID_GIGADEVICE, 0x60, 0x19, 32L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"BY25Q64BS", SFUD_MF_ID_BOYA, 0x40, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"BY25Q32BS", SFUD_MF_ID_BOYA, 0x40, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8}, \ - {"BY25Q16BS", SFUD_MF_ID_BOYA, 0x40, 0x15, 2L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0xD8} \ -} -#endif /* SFUD_USING_FLASH_INFO_TABLE */ - -#ifdef SFUD_USING_QSPI -/* This table saves flash read-fast instructions in QSPI mode, - * SFUD can use this table to select the most appropriate read instruction for flash. - * | mf_id | type_id | capacity_id | qspi_read_mode | - */ -#define SFUD_FLASH_EXT_INFO_TABLE \ -{ \ - /* W25Q40BV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x13, NORMAL_SPI_READ|DUAL_OUTPUT}, \ - /* W25Q80JV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x14, NORMAL_SPI_READ|DUAL_OUTPUT}, \ - /* W25Q16BV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x15, NORMAL_SPI_READ|DUAL_OUTPUT}, \ - /* W25Q32BV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT|QUAD_OUTPUT|QUAD_IO}, \ - /* W25Q64JV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x17, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ - /* W25Q128JV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x18, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ - /* W25Q256FV */ \ - {SFUD_MF_ID_WINBOND, 0x40, 0x19, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ - /* EN25Q32B */ \ - {SFUD_MF_ID_EON, 0x30, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT|QUAD_IO}, \ - /* S25FL216K */ \ - {SFUD_MF_ID_CYPRESS, 0x40, 0x15, NORMAL_SPI_READ|DUAL_OUTPUT}, \ - /* A25L080 */ \ - {SFUD_MF_ID_AMIC, 0x30, 0x14, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO}, \ - /* A25LQ64 */ \ - {SFUD_MF_ID_AMIC, 0x40, 0x17, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_IO}, \ - /* MX25L3206E and KH25L3206E */ \ - {SFUD_MF_ID_MICRONIX, 0x20, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT}, \ - /* GD25Q64B */ \ - {SFUD_MF_ID_GIGADEVICE, 0x40, 0x17, NORMAL_SPI_READ|DUAL_OUTPUT}, \ -} -#endif /* SFUD_USING_QSPI */ - -#ifdef __cplusplus -} -#endif - -#endif /* _SFUD_FLASH_DEF_H_ */ diff --git a/third-party/sfud-1.1.0/library.json b/third-party/sfud-1.1.0/library.json deleted file mode 100644 index aebac0df3218b1e1f9dd91810a0d3efd4d102e90..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/library.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "SFUD", - "version": "0.0.0", - "build": { - "flags": [ - "-I sfud/inc", - "-I src/drivers" - ], - "srcDir": "sfud/src", - "srcFilter": "+<*> -" - }, - "dependencies": [] -} \ No newline at end of file diff --git a/third-party/sfud-1.1.0/ports/fspim/fspim_sfud_core.c b/third-party/sfud-1.1.0/ports/fspim/fspim_sfud_core.c index 111fa14247cfcd847d0b21d3ecb276d50f7448d9..18d2c9029363884d5f5a4f62f860a8c0c0db5fbc 100644 --- a/third-party/sfud-1.1.0/ports/fspim/fspim_sfud_core.c +++ b/third-party/sfud-1.1.0/ports/fspim/fspim_sfud_core.c @@ -42,25 +42,90 @@ typedef struct boolean is_inited; } FSpimSfudOs; -static FSpimSfudOs sfud_instance = +static FSpimSfudOs sfud_instance[FSPI_NUM] = { - .spi_id = FSPI2_ID, - .spi = NULL, - .spi_cfg = + [FSPI0_ID] = { - /* you may need to assign spi mode according to flash spec. */ - .spi_mode = FFREERTOS_SPIM_MODE_0, - .en_dma = FALSE, - .inner_loopback = FALSE + .spi_id = FSPI0_ID, + .spi = NULL, + .spi_cfg = + { + /* you may need to assign spi mode according to flash spec. */ + .spi_mode = FFREERTOS_SPIM_MODE_0, + .en_dma = FALSE, + .inner_loopback = FALSE + }, + .spi_msg = + { + .rx_buf = NULL, + .rx_len = 0U, + .tx_buf = NULL, + .tx_len = 0U + }, + .is_inited = FALSE + }, + [FSPI1_ID] = + { + .spi_id = FSPI1_ID, + .spi = NULL, + .spi_cfg = + { + /* you may need to assign spi mode according to flash spec. */ + .spi_mode = FFREERTOS_SPIM_MODE_0, + .en_dma = FALSE, + .inner_loopback = FALSE + }, + .spi_msg = + { + .rx_buf = NULL, + .rx_len = 0U, + .tx_buf = NULL, + .tx_len = 0U + }, + .is_inited = FALSE + }, +#if defined(CONFIG_TARGET_E2000) + [FSPI2_ID] = + { + .spi_id = FSPI2_ID, + .spi = NULL, + .spi_cfg = + { + /* you may need to assign spi mode according to flash spec. */ + .spi_mode = FFREERTOS_SPIM_MODE_0, + .en_dma = FALSE, + .inner_loopback = FALSE + }, + .spi_msg = + { + .rx_buf = NULL, + .rx_len = 0U, + .tx_buf = NULL, + .tx_len = 0U + }, + .is_inited = FALSE }, - .spi_msg = + [FSPI3_ID] = { - .rx_buf = NULL, - .rx_len = 0U, - .tx_buf = NULL, - .tx_len = 0U + .spi_id = FSPI3_ID, + .spi = NULL, + .spi_cfg = + { + /* you may need to assign spi mode according to flash spec. */ + .spi_mode = FFREERTOS_SPIM_MODE_0, + .en_dma = FALSE, + .inner_loopback = FALSE + }, + .spi_msg = + { + .rx_buf = NULL, + .rx_len = 0U, + .tx_buf = NULL, + .tx_len = 0U + }, + .is_inited = FALSE }, - .is_inited = FALSE +#endif }; static sfud_err FSpimReadWrite(const sfud_spi *spi, const uint8_t *write_buf, size_t write_size, uint8_t *read_buf, @@ -110,30 +175,45 @@ static sfud_err FSpimReadWrite(const sfud_spi *spi, const uint8_t *write_buf, si sfud_err FSpimProbe(sfud_flash *flash) { sfud_spi *spi_p = &flash->spi; - FSpimSfudOs *user_data = &sfud_instance; - - if (!memcmp(FSPIM2_SFUD_NAME, spi_p->name, strlen(FSPIM2_SFUD_NAME))) + u32 spim_id = FSPI2_ID; + + if (!memcmp(FSPIM0_SFUD_NAME, spi_p->name, strlen(FSPIM0_SFUD_NAME))) { - /* sfud_spi_port_init will be called for each flash candidate, - and we just do controller init for the first time */ - if (FALSE == user_data->is_inited) - { - /* init spi controller */ - user_data->spi = FFreeRTOSSpimInit(user_data->spi_id, &user_data->spi_cfg); - if (NULL == user_data->spi) - { - return SFUD_ERR_NOT_FOUND; - } - - user_data->is_inited = TRUE; - } - flash->spi.user_data = user_data; - flash->spi.wr = FSpimReadWrite; + spim_id = FSPI0_ID; + } + else if (!memcmp(FSPIM1_SFUD_NAME, spi_p->name, strlen(FSPIM1_SFUD_NAME))) + { + spim_id = FSPI1_ID; } +#if defined(CONFIG_TARGET_E2000) + else if (!memcmp(FSPIM2_SFUD_NAME, spi_p->name, strlen(FSPIM2_SFUD_NAME))) + { + spim_id = FSPI2_ID; + } + else if (!memcmp(FSPIM3_SFUD_NAME, spi_p->name, strlen(FSPIM3_SFUD_NAME))) + { + spim_id = FSPI3_ID; + } +#endif else { return SFUD_ERR_NOT_FOUND; } + FSpimSfudOs *user_data = &sfud_instance[spim_id]; + /* sfud_spi_port_init will be called for each flash candidate, + and we just do controller init for the first time */ + if (FALSE == user_data->is_inited) + { + /* init spi controller */ + user_data->spi = FFreeRTOSSpimInit(user_data->spi_id, &user_data->spi_cfg); + if (NULL == user_data->spi) + { + return SFUD_ERR_NOT_FOUND; + } + user_data->is_inited = TRUE; + } + flash->spi.user_data = user_data; + flash->spi.wr = FSpimReadWrite; return SFUD_SUCCESS; } \ No newline at end of file diff --git a/third-party/sfud-1.1.0/ports/sfud_port.c b/third-party/sfud-1.1.0/ports/sfud_port.c index 252f85a8256ed17b18107d667b16e63678e67254..97d1339596e923d9153254d93cce7044829a0a83 100644 --- a/third-party/sfud-1.1.0/ports/sfud_port.c +++ b/third-party/sfud-1.1.0/ports/sfud_port.c @@ -28,7 +28,7 @@ #include "sdkconfig.h" #ifndef SDK_CONFIG_H__ - #warning "Please include sdkconfig.h" +#warning "Please include sdkconfig.h" #endif #include #include @@ -40,13 +40,12 @@ #include "semphr.h" #ifdef CONFIG_SFUD_CTRL_FSPIM - #include "fspim_sfud_core.h" +#include "fspim_sfud_core.h" #endif #ifdef CONFIG_SFUD_CTRL_FQSPI - #include "fqspi_sfud_core.h" +#include "fqspi_sfud_core.h" #endif - static char log_buf[256]; static xSemaphoreHandle xSemaphore; @@ -105,20 +104,25 @@ sfud_err sfud_spi_port_init(sfud_flash *flash) * flash->retry.delay = null; * flash->retry.times = 10000; //Required */ -#ifdef CONFIG_SFUD_CTRL_FSPIM - result = FSpimProbe(flash); - if (result == SFUD_SUCCESS) +#ifdef CONFIG_SFUD_CTRL_FQSPI + if (!memcmp(FQSPI0_SFUD_NAME, flash->spi.name, strlen(FQSPI0_SFUD_NAME))) { - SFUD_INFO("FSpimProbe success flash.index=%d.", flash->index); - goto ret; - } + result = FQspiProbe(flash); + if (result == SFUD_SUCCESS) + { + SFUD_INFO("FQspiProbe success flash.index=%d.", flash->index); + goto ret; + } + } else #endif -#ifdef CONFIG_SFUD_CTRL_FQSPI - result = FQspiProbe(flash); - if (result == SFUD_SUCCESS) +#ifdef CONFIG_SFUD_CTRL_FSPIM { - SFUD_INFO("FQspiProbe success flash.index=%d.", flash->index); - goto ret; + result = FSpimProbe(flash); + if (result == SFUD_SUCCESS) + { + SFUD_INFO("FSpimProbe success flash.index=%d.", flash->index); + goto ret; + } } #endif return SFUD_ERR_NOT_FOUND; diff --git a/third-party/sfud-1.1.0/sfud.mk b/third-party/sfud-1.1.0/sfud.mk new file mode 100644 index 0000000000000000000000000000000000000000..d6ca2e45cc617e0a85e2489c5cdaaa2c1f8caee3 --- /dev/null +++ b/third-party/sfud-1.1.0/sfud.mk @@ -0,0 +1,20 @@ +ifdef CONFIG_USE_FREERTOS + INC_DIR += $(STANDALONE_DIR)/third-party/sfud-1.1.0 \ + $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0 \ + $(STANDALONE_DIR)/third-party/sfud-1.1.0/inc \ + $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports + SRC_DIR += $(STANDALONE_DIR)/third-party/sfud-1.1.0 \ + $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0 \ + $(STANDALONE_DIR)/third-party/sfud-1.1.0/src \ + $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports + + ifdef CONFIG_SFUD_CTRL_FSPIM + INC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fspim + SRC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fspim + endif + + ifdef CONFIG_SFUD_CTRL_FQSPI + INC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fqspi + SRC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fqspi + endif +endif #CONFIG_USE_FREERTOS \ No newline at end of file diff --git a/third-party/sfud-1.1.0/src/sfud.c b/third-party/sfud-1.1.0/src/sfud.c deleted file mode 100644 index 2304800231ad33f22fa4265f4e813282445ab424..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/src/sfud.c +++ /dev/null @@ -1,1041 +0,0 @@ -/* - * This file is part of the Serial Flash Universal Driver Library. - * - * Copyright (c) 2016-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: serial flash operate functions by SFUD lib. - * Created on: 2016-04-23 - */ - -#include "sfud.h" -#include - -/* send dummy data for read data */ -#define DUMMY_DATA 0xFF - -#ifndef SFUD_FLASH_DEVICE_TABLE -#error "Please configure the flash device information table in (in sfud_cfg.h)." -#endif - -/* user configured flash device information table */ -static sfud_flash flash_table[] = SFUD_FLASH_DEVICE_TABLE; -/* supported manufacturer information table */ -static const sfud_mf mf_table[] = SFUD_MF_TABLE; - -#ifdef SFUD_USING_FLASH_INFO_TABLE -/* supported flash chip information table */ -static const sfud_flash_chip flash_chip_table[] = SFUD_FLASH_CHIP_TABLE; -#endif - -#ifdef SFUD_USING_QSPI -/** - * flash read data mode - */ -enum sfud_qspi_read_mode { - NORMAL_SPI_READ = 1 << 0, /**< mormal spi read mode */ - DUAL_OUTPUT = 1 << 1, /**< qspi fast read dual output */ - DUAL_IO = 1 << 2, /**< qspi fast read dual input/output */ - QUAD_OUTPUT = 1 << 3, /**< qspi fast read quad output */ - QUAD_IO = 1 << 4, /**< qspi fast read quad input/output */ -}; - -/* QSPI flash chip's extended information table */ -static const sfud_qspi_flash_ext_info qspi_flash_ext_info_table[] = SFUD_FLASH_EXT_INFO_TABLE; -#endif /* SFUD_USING_QSPI */ - -static sfud_err software_init(const sfud_flash *flash); -static sfud_err hardware_init(sfud_flash *flash); -static sfud_err page256_or_1_byte_write(const sfud_flash *flash, uint32_t addr, size_t size, uint16_t write_gran, - const uint8_t *data); -static sfud_err aai_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data); -static sfud_err wait_busy(const sfud_flash *flash); -static sfud_err reset(const sfud_flash *flash); -static sfud_err read_jedec_id(sfud_flash *flash); -static sfud_err set_write_enabled(const sfud_flash *flash, bool enabled); -static sfud_err set_4_byte_address_mode(sfud_flash *flash, bool enabled); -static void make_adress_byte_array(const sfud_flash *flash, uint32_t addr, uint8_t *array); - -/* ../port/sfup_port.c */ -extern void sfud_log_debug(const char *file, const long line, const char *format, ...); -extern void sfud_log_info(const char *format, ...); - -/** - * SFUD initialize by flash device - * - * @param flash flash device - * - * @return result - */ -sfud_err sfud_device_init(sfud_flash *flash) { - sfud_err result = SFUD_SUCCESS; - - /* hardware initialize */ - result = hardware_init(flash); - if (result == SFUD_SUCCESS) { - result = software_init(flash); - } - if (result == SFUD_SUCCESS) { - flash->init_ok = true; - SFUD_INFO("%s flash device is initialize success.", flash->name); - } else { - flash->init_ok = false; - SFUD_WARN("Warning: %s flash device is initialize fail.", flash->name); - } - - return result; -} - -/** - * SFUD library initialize. - * - * @return result - */ -sfud_err sfud_init(void) { - sfud_err cur_flash_result = SFUD_SUCCESS, all_flash_result = SFUD_SUCCESS; - size_t i; - - SFUD_DEBUG("Start initialize Serial Flash Universal Driver(SFUD) V%s.", SFUD_SW_VERSION); - SFUD_DEBUG("You can get the latest version on https://github.com/armink/SFUD ."); - /* initialize all flash device in flash device table */ - for (i = 0; i < sizeof(flash_table) / sizeof(sfud_flash); i++) { - /* initialize flash device index of flash device information table */ - flash_table[i].index = i; - cur_flash_result = sfud_device_init(&flash_table[i]); - - if (cur_flash_result == SFUD_SUCCESS) { - all_flash_result = cur_flash_result; - } - } - - return all_flash_result; -} - -/** - * get flash device by its index which in the flash information table - * - * @param index the index which in the flash information table @see flash_table - * - * @return flash device - */ -sfud_flash *sfud_get_device(size_t index) { - if (index < sfud_get_device_num()) { - return &flash_table[index]; - } else { - return NULL; - } -} - -/** - * get flash device total number on flash device information table @see flash_table - * - * @return flash device total number - */ -size_t sfud_get_device_num(void) { - return sizeof(flash_table) / sizeof(sfud_flash); -} - -/** - * get flash device information table @see flash_table - * - * @return flash device table pointer - */ -const sfud_flash *sfud_get_device_table(void) { - return flash_table; -} - -#ifdef SFUD_USING_QSPI -static void qspi_set_read_cmd_format(sfud_flash *flash, uint8_t ins, uint8_t ins_lines, uint8_t addr_lines, - uint8_t dummy_cycles, uint8_t data_lines) { - /* if medium size greater than 16Mb, use 4-Byte address, instruction should be added one */ - if (flash->chip.capacity <= 0x1000000) { - flash->read_cmd_format.instruction = ins; - flash->read_cmd_format.address_size = 24; - } else { - flash->read_cmd_format.instruction = ins + 1; - flash->read_cmd_format.address_size = 32; - } - - flash->read_cmd_format.instruction_lines = ins_lines; - flash->read_cmd_format.address_lines = addr_lines; - flash->read_cmd_format.alternate_bytes_lines = 0; - flash->read_cmd_format.dummy_cycles = dummy_cycles; - flash->read_cmd_format.data_lines = data_lines; -} - -/** - * Enbale the fast read mode in QSPI flash mode. Default read mode is normal SPI mode. - * - * it will find the appropriate fast-read instruction to replace the read instruction(0x03) - * fast-read instruction @see SFUD_FLASH_EXT_INFO_TABLE - * - * @note When Flash is in QSPI mode, the method must be called after sfud_device_init(). - * - * @param flash flash device - * @param data_line_width the data lines max width which QSPI bus supported, such as 1, 2, 4 - * - * @return result - */ -sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width) { - size_t i = 0; - uint8_t read_mode = NORMAL_SPI_READ; - sfud_err result = SFUD_SUCCESS; - - SFUD_ASSERT(flash); - SFUD_ASSERT(data_line_width == 1 || data_line_width == 2 || data_line_width == 4); - - /* get read_mode, If don't found, the default is SFUD_QSPI_NORMAL_SPI_READ */ - for (i = 0; i < sizeof(qspi_flash_ext_info_table) / sizeof(sfud_qspi_flash_ext_info); i++) { - if ((qspi_flash_ext_info_table[i].mf_id == flash->chip.mf_id) - && (qspi_flash_ext_info_table[i].type_id == flash->chip.type_id) - && (qspi_flash_ext_info_table[i].capacity_id == flash->chip.capacity_id)) { - read_mode = qspi_flash_ext_info_table[i].read_mode; - } - } - - /* determine qspi supports which read mode and set read_cmd_format struct */ - switch (data_line_width) { - case 1: - qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); - break; - case 2: - if (read_mode & DUAL_IO) { - qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_IO_READ_DATA, 1, 2, 8, 2); - } else if (read_mode & DUAL_OUTPUT) { - qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_OUTPUT_READ_DATA, 1, 1, 8, 2); - } else { - qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); - } - break; - case 4: - if (read_mode & QUAD_IO) { - qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_IO_READ_DATA, 1, 4, 6, 4); - } else if (read_mode & QUAD_OUTPUT) { - qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_OUTPUT_READ_DATA, 1, 1, 8, 4); - } else { - qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); - } - break; - } - - return result; -} -#endif /* SFUD_USING_QSPI */ - -/** - * hardware initialize - */ -static sfud_err hardware_init(sfud_flash *flash) { - extern sfud_err sfud_spi_port_init(sfud_flash * flash); - - sfud_err result = SFUD_SUCCESS; - size_t i; - - SFUD_ASSERT(flash); - - result = sfud_spi_port_init(flash); - if (result != SFUD_SUCCESS) { - return result; - } - -#ifdef SFUD_USING_QSPI - /* set default read instruction */ - flash->read_cmd_format.instruction = SFUD_CMD_READ_DATA; -#endif /* SFUD_USING_QSPI */ - - /* SPI write read function must be initialize */ - SFUD_ASSERT(flash->spi.wr); - /* if the user don't configure flash chip information then using SFDP parameter or static flash parameter table */ - if (flash->chip.capacity == 0 || flash->chip.write_mode == 0 || flash->chip.erase_gran == 0 - || flash->chip.erase_gran_cmd == 0) { - /* read JEDEC ID include manufacturer ID, memory type ID and flash capacity ID */ - result = read_jedec_id(flash); - if (result != SFUD_SUCCESS) { - return result; - } - -#ifdef SFUD_USING_SFDP - extern bool sfud_read_sfdp(sfud_flash *flash); - /* read SFDP parameters */ - if (sfud_read_sfdp(flash)) { - flash->chip.name = NULL; - flash->chip.capacity = flash->sfdp.capacity; - /* only 1 byte or 256 bytes write mode for SFDP */ - if (flash->sfdp.write_gran == 1) { - flash->chip.write_mode = SFUD_WM_BYTE; - } else { - flash->chip.write_mode = SFUD_WM_PAGE_256B; - } - /* find the the smallest erase sector size for eraser. then will use this size for erase granularity */ - flash->chip.erase_gran = flash->sfdp.eraser[0].size; - flash->chip.erase_gran_cmd = flash->sfdp.eraser[0].cmd; - for (i = 1; i < SFUD_SFDP_ERASE_TYPE_MAX_NUM; i++) { - if (flash->sfdp.eraser[i].size != 0 && flash->chip.erase_gran > flash->sfdp.eraser[i].size) { - flash->chip.erase_gran = flash->sfdp.eraser[i].size; - flash->chip.erase_gran_cmd = flash->sfdp.eraser[i].cmd; - } - } - } else { -#endif - -#ifdef SFUD_USING_FLASH_INFO_TABLE - /* read SFDP parameters failed then using SFUD library provided static parameter */ - for (i = 0; i < sizeof(flash_chip_table) / sizeof(sfud_flash_chip); i++) { - if ((flash_chip_table[i].mf_id == flash->chip.mf_id) - && (flash_chip_table[i].type_id == flash->chip.type_id) - && (flash_chip_table[i].capacity_id == flash->chip.capacity_id)) { - flash->chip.name = flash_chip_table[i].name; - flash->chip.capacity = flash_chip_table[i].capacity; - flash->chip.write_mode = flash_chip_table[i].write_mode; - flash->chip.erase_gran = flash_chip_table[i].erase_gran; - flash->chip.erase_gran_cmd = flash_chip_table[i].erase_gran_cmd; - break; - } - } -#endif - -#ifdef SFUD_USING_SFDP - } -#endif - - } - - if (flash->chip.capacity == 0 || flash->chip.write_mode == 0 || flash->chip.erase_gran == 0 - || flash->chip.erase_gran_cmd == 0) { - SFUD_INFO("Warning: This flash device is not found or not support."); - return SFUD_ERR_NOT_FOUND; - } else { - const char *flash_mf_name = NULL; - /* find the manufacturer information */ - for (i = 0; i < sizeof(mf_table) / sizeof(sfud_mf); i++) { - if (mf_table[i].id == flash->chip.mf_id) { - flash_mf_name = mf_table[i].name; - break; - } - } - /* print manufacturer and flash chip name */ - if (flash_mf_name && flash->chip.name) { - SFUD_INFO("Find a %s %s flash chip. Size is %ld bytes.", flash_mf_name, flash->chip.name, - flash->chip.capacity); - } else if (flash_mf_name) { - SFUD_INFO("Find a %s flash chip. Size is %ld bytes.", flash_mf_name, flash->chip.capacity); - } else { - SFUD_INFO("Find a flash chip. Size is %ld bytes.", flash->chip.capacity); - } - } - - /* reset flash device */ - result = reset(flash); - if (result != SFUD_SUCCESS) { - return result; - } - - /* The flash all blocks is protected,so need change the flash status to unprotected before write and erase operate. */ - if (flash->chip.write_mode & SFUD_WM_AAI) { - result = sfud_write_status(flash, true, 0x00); - } else { - /* MX25L3206E */ - if ((0xC2 == flash->chip.mf_id) && (0x20 == flash->chip.type_id) && (0x16 == flash->chip.capacity_id)) { - result = sfud_write_status(flash, false, 0x00); - } - } - if (result != SFUD_SUCCESS) { - return result; - } - - /* if the flash is large than 16MB (256Mb) then enter in 4-Byte addressing mode */ - if (flash->chip.capacity > (1L << 24)) { - result = set_4_byte_address_mode(flash, true); - } else { - flash->addr_in_4_byte = false; - } - - return result; -} - -/** - * software initialize - * - * @param flash flash device - * - * @return result - */ -static sfud_err software_init(const sfud_flash *flash) { - sfud_err result = SFUD_SUCCESS; - - SFUD_ASSERT(flash); - - return result; -} - -/** - * read flash data - * - * @param flash flash device - * @param addr start address - * @param size read size - * @param data read data pointer - * - * @return result - */ -sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[5], cmd_size; - - SFUD_ASSERT(flash); - SFUD_ASSERT(data); - /* must be call this function after initialize OK */ - SFUD_ASSERT(flash->init_ok); - /* check the flash address bound */ - if (addr + size > flash->chip.capacity) { - SFUD_INFO("Error: Flash address is out of bound."); - return SFUD_ERR_ADDR_OUT_OF_BOUND; - } - /* lock SPI */ - if (spi->lock) { - spi->lock(spi); - } - - result = wait_busy(flash); - - if (result == SFUD_SUCCESS) { -#ifdef SFUD_USING_QSPI - if (spi->qspi_read) { - result = spi->qspi_read(spi, addr, (sfud_qspi_read_cmd_format *)&flash->read_cmd_format, data, size); - } else -#endif - { - cmd_data[0] = SFUD_CMD_READ_DATA; - make_adress_byte_array(flash, addr, &cmd_data[1]); - cmd_size = flash->addr_in_4_byte ? 5 : 4; - result = spi->wr(spi, cmd_data, cmd_size, data, size); - } - } - /* unlock SPI */ - if (spi->unlock) { - spi->unlock(spi); - } - - return result; -} - -/** - * erase all flash data - * - * @param flash flash device - * - * @return result - */ -sfud_err sfud_chip_erase(const sfud_flash *flash) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[4]; - - SFUD_ASSERT(flash); - /* must be call this function after initialize OK */ - SFUD_ASSERT(flash->init_ok); - /* lock SPI */ - if (spi->lock) { - spi->lock(spi); - } - - /* set the flash write enable */ - result = set_write_enabled(flash, true); - if (result != SFUD_SUCCESS) { - goto __exit; - } - - cmd_data[0] = SFUD_CMD_ERASE_CHIP; - /* dual-buffer write, like AT45DB series flash chip erase operate is different for other flash */ - if (flash->chip.write_mode & SFUD_WM_DUAL_BUFFER) { - cmd_data[1] = 0x94; - cmd_data[2] = 0x80; - cmd_data[3] = 0x9A; - result = spi->wr(spi, cmd_data, 4, NULL, 0); - } else { - result = spi->wr(spi, cmd_data, 1, NULL, 0); - } - if (result != SFUD_SUCCESS) { - SFUD_INFO("Error: Flash chip erase SPI communicate error."); - goto __exit; - } - result = wait_busy(flash); - -__exit: - /* set the flash write disable */ - set_write_enabled(flash, false); - /* unlock SPI */ - if (spi->unlock) { - spi->unlock(spi); - } - - return result; -} - -/** - * erase flash data - * - * @note It will erase align by erase granularity. - * - * @param flash flash device - * @param addr start address - * @param size erase size - * - * @return result - */ -sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size) { - extern size_t sfud_sfdp_get_suitable_eraser(const sfud_flash *flash, uint32_t addr, size_t erase_size); - - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[5], cmd_size, cur_erase_cmd; - size_t cur_erase_size; - - SFUD_ASSERT(flash); - /* must be call this function after initialize OK */ - SFUD_ASSERT(flash->init_ok); - /* check the flash address bound */ - if (addr + size > flash->chip.capacity) { - SFUD_INFO("Error: Flash address is out of bound."); - return SFUD_ERR_ADDR_OUT_OF_BOUND; - } - - if (addr == 0 && size == flash->chip.capacity) { - return sfud_chip_erase(flash); - } - - /* lock SPI */ - if (spi->lock) { - spi->lock(spi); - } - - /* loop erase operate. erase unit is erase granularity */ - while (size) { - /* if this flash is support SFDP parameter, then used SFDP parameter supplies eraser */ -#ifdef SFUD_USING_SFDP - size_t eraser_index; - if (flash->sfdp.available) { - /* get the suitable eraser for erase process from SFDP parameter */ - eraser_index = sfud_sfdp_get_suitable_eraser(flash, addr, size); - cur_erase_cmd = flash->sfdp.eraser[eraser_index].cmd; - cur_erase_size = flash->sfdp.eraser[eraser_index].size; - } else { -#else - { -#endif - cur_erase_cmd = flash->chip.erase_gran_cmd; - cur_erase_size = flash->chip.erase_gran; - } - /* set the flash write enable */ - result = set_write_enabled(flash, true); - if (result != SFUD_SUCCESS) { - goto __exit; - } - - cmd_data[0] = cur_erase_cmd; - make_adress_byte_array(flash, addr, &cmd_data[1]); - cmd_size = flash->addr_in_4_byte ? 5 : 4; - result = spi->wr(spi, cmd_data, cmd_size, NULL, 0); - if (result != SFUD_SUCCESS) { - SFUD_INFO("Error: Flash erase SPI communicate error."); - goto __exit; - } - result = wait_busy(flash); - if (result != SFUD_SUCCESS) { - goto __exit; - } - /* make erase align and calculate next erase address */ - if (addr % cur_erase_size != 0) { - if (size > cur_erase_size - (addr % cur_erase_size)) { - size -= cur_erase_size - (addr % cur_erase_size); - addr += cur_erase_size - (addr % cur_erase_size); - } else { - goto __exit; - } - } else { - if (size > cur_erase_size) { - size -= cur_erase_size; - addr += cur_erase_size; - } else { - goto __exit; - } - } - } - -__exit: - /* set the flash write disable */ - set_write_enabled(flash, false); - /* unlock SPI */ - if (spi->unlock) { - spi->unlock(spi); - } - - return result; -} - -/** - * write flash data (no erase operate) for write 1 to 256 bytes per page mode or byte write mode - * - * @param flash flash device - * @param addr start address - * @param size write size - * @param write_gran write granularity bytes, only support 1 or 256 - * @param data write data - * - * @return result - */ -static sfud_err page256_or_1_byte_write(const sfud_flash *flash, uint32_t addr, size_t size, uint16_t write_gran, - const uint8_t *data) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - static uint8_t cmd_data[5 + SFUD_WRITE_MAX_PAGE_SIZE]; - uint8_t cmd_size; - size_t data_size; - - SFUD_ASSERT(flash); - /* only support 1 or 256 */ - SFUD_ASSERT(write_gran == 1 || write_gran == 256); - /* must be call this function after initialize OK */ - SFUD_ASSERT(flash->init_ok); - /* check the flash address bound */ - if (addr + size > flash->chip.capacity) { - SFUD_INFO("Error: Flash address is out of bound."); - return SFUD_ERR_ADDR_OUT_OF_BOUND; - } - /* lock SPI */ - if (spi->lock) { - spi->lock(spi); - } - - /* loop write operate. write unit is write granularity */ - while (size) { - /* set the flash write enable */ - result = set_write_enabled(flash, true); - if (result != SFUD_SUCCESS) { - goto __exit; - } - cmd_data[0] = SFUD_CMD_PAGE_PROGRAM; - make_adress_byte_array(flash, addr, &cmd_data[1]); - cmd_size = flash->addr_in_4_byte ? 5 : 4; - - /* make write align and calculate next write address */ - if (addr % write_gran != 0) { - if (size > write_gran - (addr % write_gran)) { - data_size = write_gran - (addr % write_gran); - } else { - data_size = size; - } - } else { - if (size > write_gran) { - data_size = write_gran; - } else { - data_size = size; - } - } - size -= data_size; - addr += data_size; - - memcpy(&cmd_data[cmd_size], data, data_size); - - result = spi->wr(spi, cmd_data, cmd_size + data_size, NULL, 0); - if (result != SFUD_SUCCESS) { - SFUD_INFO("Error: Flash write SPI communicate error."); - goto __exit; - } - result = wait_busy(flash); - if (result != SFUD_SUCCESS) { - goto __exit; - } - data += data_size; - } - -__exit: - /* set the flash write disable */ - set_write_enabled(flash, false); - /* unlock SPI */ - if (spi->unlock) { - spi->unlock(spi); - } - - return result; -} - -/** - * write flash data (no erase operate) for auto address increment mode - * - * If the address is odd number, it will place one 0xFF before the start of data for protect the old data. - * If the latest remain size is 1, it will append one 0xFF at the end of data for protect the old data. - * - * @param flash flash device - * @param addr start address - * @param size write size - * @param data write data - * - * @return result - */ -static sfud_err aai_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[8], cmd_size; - bool first_write = true; - - SFUD_ASSERT(flash); - SFUD_ASSERT(flash->init_ok); - /* check the flash address bound */ - if (addr + size > flash->chip.capacity) { - SFUD_INFO("Error: Flash address is out of bound."); - return SFUD_ERR_ADDR_OUT_OF_BOUND; - } - /* lock SPI */ - if (spi->lock) { - spi->lock(spi); - } - /* The address must be even for AAI write mode. So it must write one byte first when address is odd. */ - if (addr % 2 != 0) { - result = page256_or_1_byte_write(flash, addr++, 1, 1, data++); - if (result != SFUD_SUCCESS) { - goto __exit; - } - size--; - } - /* set the flash write enable */ - result = set_write_enabled(flash, true); - if (result != SFUD_SUCCESS) { - goto __exit; - } - /* loop write operate. */ - cmd_data[0] = SFUD_CMD_AAI_WORD_PROGRAM; - while (size >= 2) { - if (first_write) { - make_adress_byte_array(flash, addr, &cmd_data[1]); - cmd_size = flash->addr_in_4_byte ? 5 : 4; - cmd_data[cmd_size] = *data; - cmd_data[cmd_size + 1] = *(data + 1); - first_write = false; - } else { - cmd_size = 1; - cmd_data[1] = *data; - cmd_data[2] = *(data + 1); - } - - result = spi->wr(spi, cmd_data, cmd_size + 2, NULL, 0); - if (result != SFUD_SUCCESS) { - SFUD_INFO("Error: Flash write SPI communicate error."); - goto __exit; - } - - result = wait_busy(flash); - if (result != SFUD_SUCCESS) { - goto __exit; - } - - size -= 2; - addr += 2; - data += 2; - } - /* set the flash write disable for exit AAI mode */ - result = set_write_enabled(flash, false); - /* write last one byte data when origin write size is odd */ - if (result == SFUD_SUCCESS && size == 1) { - result = page256_or_1_byte_write(flash, addr, 1, 1, data); - } - -__exit: - if (result != SFUD_SUCCESS) { - set_write_enabled(flash, false); - } - /* unlock SPI */ - if (spi->unlock) { - spi->unlock(spi); - } - - return result; -} - -/** - * write flash data (no erase operate) - * - * @param flash flash device - * @param addr start address - * @param size write size - * @param data write data - * - * @return result - */ -sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data) { - sfud_err result = SFUD_SUCCESS; - - if (flash->chip.write_mode & SFUD_WM_PAGE_256B) { - result = page256_or_1_byte_write(flash, addr, size, 256, data); - } else if (flash->chip.write_mode & SFUD_WM_AAI) { - result = aai_write(flash, addr, size, data); - } else if (flash->chip.write_mode & SFUD_WM_DUAL_BUFFER) { - //TODO dual-buffer write mode - } - - return result; -} - -/** - * erase and write flash data - * - * @param flash flash device - * @param addr start address - * @param size write size - * @param data write data - * - * @return result - */ -sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data) { - sfud_err result = SFUD_SUCCESS; - - result = sfud_erase(flash, addr, size); - - if (result == SFUD_SUCCESS) { - result = sfud_write(flash, addr, size, data); - } - - return result; -} - -static sfud_err reset(const sfud_flash *flash) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[2]; - - SFUD_ASSERT(flash); - - cmd_data[0] = SFUD_CMD_ENABLE_RESET; - result = spi->wr(spi, cmd_data, 1, NULL, 0); - if (result == SFUD_SUCCESS) { - result = wait_busy(flash); - } else { - SFUD_INFO("Error: Flash device reset failed."); - return result; - } - - cmd_data[1] = SFUD_CMD_RESET; - result = spi->wr(spi, &cmd_data[1], 1, NULL, 0); - - if (result == SFUD_SUCCESS) { - result = wait_busy(flash); - } - - if (result == SFUD_SUCCESS) { - SFUD_DEBUG("Flash device reset success."); - } else { - SFUD_INFO("Error: Flash device reset failed."); - } - - return result; -} - -static sfud_err read_jedec_id(sfud_flash *flash) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[1], recv_data[3]; - - SFUD_ASSERT(flash); - - cmd_data[0] = SFUD_CMD_JEDEC_ID; - result = spi->wr(spi, cmd_data, sizeof(cmd_data), recv_data, sizeof(recv_data)); - if (result == SFUD_SUCCESS) { - flash->chip.mf_id = recv_data[0]; - flash->chip.type_id = recv_data[1]; - flash->chip.capacity_id = recv_data[2]; - SFUD_DEBUG("The flash device manufacturer ID is 0x%02X, memory type ID is 0x%02X, capacity ID is 0x%02X.", - flash->chip.mf_id, flash->chip.type_id, flash->chip.capacity_id); - } else { - SFUD_INFO("Error: Read flash device JEDEC ID error."); - } - - return result; -} - -/** - * set the flash write enable or write disable - * - * @param flash flash device - * @param enabled true: enable false: disable - * - * @return result - */ -static sfud_err set_write_enabled(const sfud_flash *flash, bool enabled) { - sfud_err result = SFUD_SUCCESS; - uint8_t cmd, register_status; - - SFUD_ASSERT(flash); - - if (enabled) { - cmd = SFUD_CMD_WRITE_ENABLE; - } else { - cmd = SFUD_CMD_WRITE_DISABLE; - } - - result = flash->spi.wr(&flash->spi, &cmd, 1, NULL, 0); - - if (result == SFUD_SUCCESS) { - result = sfud_read_status(flash, ®ister_status); - } - - if (result == SFUD_SUCCESS) { - if (enabled && (register_status & SFUD_STATUS_REGISTER_WEL) == 0) { - SFUD_ERROR("Error: Can't enable write status."); - return SFUD_ERR_WRITE; - } else if (!enabled && (register_status & SFUD_STATUS_REGISTER_WEL) != 0) { - SFUD_ERROR("Error: Can't disable write status."); - return SFUD_ERR_WRITE; - } - } - - return result; -} - -/** - * enable or disable 4-Byte addressing for flash - * - * @note The 4-Byte addressing just supported for the flash capacity which is large then 16MB (256Mb). - * - * @param flash flash device - * @param enabled true: enable false: disable - * - * @return result - */ -static sfud_err set_4_byte_address_mode(sfud_flash *flash, bool enabled) { - sfud_err result = SFUD_SUCCESS; - uint8_t cmd; - - SFUD_ASSERT(flash); - - /* set the flash write enable */ - result = set_write_enabled(flash, true); - if (result != SFUD_SUCCESS) { - return result; - } - - if (enabled) { - cmd = SFUD_CMD_ENTER_4B_ADDRESS_MODE; - } else { - cmd = SFUD_CMD_EXIT_4B_ADDRESS_MODE; - } - - result = flash->spi.wr(&flash->spi, &cmd, 1, NULL, 0); - - if (result == SFUD_SUCCESS) { - flash->addr_in_4_byte = enabled ? true : false; - SFUD_DEBUG("%s 4-Byte addressing mode success.", enabled ? "Enter" : "Exit"); - } else { - SFUD_INFO("Error: %s 4-Byte addressing mode failed.", enabled ? "Enter" : "Exit"); - } - - return result; -} - -/** - * read flash register status - * - * @param flash flash device - * @param status register status - * - * @return result - */ -sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status) { - uint8_t cmd = SFUD_CMD_READ_STATUS_REGISTER; - - SFUD_ASSERT(flash); - SFUD_ASSERT(status); - - return flash->spi.wr(&flash->spi, &cmd, 1, status, 1); -} - -static sfud_err wait_busy(const sfud_flash *flash) { - sfud_err result = SFUD_SUCCESS; - uint8_t status; - size_t retry_times = flash->retry.times; - - SFUD_ASSERT(flash); - - while (true) { - result = sfud_read_status(flash, &status); - if (result == SFUD_SUCCESS && ((status & SFUD_STATUS_REGISTER_BUSY)) == 0) { - break; - } - /* retry counts */ - SFUD_RETRY_PROCESS(flash->retry.delay, retry_times, result); - } - - if (result != SFUD_SUCCESS || ((status & SFUD_STATUS_REGISTER_BUSY)) != 0) { - SFUD_ERROR("Error: Flash wait busy has an error: %d, status: 0x%x, retries: %ld ", - result, status, flash->retry.times); - } - - return result; -} - -static void make_adress_byte_array(const sfud_flash *flash, uint32_t addr, uint8_t *array) { - uint8_t len, i; - - SFUD_ASSERT(flash); - SFUD_ASSERT(array); - - len = flash->addr_in_4_byte ? 4 : 3; - for (i = 0; i < len; i++) - { - array[i] = (addr >> ((len - (i + 1)) * 8)) & 0xFF; - } -} - -/** - * write status register - * - * @param flash flash device - * @param is_volatile true: volatile mode, false: non-volatile mode - * @param status register status - * - * @return result - */ -sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status) { - sfud_err result = SFUD_SUCCESS; - const sfud_spi *spi = &flash->spi; - uint8_t cmd_data[2]; - - SFUD_ASSERT(flash); - - if (is_volatile) { - cmd_data[0] = SFUD_VOLATILE_SR_WRITE_ENABLE; - result = spi->wr(spi, cmd_data, 1, NULL, 0); - } else { - result = set_write_enabled(flash, true); - } - - if (result == SFUD_SUCCESS) { - cmd_data[0] = SFUD_CMD_WRITE_STATUS_REGISTER; - cmd_data[1] = status; - result = spi->wr(spi, cmd_data, 2, NULL, 0); - } - - if (result != SFUD_SUCCESS) { - SFUD_INFO("Error: Write_status register failed."); - } - - return result; -} diff --git a/third-party/sfud-1.1.0/src/sfud_sfdp.c b/third-party/sfud-1.1.0/src/sfud_sfdp.c deleted file mode 100644 index 3e3d3e52ce60b2e6488a41ae1b8b1cd48509ff3a..0000000000000000000000000000000000000000 --- a/third-party/sfud-1.1.0/src/sfud_sfdp.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - * This file is part of the Serial Flash Universal Driver Library. - * - * Copyright (c) 2016, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Analyze the SFDP (Serial Flash Discoverable Parameters) which from JESD216/A/B (V1.X) standard. - * JESD216 (V1.0) document: http://www.jedec.org/sites/default/files/docs/JESD216.pdf - * JESD216A (V1.5) document: http://www.jedec.org/sites/default/files/docs/JESD216A.pdf - * JESD216B (V1.6) document: http://www.jedec.org/sites/default/files/docs/JESD216B.pdf - * - * Created on: 2016-05-26 - */ - -#include "sfud.h" - -/** - * JEDEC Standard JESD216 Terms and definitions: - * - * DWORD: Four consecutive 8-bit bytes used as the basic 32-bit building block for headers and parameter tables. - * - * Sector: The minimum granularity - size and alignment - of an area that can be erased in the data array - * of a flash memory device. Different areas within the address range of the data array may have a different - * minimum erase granularity (sector size). - */ - -#ifdef SFUD_USING_SFDP - -/* support maximum SFDP major revision by driver */ -#define SUPPORT_MAX_SFDP_MAJOR_REV 1 -/* the JEDEC basic flash parameter table length is 9 DWORDs (288-bit) on JESD216 (V1.0) initial release standard */ -#define BASIC_TABLE_LEN 9 -/* the smallest eraser in SFDP eraser table */ -#define SMALLEST_ERASER_INDEX 0 -/** - * SFDP parameter header structure - */ -typedef struct { - uint8_t id; /**< Parameter ID LSB */ - uint8_t minor_rev; /**< Parameter minor revision */ - uint8_t major_rev; /**< Parameter major revision */ - uint8_t len; /**< Parameter table length(in double words) */ - uint32_t ptp; /**< Parameter table 24bit pointer (byte address) */ -} sfdp_para_header; - -static sfud_err read_sfdp_data(const sfud_flash *flash, uint32_t addr, uint8_t *read_buf, size_t size); -static bool read_sfdp_header(sfud_flash *flash); -static bool read_basic_header(const sfud_flash *flash, sfdp_para_header *basic_header); -static bool read_basic_table(sfud_flash *flash, sfdp_para_header *basic_header); - -/* ../port/sfup_port.c */ -extern void sfud_log_debug(const char *file, const long line, const char *format, ...); -extern void sfud_log_info(const char *format, ...); - -/** - * Read SFDP parameter information - * - * @param flash flash device - * - * @return true: read OK - */ -bool sfud_read_sfdp(sfud_flash *flash) { - SFUD_ASSERT(flash); - - /* JEDEC basic flash parameter header */ - sfdp_para_header basic_header; - if (read_sfdp_header(flash) && read_basic_header(flash, &basic_header)) { - return read_basic_table(flash, &basic_header); - } else { - SFUD_WARN("Warning: Read SFDP parameter header information failed. The %s is not support JEDEC SFDP.", flash->name); - return false; - } -} - -/** - * Read SFDP parameter header - * - * @param flash flash device - * - * @return true: read OK - */ -static bool read_sfdp_header(sfud_flash *flash) { - sfud_sfdp *sfdp = &flash->sfdp; - /* The SFDP header is located at address 000000h of the SFDP data structure. - * It identifies the SFDP Signature, the number of parameter headers, and the SFDP revision numbers. */ - /* sfdp parameter header address */ - uint32_t header_addr = 0; - /* each parameter header being 2 DWORDs (64-bit) */ - uint8_t header[2 * 4] = { 0 }; - - SFUD_ASSERT(flash); - - sfdp->available = false; - /* read SFDP header */ - if (read_sfdp_data(flash, header_addr, header, sizeof(header)) != SFUD_SUCCESS) { - SFUD_INFO("Error: Can't read SFDP header."); - return false; - } - /* check SFDP header */ - if (!(header[0] == 'S' && - header[1] == 'F' && - header[2] == 'D' && - header[3] == 'P')) { - SFUD_DEBUG("Error: Check SFDP signature error. It's must be 50444653h('S' 'F' 'D' 'P')."); - return false; - } - sfdp->minor_rev = header[4]; - sfdp->major_rev = header[5]; - if (sfdp->major_rev > SUPPORT_MAX_SFDP_MAJOR_REV) { - SFUD_INFO("Error: This reversion(V%d.%d) SFDP is not supported.", sfdp->major_rev, sfdp->minor_rev); - return false; - } - SFUD_DEBUG("Check SFDP header is OK. The reversion is V%d.%d, NPN is %d.", sfdp->major_rev, sfdp->minor_rev, - header[6]); - - return true; -} - -/** - * Read JEDEC basic parameter header - * - * @param flash flash device - * - * @return true: read OK - */ -static bool read_basic_header(const sfud_flash *flash, sfdp_para_header *basic_header) { - /* The basic parameter header is mandatory, is defined by this standard, and starts at byte offset 08h. */ - uint32_t header_addr = 8; - /* each parameter header being 2 DWORDs (64-bit) */ - uint8_t header[2 * 4] = { 0 }; - - SFUD_ASSERT(flash); - SFUD_ASSERT(basic_header); - - /* read JEDEC basic flash parameter header */ - if (read_sfdp_data(flash, header_addr, header, sizeof(header)) != SFUD_SUCCESS) { - SFUD_INFO("Error: Can't read JEDEC basic flash parameter header."); - return false; - } - basic_header->id = header[0]; - basic_header->minor_rev = header[1]; - basic_header->major_rev = header[2]; - basic_header->len = header[3]; - basic_header->ptp = (long)header[4] | (long)header[5] << 8 | (long)header[6] << 16; - /* check JEDEC basic flash parameter header */ - if (basic_header->major_rev > SUPPORT_MAX_SFDP_MAJOR_REV) { - SFUD_INFO("Error: This reversion(V%d.%d) JEDEC basic flash parameter header is not supported.", - basic_header->major_rev, basic_header->minor_rev); - return false; - } - if (basic_header->len < BASIC_TABLE_LEN) { - SFUD_INFO("Error: The JEDEC basic flash parameter table length (now is %d) error.", basic_header->len); - return false; - } - SFUD_DEBUG("Check JEDEC basic flash parameter header is OK. The table id is %d, reversion is V%d.%d," - " length is %d, parameter table pointer is 0x%06lX.", basic_header->id, basic_header->major_rev, - basic_header->minor_rev, basic_header->len, basic_header->ptp); - - return true; -} - -/** - * Read JEDEC basic parameter table - * - * @param flash flash device - * - * @return true: read OK - */ -static bool read_basic_table(sfud_flash *flash, sfdp_para_header *basic_header) { - sfud_sfdp *sfdp = &flash->sfdp; - /* parameter table address */ - uint32_t table_addr = basic_header->ptp; - /* parameter table */ - uint8_t table[BASIC_TABLE_LEN * 4] = { 0 }, i, j; - - SFUD_ASSERT(flash); - SFUD_ASSERT(basic_header); - - /* read JEDEC basic flash parameter table */ - if (read_sfdp_data(flash, table_addr, table, sizeof(table)) != SFUD_SUCCESS) { - SFUD_INFO("Warning: Can't read JEDEC basic flash parameter table."); - return false; - } - /* print JEDEC basic flash parameter table info */ - SFUD_DEBUG("JEDEC basic flash parameter table info:"); - SFUD_DEBUG("MSB-LSB 3 2 1 0"); - for (i = 0; i < BASIC_TABLE_LEN; i++) { - SFUD_DEBUG("[%04d] 0x%02X 0x%02X 0x%02X 0x%02X", i + 1, table[i * 4 + 3], table[i * 4 + 2], table[i * 4 + 1], - table[i * 4]); - } - - /* get block/sector 4 KB erase supported and command */ - sfdp->erase_4k_cmd = table[1]; - switch (table[0] & 0x03) { - case 1: - sfdp->erase_4k = true; - SFUD_DEBUG("4 KB Erase is supported throughout the device. Command is 0x%02X.", sfdp->erase_4k_cmd); - break; - case 3: - sfdp->erase_4k = false; - SFUD_DEBUG("Uniform 4 KB erase is unavailable for this device."); - break; - default: - SFUD_INFO("Error: Uniform 4 KB erase supported information error."); - return false; - } - /* get write granularity */ - //TODO 目前为 1.0 所提供的方式,后期支持 V1.5 及以上的方式读取 page size - switch ((table[0] & (0x01 << 2)) >> 2) { - case 0: - sfdp->write_gran = 1; - SFUD_DEBUG("Write granularity is 1 byte."); - break; - case 1: - sfdp->write_gran = 256; - SFUD_DEBUG("Write granularity is 64 bytes or larger."); - break; - } - /* volatile status register block protect bits */ - switch ((table[0] & (0x01 << 3)) >> 3) { - case 0: - /* Block Protect bits in device's status register are solely non-volatile or may be - * programmed either as volatile using the 50h instruction for write enable or non-volatile - * using the 06h instruction for write enable. - */ - sfdp->sr_is_non_vola = true; - SFUD_DEBUG("Target flash status register is non-volatile."); - break; - case 1: - /* block protect bits in device's status register are solely volatile. */ - sfdp->sr_is_non_vola = false; - SFUD_DEBUG("Block Protect bits in device's status register are solely volatile."); - /* write enable instruction select for writing to volatile status register */ - switch ((table[0] & (0x01 << 4)) >> 4) { - case 0: - sfdp->vola_sr_we_cmd = SFUD_VOLATILE_SR_WRITE_ENABLE; - SFUD_DEBUG("Flash device requires instruction 50h as the write enable prior " - "to performing a volatile write to the status register."); - break; - case 1: - sfdp->vola_sr_we_cmd = SFUD_CMD_WRITE_ENABLE; - SFUD_DEBUG("Flash device requires instruction 06h as the write enable prior " - "to performing a volatile write to the status register."); - break; - } - break; - } - /* get address bytes, number of bytes used in addressing flash array read, write and erase. */ - switch ((table[2] & (0x03 << 1)) >> 1) { - case 0: - sfdp->addr_3_byte = true; - sfdp->addr_4_byte = false; - SFUD_DEBUG("3-Byte only addressing."); - break; - case 1: - sfdp->addr_3_byte = true; - sfdp->addr_4_byte = true; - SFUD_DEBUG("3- or 4-Byte addressing."); - break; - case 2: - sfdp->addr_3_byte = false; - sfdp->addr_4_byte = true; - SFUD_DEBUG("4-Byte only addressing."); - break; - default: - sfdp->addr_3_byte = false; - sfdp->addr_4_byte = false; - SFUD_INFO("Error: Read address bytes error!"); - return false; - } - /* get flash memory capacity */ - uint32_t table2_temp = ((long)table[7] << 24) | ((long)table[6] << 16) | ((long)table[5] << 8) | (long)table[4]; - switch ((table[7] & (0x01 << 7)) >> 7) { - case 0: - sfdp->capacity = 1 + (table2_temp >> 3); - break; - case 1: - table2_temp &= 0x7FFFFFFF; - if (table2_temp > sizeof(sfdp->capacity) * 8 + 3) { - sfdp->capacity = 0; - SFUD_INFO("Error: The flash capacity is grater than 32 Gb/ 4 GB! Not Supported."); - return false; - } - sfdp->capacity = 1L << (table2_temp - 3); - break; - } - SFUD_DEBUG("Capacity is %ld Bytes.", sfdp->capacity); - /* get erase size and erase command */ - for (i = 0, j = 0; i < SFUD_SFDP_ERASE_TYPE_MAX_NUM; i++) { - if (table[28 + 2 * i] != 0x00) { - sfdp->eraser[j].size = 1L << table[28 + 2 * i]; - sfdp->eraser[j].cmd = table[28 + 2 * i + 1]; - SFUD_DEBUG("Flash device supports %ldKB block erase. Command is 0x%02X.", sfdp->eraser[j].size / 1024, - sfdp->eraser[j].cmd); - j++; - } - } - /* sort the eraser size from small to large */ - for (i = 0, j = 0; i < SFUD_SFDP_ERASE_TYPE_MAX_NUM; i++) { - if (sfdp->eraser[i].size) { - for (j = i + 1; j < SFUD_SFDP_ERASE_TYPE_MAX_NUM; j++) { - if (sfdp->eraser[j].size != 0 && sfdp->eraser[i].size > sfdp->eraser[j].size) { - /* swap the small eraser */ - uint32_t temp_size = sfdp->eraser[i].size; - uint8_t temp_cmd = sfdp->eraser[i].cmd; - sfdp->eraser[i].size = sfdp->eraser[j].size; - sfdp->eraser[i].cmd = sfdp->eraser[j].cmd; - sfdp->eraser[j].size = temp_size; - sfdp->eraser[j].cmd = temp_cmd; - } - } - } - } - - sfdp->available = true; - return true; -} - -static sfud_err read_sfdp_data(const sfud_flash *flash, uint32_t addr, uint8_t *read_buf, size_t size) { - uint8_t cmd[] = { - SFUD_CMD_READ_SFDP_REGISTER, - (addr >> 16) & 0xFF, - (addr >> 8) & 0xFF, - (addr >> 0) & 0xFF, - SFUD_DUMMY_DATA, - }; - - SFUD_ASSERT(flash); - SFUD_ASSERT(addr < 1L << 24); - SFUD_ASSERT(read_buf); - SFUD_ASSERT(flash->spi.wr); - - return flash->spi.wr(&flash->spi, cmd, sizeof(cmd), read_buf, size); -} - -/** - * get the most suitable eraser for erase process from SFDP parameter - * - * @param flash flash device - * @param addr start address - * @param erase_size will be erased size - * - * @return the eraser index of SFDP eraser table @see sfud_sfdp.eraser[] - */ -size_t sfud_sfdp_get_suitable_eraser(const sfud_flash *flash, uint32_t addr, size_t erase_size) { - size_t index = SMALLEST_ERASER_INDEX, i; - /* only used when flash supported SFDP */ - SFUD_ASSERT(flash->sfdp.available); - /* the address isn't align by smallest eraser's size, then use the smallest eraser */ - if (addr % flash->sfdp.eraser[SMALLEST_ERASER_INDEX].size) { - return SMALLEST_ERASER_INDEX; - } - /* Find the suitable eraser. - * The largest size eraser is at the end of eraser table. - * In order to decrease erase command counts, so the find process is from the end of eraser table. */ - for (i = SFUD_SFDP_ERASE_TYPE_MAX_NUM - 1;; i--) { - if ((flash->sfdp.eraser[i].size != 0) && (erase_size >= flash->sfdp.eraser[i].size) - && (addr % flash->sfdp.eraser[i].size == 0)) { - index = i; - break; - } - if (i == SMALLEST_ERASER_INDEX) { - break; - } - } - return index; -} - -#endif /* SFUD_USING_SFDP */ diff --git a/third-party/spiffs-0.3.7/config.md b/third-party/spiffs-0.3.7/config.md index 50d96b4de9167b16eaa548b5ba70f12efaea72a2..1fe9cd13f5d19eaee56d9a058c6c58784a95a3aa 100644 --- a/third-party/spiffs-0.3.7/config.md +++ b/third-party/spiffs-0.3.7/config.md @@ -1,14 +1,14 @@ # SPIFFS文件系统移植配置解释 移植SPIFFS过程中需要对其文件目录`spiffs-0.3.7\src\default`下`spiffs_config.h`配置文件进行一定修改,来使其适配不同的应用环境。本文档介绍飞腾FreeTROS环境下SPIFFS的相关配置。 -####github +### github 在github上有wiki说明SPIFFS相关配置信息: - http://github.com/pellepl/spiffs/wiki SPIFFS技术手册: - http://blog.csdn.net/zhangjinxing_2006/article/details/75050611 -####重要移植概述 +### 重要移植概述 在SPIFFS暴露的配置中,由许多是不需要修改的。在用户移植的过程中,可以参考如下配置设置。 #####基础函数库配置 ``` @@ -34,7 +34,7 @@ SPIFFS技术手册: ``` 在一系列C语言库函数后,我们加入了飞腾的定义库`"ft_types.h"`与debug库`"ft_debug.h"` -#####Debug方式 +#### Debug方式 使用飞腾定义好的debug方法 ``` // port debug printfs @@ -59,7 +59,7 @@ SPIFFS技术手册: #define SPIFFS_API_DBG(_f, ...) FT_DEBUG_PRINT_D("SPIFFS-API", _f, ##__VA_ARGS__) #endif ``` -#####Cache配置 +#### Cache配置 如果启用Cache缓存机制,会大大加速执行速度,但是必须为SPIFFS提供额外的RAM内存。强烈建议打开`SPIFFS_CACHE_WR`选项,这个选项会使得写入flash的数据进入缓存区,多次得到写入的数据后,再一次性写入flash。如果没有打开这个选项,所有对flash的写入都是直接的,这样会使得flash寿命减少。 ``` // Enables/disable memory read caching of nucleus file system operations. @@ -93,7 +93,7 @@ SPIFFS技术手册: ``` -#####基本flash信息配置 +#### 基本flash信息配置 飞腾不止使用单个SPIFFS实例,故将`SPIFFS_SINGLETON`设为0。并且不需要预设flash信息为某一固定值,通过其他模块的接口,可以实现读取装在SPIM上的flash信息。对于一般用户来说,可以将此选项打开,并直接在SPIFFS层面设置好相关配置。 ``` #ifndef SPIFFS_SINGLETON @@ -127,7 +127,7 @@ SPIFFS技术手册: #endif ``` 如果不能正确配置这些类型,可能会由溢出和一堆其他问题造成死循环。在您无法弄清楚文件系统的需求配置时,可以选择将容量设置稍大一点,因为如果设置得太小,会导致更加严重的后果。 -#####flash文件系统检查 +#### flash文件系统检查 打开flash检查magic开关,设置启用按文件系统长度来检查flash配置,保证flash配置符合SPIFFS要求,如果进一步打开`SPIFFS_USE_MAGIC_LENGTH`,则会进一步比较挂载文件系统与flash配置长度是否一致。 ``` #ifndef SPIFFS_USE_MAGIC @@ -147,7 +147,7 @@ SPIFFS技术手册: #endif ``` -#####上锁操作 +#### 上锁操作 为了适配FreeRTOS这种多任务的实时操作系统,需要打开SPIFFS的上锁功能开关,并将写好的上锁和解锁接口告诉SPIFFS。 ``` extern void FSpiffsSemLock(void); @@ -178,7 +178,7 @@ void FSpiffsSemUnlock(void) xSemaphoreGive(xSpiffsSemaphore); } ``` -#####读写函数接口 +#### 读写函数接口 在创建的SPIFFS文件系统config实例中,需要添加读写文件与擦除数据的操作 ``` static const spiffs_config cfg = diff --git a/third-party/third-party.mk b/third-party/third-party.mk index 7b25d263e31ae9321bc070e5d0510389167f3af4..fdef814f3e7ae3e0914875cd3c60dae6072d0cb0 100644 --- a/third-party/third-party.mk +++ b/third-party/third-party.mk @@ -123,24 +123,7 @@ endif #CONFIG_USE_FATFS_0_1_4 ifdef CONFIG_USE_SFUD -# $(shell export PATH=$(THIRD_PARTY_CUR_DIR)/sfud:$PATH) - - INC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0 \ - $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/inc \ - $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports - SRC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0 \ - $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/src \ - $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports - - ifdef CONFIG_SFUD_CTRL_FSPIM - INC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fspim - SRC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fspim - endif - - ifdef CONFIG_SFUD_CTRL_FQSPI - INC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fqspi - SRC_DIR += $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/ports/fqspi - endif +include $(THIRD_PARTY_CUR_DIR)/sfud-1.1.0/sfud.mk endif #CONFIG_USE_SFUD @@ -200,7 +183,7 @@ endif #CONFIG_USE_SDMMC_CMD ifdef CONFIG_USE_CHERRY_USB -include $(THIRD_PARTY_CUR_DIR)/cherryusb-0.6.0/makefile +include $(THIRD_PARTY_CUR_DIR)/cherryusb-0.7.0/makefile endif #CONFIG_USE_CHERRY_USB