diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..fcb5b0741f27b95c7a12d1cfdb4171cc77aeb782 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,19 @@ +# Phytium Iot gitlab-ci.yml file + +stages: + - basic_stage + +risk_controller: + stage: basic_stage + tags: + - normal_runner + script: + - pwd + - echo "Phytium Changsha Iot Gitlab Runner is at work." + - echo "This job only run manually to prevent merge request from not being reviewed by Jenkins pipeline." + - echo "Approve merge request to start Jenkins auto compile item." + - sleep 10 # 这个延时是为了让操作者明确知道自己已经开启了这项操作; + - exit 1 # 这个任务一定会失败,目的是保护被合入的分支 + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + when: manual \ No newline at end of file diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index ebe84f9e24f9bec02d032a5a3c9ad215050b561e..0334c420990adc111acbe66837197a5d9c65b3e9 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -1,3 +1,23 @@ +# Phytium FreeRTOS SDK 2024-04-19 ChangeLog + +Change Log since 2024-04-19 + +## drivers + +- modify pwm drivers + +# Phytium FreeRTOS SDK 2024-04-17 ChangeLog + +Change Log since 2024-04-17 + +- Refactoring peripheral spi example + +# Phytium FreeRTOS SDK 2024-04-15 ChangeLog + +Change Log since 2024-04-10 + +- add gitlab-ci.yml file to trigger gitlab CI/CD tool + # Phytium FreeRTOS SDK 2024-04-10 ChangeLog Change Log since 2024-04-10 diff --git a/drivers/pwm/fpwm_os.c b/drivers/pwm/fpwm_os.c index b418a2431abb4446297bac46ca1437185a96b2ac..1d6e0674702a92f32354c00dde9d1387817f6ad4 100644 --- a/drivers/pwm/fpwm_os.c +++ b/drivers/pwm/fpwm_os.c @@ -287,6 +287,7 @@ FError FFreeRTOSPwmPulseSet(FFreeRTOSPwm *os_pwm_p, u8 channel, u16 pulse) FFreeRTOSPwmConfig configuration = {0}; configuration.pwm_cfg.pwm_pulse = pulse; + configuration.channel = channel; ret = FFreeRTOSPwmControl(os_pwm_p, FREERTOS_PWM_CTRL_PULSE_SET, &configuration); return ret; diff --git a/example/peripheral/pwm/README.md b/example/peripheral/pwm/README.md index ae1bf7c524aa3533d0f7f529cac68362fe9b2e5a..91f14ad15356b9c6e6086a18a975ea7f070a21ef 100644 --- a/example/peripheral/pwm/README.md +++ b/example/peripheral/pwm/README.md @@ -6,9 +6,7 @@ 程序启动后,创建pwm初始化任务,设置pwm时钟分频、周期和占空比等; 创建pwm占空比变化任务FFreeRTOSPwmChangeTask,用于定时变化pwm占空比; 创建单次模式的软件定时器,回调函数为删除FFreeRTOSPwmChangeTask,去初始化pwm,删除软件定时器; -使用E2000D/E2000Q demo板进行测试,选择pwm模块6的pwm12_dat_out作为输出,对应开发板上J30引脚7 -使用C板进行测试,选择pwm模块7的两路pwm_out,也就是pwm14和pwm15作为输出,对应开发板上J152的引脚18和引脚20; -使用PhytiumPi进行测试,选择pwm模块2的pwm5_dat_out作为输出,对应开发板上J1引脚33 +注:E2000共有8个PWM控制器(PWM0~PWM7),每个PWM控制器对应两路CHANNEL ## 2. 如何使用例程 @@ -33,6 +31,8 @@ ### 2.1.1 E2000 - E2000 demo板需外接逻辑分析仪或示波器测试,方法如下 +- 选择控制器PWM6的pwm12_dat_out(CHANNEL0)作为输出,对应开发板上J30引脚7 + ![e2000_pwm](./figs/e2000_pwm.png) - 上图所示为E2000 J30组引脚,将pwm_out与GND与逻辑分析仪或示波器相连即可 @@ -40,9 +40,22 @@ ### 2.1.2 PhytiumPi - PhytiumPi需外接逻辑分析仪或示波器测试,方法如下 +- PhytiumPI:飞腾派引出多个引脚可供PWM使用 + ![phytiumpi_pwm](./figs/phytiumpi_pwm.png) --上图为PhytiumPi J1组引脚,第33号引脚为pwm(红色标记处)输出引脚,39号引脚(蓝色标记处)为GND,将该引脚与逻辑分析仪或示波器相连即可 +PhytiumPI:飞腾派引出多个引脚可供PWM使用 + +| **引脚** | **控制器与通道** | +| :----------: | :----------------- | +| J1 PIN_32 | PWM1 CHANNEL0 | +| J1 PIN_33 | PWM2 CHANNEL1 | +| J1 PIN_7 | PWM3 CHANNEL0 | +| J2 PIN_4 | PWM3 CHANNEL1 | +| J1 PIN_3 | PWM4 CHANNEL0 | +| J1 PIN_8 | PWM4 CHANNEL1 | +| J1 PIN_16 | PWM5 CHANNEL0 | +| J1 PIN_27 | PWM6 CHANNEL1 | ### 2.2 SDK配置方法 @@ -107,7 +120,9 @@ bootelf -p 0x90100000 ![pwm_out](./figs/pwm_out.png) ## 3. 如何解决问题 -- 若不想使能死区输出,可将FFreeRTOSPwmDbSet的部分去除,只需调用FFreeRTOSPwmSet即可。 +- 如默认用例无法使用或无波形输出,请根据不同的开发板,修改`pwm_example.h`文件中`PWM_TEST_ID`和`PWM_TEST_CHANNEL`两个宏定义,确保`FIOPadSetPwmMux`引脚复用设置正确 + +- `PWM_TEST_CHANNEL`决定死区输入源,另一个CHANNEL作为输出源。若不想使能死区输出,可将FFreeRTOSPwmDbSet的部分去除,只需调用FFreeRTOSPwmSet即 可。 ## 4. 修改历史记录 diff --git a/example/peripheral/pwm/figs/phytiumpi_pwm.png b/example/peripheral/pwm/figs/phytiumpi_pwm.png index 033e80f72cc2b1fae9e492e3e07737be7bf0b2f0..c31475e90c23c77707c53f4c6c3875b433a61a57 100644 Binary files a/example/peripheral/pwm/figs/phytiumpi_pwm.png and b/example/peripheral/pwm/figs/phytiumpi_pwm.png differ diff --git a/example/peripheral/pwm/inc/pwm_example.h b/example/peripheral/pwm/inc/pwm_example.h index 14a587013de0e51440bba6d58df4c337e57e66d8..fd7b5c49f6c49dcf720bf3f57ecd133d5f68b137 100644 --- a/example/peripheral/pwm/inc/pwm_example.h +++ b/example/peripheral/pwm/inc/pwm_example.h @@ -33,8 +33,10 @@ extern "C" #if defined(CONFIG_TARGET_E2000D)||defined(CONFIG_TARGET_E2000Q) #define PWM_TEST_ID FPWM6_ID +#define PWM_TEST_CHANNEL FPWM_CHANNEL_0 #elif defined(CONFIG_TARGET_PHYTIUMPI) #define PWM_TEST_ID FPWM2_ID +#define PWM_TEST_CHANNEL FPWM_CHANNEL_1 #endif /* pwm test */ BaseType_t FFreeRTOSPwmCreate(u32 id); diff --git a/example/peripheral/pwm/src/pwm_example.c b/example/peripheral/pwm/src/pwm_example.c index 368186a99f32d483c7b65717b40b1740ac558cd2..17f264fd74359b4fe0d82b19efa24332422d93f3 100644 --- a/example/peripheral/pwm/src/pwm_example.c +++ b/example/peripheral/pwm/src/pwm_example.c @@ -40,9 +40,6 @@ /* pwm pulse amplitude of periodic variation */ #define PWM_PULSE_CHANGE 1000 -/* pwm channel use, 0/1 */ -#define PWM_CHANNEL_USE FPWM_CHANNEL_0 - /* pwm primary config */ #define PWM_DIV 500 #define PWM_PERIOD 10000 @@ -88,7 +85,8 @@ static void FFreeRTOSPwmInitTask(void *pvParameters) db_cfg.db_rise_cycle = 500; db_cfg.db_fall_cycle = 500; db_cfg.db_polarity_sel = FPWM_DB_AHC; - db_cfg.db_in_mode = FPWM_DB_IN_MODE_PWM0; + /*将死区输入源设置为当前测试使用的CHANNEL*/ + db_cfg.db_in_mode = PWM_TEST_CHANNEL == FPWM_CHANNEL_0 ? FPWM_DB_IN_MODE_PWM0 : FPWM_DB_IN_MODE_PWM1; db_cfg.db_out_mode = FPWM_DB_OUT_MODE_ENABLE_RISE_FALL; ret = FFreeRTOSPwmDbSet(os_pwm_ctrl_p, &db_cfg); if (FPWM_SUCCESS != ret) @@ -106,7 +104,7 @@ static void FFreeRTOSPwmInitTask(void *pvParameters) pwm_cfg.pwm_mode = FPWM_OUTPUT_COMPARE; pwm_cfg.pwm_polarity = FPWM_POLARITY_NORMAL; pwm_cfg.pwm_duty_source_mode = FPWM_DUTY_CCR; - ret = FFreeRTOSPwmSet(os_pwm_ctrl_p, PWM_CHANNEL_USE, &pwm_cfg); + ret = FFreeRTOSPwmSet(os_pwm_ctrl_p, PWM_TEST_CHANNEL, &pwm_cfg); if (FPWM_SUCCESS != ret) { printf("FFreeRTOSPwmSet failed.\n"); @@ -124,7 +122,7 @@ static void FFreeRTOSPwmInitTask(void *pvParameters) printf("db_cfg.db_in_mode = %d\n", db_cfg.db_in_mode); printf("db_cfg.db_out_mode = %d\n", db_cfg.db_out_mode); - FFreeRTOSPwmGet(os_pwm_ctrl_p, PWM_CHANNEL_USE, &pwm_cfg); + FFreeRTOSPwmGet(os_pwm_ctrl_p, PWM_TEST_CHANNEL, &pwm_cfg); printf("FPwmVariableGet:\n"); printf("pwm_cfg.tim_ctrl_mode = %d\n", pwm_cfg.tim_ctrl_mode); printf("pwm_cfg.tim_ctrl_div = %d\n", pwm_cfg.tim_ctrl_div); @@ -134,7 +132,7 @@ static void FFreeRTOSPwmInitTask(void *pvParameters) printf("pwm_cfg.pwm_polarity = %d\n", pwm_cfg.pwm_polarity); printf("pwm_cfg.pwm_duty_source_mode = %d\n", pwm_cfg.pwm_duty_source_mode); - FFreeRTOSPwmEnable(os_pwm_ctrl_p, PWM_CHANNEL_USE, TRUE); + FFreeRTOSPwmEnable(os_pwm_ctrl_p, PWM_TEST_CHANNEL, TRUE); printf("FFreeRTOSPwmInitTask execute successfully.\r\n"); @@ -155,7 +153,7 @@ static void FFreeRTOSPwmChangeTask(void *pvParameters) /* As per most tasks, this task is implemented in an infinite loop. */ for (;;) { - FFreeRTOSPwmPulseSet(os_pwm_ctrl_p, PWM_CHANNEL_USE, pwm_pulse); + FFreeRTOSPwmPulseSet(os_pwm_ctrl_p, PWM_TEST_CHANNEL, pwm_pulse); printf("FFreeRTOSPwmChangeTask run, pwm_pulse: %d\r\n", pwm_pulse); pwm_pulse = (pwm_pulse + PWM_PULSE_CHANGE) % PWM_PERIOD; @@ -244,7 +242,7 @@ BaseType_t FFreeRTOSPwmCreate(u32 id) static void FFreeRTOSPwmDelete(FFreeRTOSPwm *os_pwm_p) { BaseType_t xReturn = pdPASS; - FFreeRTOSPwmEnable(os_pwm_p, PWM_CHANNEL_USE, FALSE); + FFreeRTOSPwmEnable(os_pwm_p, PWM_TEST_CHANNEL, FALSE); FFreeRTOSPwmDeinit(os_pwm_p); if (change_handle) diff --git a/example/peripheral/spi/README.md b/example/peripheral/spi/README.md index 15c61bb2d96ee3854696125ab98a9536dba5ac2e..03a59a1a9d9e21a2084a6607ca4e8ecb7391204b 100644 --- a/example/peripheral/spi/README.md +++ b/example/peripheral/spi/README.md @@ -95,22 +95,12 @@ bootelf -p 0xa0100000 - 系统进入后,创建任务初始化sfud, 读取flash id信息 -``` -sf probe -``` - -![probe](./figs/probe.png) - - 初始化成功后,在flash的偏移量0x20位置,写入一段不带空格的连续字符串,如‘write-spi-nor-flash-from-freertos-sfud’ -``` -sf write 0x10 "write-spi-nor-flash-from-freertos-sfud" -``` - - 写入成功后,从flash的偏移量0x0开始,读取64个字节 ``` -sf read 0x0 +sf sfud_read_write ``` ![write read](./figs/wr_rd.png) diff --git a/example/peripheral/spi/figs/probe.png b/example/peripheral/spi/figs/probe.png deleted file mode 100644 index 5da9c408cd2c4f990093b72d57e08531778ba6c5..0000000000000000000000000000000000000000 Binary files a/example/peripheral/spi/figs/probe.png and /dev/null differ diff --git a/example/peripheral/spi/figs/wr_rd.png b/example/peripheral/spi/figs/wr_rd.png index a308c4fe85df23803b3f9fc9f7df6b82d249c8e9..ab32bfaddcb637b27c16bff6ee209cbc2457c26f 100644 Binary files a/example/peripheral/spi/figs/wr_rd.png and b/example/peripheral/spi/figs/wr_rd.png differ diff --git a/example/peripheral/spi/inc/sfud_read_write.h b/example/peripheral/spi/inc/sfud_read_write.h index b6e0ba1e9ddf5f3ad3aca9f2ee117c8b1ce9e7c3..bf23b8e279cf85670a456bbefc6d8357021b5e00 100644 --- a/example/peripheral/spi/inc/sfud_read_write.h +++ b/example/peripheral/spi/inc/sfud_read_write.h @@ -24,6 +24,8 @@ #ifndef SFUD_READ_WRITE_H #define SFUD_READ_WRITE_H +#include "ftypes.h" +#include "FreeRTOS.h" #ifdef __cplusplus extern "C" { @@ -40,9 +42,9 @@ extern "C" /************************** Function Prototypes ******************************/ /*****************************************************************************/ -BaseType_t FFreeRTOSSfudWrite(u32 in_chip_addr, const char *content); -BaseType_t FFreeRTOSSfudRead(u32 in_chip_addr); -BaseType_t FFreeRTOSSfudInit(void); +void SfudExampleTaskEntry(); + +void FFreeRTOSSfudWriteThenRead(); #ifdef __cplusplus } diff --git a/example/peripheral/spi/main.c b/example/peripheral/spi/main.c index 5a9258ce8dcf738f8f5f8e9a76bcd88a6535e567..81a8844b3aa0fa9798354c315d92fb6ba8c85a1d 100644 --- a/example/peripheral/spi/main.c +++ b/example/peripheral/spi/main.c @@ -22,36 +22,38 @@ * 1.0 zhugengyu 2022/8/26 first commit */ +#include +#include "sfud_read_write.h" +#include "FreeRTOS.h" +#include "task.h" + +#ifdef CONFIG_USE_LETTER_SHELL #include "shell.h" #include "shell_port.h" -#include +#endif int main(void) { - BaseType_t ret; - - printf("Entering into main function \r\n"); + BaseType_t ret = pdPASS;/* 定义一个创建信息返回值,默认为 pdPASS */ +#ifdef CONFIG_USE_LETTER_SHELL ret = LSUserShellTask() ; if (ret != pdPASS) { goto FAIL_EXIT; } - - /* - ret = FFreeRTOSSfudInit(); - if(ret != pdPASS) - goto FAIL_EXIT; - - ret = FFreeRTOSSfudWrite(0x20, "hello-sfud"); - if(ret != pdPASS) - goto FAIL_EXIT; - - ret = FFreeRTOSSfudRead(0x20); - if(ret != pdPASS) - goto FAIL_EXIT; - */ - +#else + + taskENTER_CRITICAL(); /*进入临界区*/ + ret = xTaskCreate((TaskFunction_t)SfudExampleTaskEntry, /* 任务入口函数 */ + (const char *)"SfudExampleTaskEntry",/* 任务名字 */ + (uint16_t)4096, /* 任务栈大小 */ + NULL,/* 任务入口函数参数 */ + (UBaseType_t)2, /* 任务的优先级 */ + NULL); + taskEXIT_CRITICAL(); /*退出临界区*/ + +#endif vTaskStartScheduler(); /* 启动任务,开启调度 */ while (1); /* 正常不会执行到这里 */ diff --git a/example/peripheral/spi/src/cmd_sf.c b/example/peripheral/spi/src/cmd_sf.c index 6913d436aced7e88f73be07696f0d0d7cebccbdb..4a878a778f32fe295641d8cfb1180a1973999a85 100644 --- a/example/peripheral/spi/src/cmd_sf.c +++ b/example/peripheral/spi/src/cmd_sf.c @@ -22,15 +22,15 @@ * 1.0 zhugengyu 2022/8/26 first commit */ /***************************** Include Files *********************************/ +#include "sdkconfig.h" +#include "FreeRTOS.h" +#include "sfud_read_write.h" #include +#include "task.h" #include #include "strto.h" -#include "sdkconfig.h" - -#include "FreeRTOS.h" - +#ifdef CONFIG_USE_LETTER_SHELL #include "../src/shell.h" -#include "sfud_read_write.h" /************************** Constant Definitions *****************************/ /**************************** Type Definitions *******************************/ @@ -45,16 +45,13 @@ static void SfudCmdUsage() { printf("Usage:\r\n"); - printf(" sf probe\r\n"); - printf(" -- Probe and init SPI flash\r\n"); - printf(" sf rw \r\n"); - printf(" -- Demo read and write by sfud\r\n"); + printf("sf sfud_read_write\r\n"); + printf("-- Demo read and write by sfud\r\n"); } static int SfudCmdEntry(int argc, char *argv[]) { int ret = 0; - static boolean inited = FALSE; if (argc < 2) { @@ -62,53 +59,22 @@ static int SfudCmdEntry(int argc, char *argv[]) return -1; } - if ((FALSE == inited) || (!strcmp(argv[1], "probe"))) + if (!strcmp(argv[1], "sfud_read_write")) { - if (pdPASS != FFreeRTOSSfudInit()) - { - return -2; - } - - inited = TRUE; + FFreeRTOSSfudWriteThenRead(); } - if (!strcmp(argv[1], "read")) - { - u32 in_chip_addr = 0x0; - - if (argc > 2) - { - in_chip_addr = (u32)simple_strtoul(argv[2], NULL, 16); - } - - BaseType_t task_ret = FFreeRTOSSfudRead(in_chip_addr); - if (pdPASS != task_ret) - { - return -2; - } - } - else if (!strcmp(argv[1], "write")) - { - u32 in_chip_addr = 0x0; - const char *wr_str = "write flash by sfud"; - - if (argc > 2) - { - in_chip_addr = (u32)simple_strtoul(argv[2], NULL, 16); - } + return 0; +} +SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), sf, SfudCmdEntry, test freertos sfud); +#endif - if (argc > 3) - { - wr_str = argv[3]; - } +void SfudExampleTaskEntry() +{ + /*Demo read and write by sfud*/ + FFreeRTOSSfudWriteThenRead(); - BaseType_t task_ret = FFreeRTOSSfudWrite(in_chip_addr, wr_str); - if (pdPASS != task_ret) - { - return -2; - } - } + printf("[test_end]\r\n"); - return 0; -} -SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), sf, SfudCmdEntry, test freertos sfud); \ No newline at end of file + vTaskDelete(NULL); +} \ No newline at end of file diff --git a/example/peripheral/spi/src/sfud_read_write.c b/example/peripheral/spi/src/sfud_read_write.c index 04bd161fc517727afe9ee4e88292020d963aef63..0e6bf718b0cf6369b2a5a7445e56e0119b4308f6 100644 --- a/example/peripheral/spi/src/sfud_read_write.c +++ b/example/peripheral/spi/src/sfud_read_write.c @@ -27,10 +27,11 @@ #include "FreeRTOS.h" #include "task.h" - +#include "queue.h" #include "fdebug.h" #include "fsleep.h" #include "fkernel.h" +#include "timers.h" #include "sfud.h" @@ -44,8 +45,13 @@ /************************** Variable Definitions *****************************/ static u32 flash_addr = 0x0; -static u8 flash_buffer[SFUD_WR_BUF_LEN]; +static u8 write_flash_buffer[SFUD_WR_BUF_LEN]; +static u8 read_flash_buffer[SFUD_WR_BUF_LEN]; +static QueueHandle_t xQueue = NULL; + /***************** Macros (Inline Functions) Definitions *********************/ +#define TIMER_OUT ( pdMS_TO_TICKS( 3000UL ) ) + #define FSPIM_DEBUG_TAG "SFUD-DEMO" #define FSPIM_ERROR(format, ...) FT_DEBUG_PRINT_E(FSPIM_DEBUG_TAG, format, ##__VA_ARGS__) #define FSPIM_WARN(format, ...) FT_DEBUG_PRINT_W(FSPIM_DEBUG_TAG, format, ##__VA_ARGS__) @@ -55,19 +61,29 @@ static u8 flash_buffer[SFUD_WR_BUF_LEN]; /************************** Function Prototypes ******************************/ /*****************************************************************************/ -static void SfudInitTask(void *args) +enum +{ + SPI_SFUD_TEST_SUCCESS = 1, /*SPI sufd test success*/ + SPI_SFUD_INIT_FAILURE = 2, /*SPI init step failure*/ + SPI_SFUD_WRITE_FAILURE = 3, /*SPI write step failure*/ + SPI_SFUD_READ_FAILURE = 4, /*SPI read step failure*/ +}; + +static sfud_err SpiSfudInit(void) { + int task_res = 0; sfud_err sfud_ret = sfud_init(); if (SFUD_SUCCESS != sfud_ret) { - goto task_exit; + goto init_exit; } const sfud_flash *flash = sfud_get_device(SFUD_FLASH_INDEX); if (NULL == flash) { FSPIM_ERROR("Flash not found."); - goto task_exit; + sfud_ret = SFUD_ERR_NOT_FOUND; + goto init_exit; } /* print flash info */ @@ -87,23 +103,31 @@ static void SfudInitTask(void *args) printf(" Erase granularity: %d Bytes\r\n", flash->chip.erase_gran); -task_exit: - vTaskDelete(NULL); /* delete task itself */ +init_exit: + if (SFUD_SUCCESS != sfud_ret) + { + task_res = SPI_SFUD_INIT_FAILURE; + xQueueSend(xQueue, &task_res, 0); + } + + return sfud_ret; } -static void SfudWriteTask(void *args) +static sfud_err SpiSfudWrite(void) { - sfud_err sfud_ret; + sfud_err sfud_ret = SFUD_SUCCESS; + int task_res = 0; u32 in_chip_addr = flash_addr; const sfud_flash *flash = NULL; u8 status = 0; - u8 *write_buf = flash_buffer; + u8 *write_buf = write_flash_buffer; flash = sfud_get_device(SFUD_FLASH_INDEX); if (NULL == flash) { FSPIM_ERROR("Flash not found."); - goto task_exit; + sfud_ret = SFUD_ERR_NOT_FOUND; + goto write_exit; } /* remove flash write protect */ @@ -111,7 +135,7 @@ static void SfudWriteTask(void *args) if (SFUD_SUCCESS != sfud_ret) { FSPIM_ERROR("Write flash status failed."); - goto task_exit; + goto write_exit; } /* get flash status */ @@ -119,7 +143,7 @@ static void SfudWriteTask(void *args) if (SFUD_SUCCESS != sfud_ret) { FSPIM_ERROR("Read flash status failed."); - goto task_exit; + goto write_exit; } else { @@ -137,33 +161,41 @@ static void SfudWriteTask(void *args) if (SFUD_SUCCESS != sfud_ret) { FSPIM_ERROR("Erase flash failed."); - goto task_exit; + goto write_exit; } sfud_ret = sfud_write(flash, in_chip_addr, SFUD_WR_BUF_LEN, write_buf); if (SFUD_SUCCESS != sfud_ret) { FSPIM_ERROR("Write flash failed."); - goto task_exit; + goto write_exit; } -task_exit: - vTaskDelete(NULL); /* delete task itself */ +write_exit: + if (SFUD_SUCCESS != sfud_ret) + { + task_res = SPI_SFUD_WRITE_FAILURE; + xQueueSend(xQueue, &task_res, 0);; + } + + return sfud_ret; } -static void SfudReadTask(void *args) +static sfud_err SpiSfudRead(void) { - sfud_err sfud_ret; + sfud_err sfud_ret = SFUD_SUCCESS; + int task_res = 0; u32 in_chip_addr = flash_addr; const sfud_flash *flash = NULL; u8 status = 0; - u8 *read_buf = flash_buffer; + u8 *read_buf = read_flash_buffer; flash = sfud_get_device(SFUD_FLASH_INDEX); if (NULL == flash) { FSPIM_ERROR("Flash not found."); - goto task_exit; + sfud_ret = SFUD_ERR_NOT_FOUND; + goto read_exit; } /* get flash status */ @@ -171,7 +203,7 @@ static void SfudReadTask(void *args) if (SFUD_SUCCESS != sfud_ret) { FSPIM_ERROR("Read flash status failed."); - goto task_exit; + goto read_exit; } else { @@ -184,86 +216,117 @@ static void SfudReadTask(void *args) if (SFUD_SUCCESS != sfud_ret) { FSPIM_ERROR("Read flash failed."); - goto task_exit; + goto read_exit; } taskENTER_CRITICAL(); /* no schedule when printf bulk */ + for (u32 i = 0; i < SFUD_WR_BUF_LEN; i++) + { + if (read_buf[i] != write_flash_buffer[i]) + { + FSPIM_ERROR("Read flash failed.read_buf != write_flash_buffer\r\n"); + sfud_ret = SFUD_ERR_READ; + goto read_exit; + } + } + printf("Data read from flash @0x%x...\r\n", in_chip_addr); FtDumpHexByte(read_buf, SFUD_WR_BUF_LEN); taskEXIT_CRITICAL(); -task_exit: - vTaskDelete(NULL); /* delete task itself */ +read_exit: + if (SFUD_SUCCESS != sfud_ret) + { + task_res = SPI_SFUD_READ_FAILURE; + xQueueSend(xQueue, &task_res, 0);; + } + + return sfud_ret; } -BaseType_t FFreeRTOSSfudRead(u32 in_chip_addr) +static void SpiSfudWriteThenReadTask(void) { - BaseType_t xReturn = pdPASS; + sfud_err sfud_ret = SFUD_SUCCESS; + int task_res = 0; - printf("This is sfud read task.\r\n"); - - memset(flash_buffer, 0, sizeof(flash_buffer)); - flash_addr = in_chip_addr; + sfud_ret = SpiSfudInit(); + if (SFUD_SUCCESS != sfud_ret) + { + FSPIM_ERROR("Flash init failed.\r\n"); + goto task_exit; + } - taskENTER_CRITICAL(); /* no schedule when create task */ + sfud_ret = SpiSfudWrite(); + if (SFUD_SUCCESS != sfud_ret) + { + FSPIM_ERROR("Write flash failed.\r\n"); + goto task_exit; + } - xReturn = xTaskCreate((TaskFunction_t)SfudReadTask, - (const char *)"SfudReadTask", - (uint16_t)2048, - NULL, - (UBaseType_t)configMAX_PRIORITIES - 1, - NULL); + sfud_ret = SpiSfudRead(); + if (SFUD_SUCCESS != sfud_ret) + { + FSPIM_ERROR("Read flash failed.\r\n"); + goto task_exit; + } - taskEXIT_CRITICAL(); /* allow schedule since task created */ +task_exit: + if (sfud_ret == SFUD_SUCCESS) + { + task_res = SPI_SFUD_TEST_SUCCESS; + xQueueSend(xQueue, &task_res, 0); + } - return xReturn; + vTaskDelete(NULL); } -BaseType_t FFreeRTOSSfudWrite(u32 in_chip_addr, const char *content) +BaseType_t FFreeRTOSSfudWriteThenRead() { - BaseType_t xReturn = pdPASS; - - printf("This is sfud write task.\r\n"); - - flash_addr = in_chip_addr; + BaseType_t xReturn = pdPASS;/* 定义一个创建信息返回值,默认为 pdPASS */ + int task_res = 0; + flash_addr = 0x10; + const char *content = "write-spi-nor-flash-from-freertos-sfud"; if (strlen(content) + 1 > SFUD_WR_BUF_LEN) { - return pdFAIL; + FSPIM_ERROR("write content too long.\r\n"); + goto exit; } - memset(flash_buffer, 0, sizeof(flash_buffer)); - memcpy(flash_buffer, content, strlen(content) + 1); - - taskENTER_CRITICAL(); /* no schedule when create task */ - - xReturn = xTaskCreate((TaskFunction_t)SfudWriteTask, - (const char *)"SfudWriteTask", - (uint16_t)2048, - NULL, - (UBaseType_t)configMAX_PRIORITIES - 1, + memset(write_flash_buffer, 0, sizeof(write_flash_buffer)); + memcpy(write_flash_buffer, content, strlen(content) + 1); + xQueue = xQueueCreate(1, sizeof(int)); + if (xQueue == NULL) + { + FSPIM_ERROR("xQueue create failed.\r\n"); + goto exit; + } + + taskENTER_CRITICAL(); /*进入临界区*/ + xReturn = xTaskCreate((TaskFunction_t)SpiSfudWriteThenReadTask, /* 任务入口函数 */ + (const char *)"SpiSfudWriteThenReadTask",/* 任务名字 */ + (uint16_t)4096, /* 任务栈大小 */ + NULL,/* 任务入口函数参数 */ + (UBaseType_t)2, /* 任务的优先级 */ NULL); + taskEXIT_CRITICAL(); /*退出临界区*/ + xReturn = xQueueReceive(xQueue, &task_res, TIMER_OUT); - taskEXIT_CRITICAL(); /* allow schedule since task created */ - - return xReturn; + if (xReturn == pdFAIL) + { + FSPIM_ERROR("xQueue receive timeout.\r\n"); + goto exit; + } + +exit: + vQueueDelete(xQueue); + if (task_res != SPI_SFUD_TEST_SUCCESS) + { + printf("%s@%d: Spi sfud read then write example [failure], task_res = %d\r\n", __func__, __LINE__, task_res); + return pdFAIL; + } + else + { + printf("%s@%d: Spi sfud read then write example [success].\r\n", __func__, __LINE__); + return pdTRUE; + } } - -BaseType_t FFreeRTOSSfudInit(void) -{ - BaseType_t xReturn = pdPASS; - - printf("This is sfud init task.\r\n"); - - taskENTER_CRITICAL(); /* no schedule when create task */ - - xReturn = xTaskCreate((TaskFunction_t)SfudInitTask, - (const char *)"SfudInitTask", - (uint16_t)2048, - NULL, - (UBaseType_t)configMAX_PRIORITIES - 1, - NULL); - - taskEXIT_CRITICAL(); /* allow schedule since task created */ - - return pdPASS; -} \ No newline at end of file diff --git a/install.py b/install.py index f42702a49a23db29b9b16aba6c9f519815f87e55..96a4d84df70333dfc7c6bc68d90ac02a2902c31c 100755 --- a/install.py +++ b/install.py @@ -36,18 +36,18 @@ freertos_sdk_path = install_path print("Standalone SDK at {}".format(freertos_sdk_path)) # Add standalone sdk -standalone_sdk_v="cd15b23000d0c52968dc322b6d99025195bbf446" +standalone_sdk_v="14741a4caf11977447d8f91fd928e23955e837de" if (install_platform == windows_x64): standalone_path=freertos_sdk_path + '\\standalone' else: standalone_path=freertos_sdk_path + '/standalone' -standalone_branche="master" +standalone_branch="master" standalone_remote="https://gitee.com/phytium_embedded/phytium-standalone-sdk.git" if not os.path.exists(standalone_path): current_path = os.getcwd() - os.system("git clone -b {} {} {}".format(standalone_branche, standalone_remote,standalone_path)) + os.system("git clone -b {} {} {}".format(standalone_branch, standalone_remote,standalone_path)) os.chdir(standalone_path)# 切换工作路径至standalone 路径 os.system("git config core.sparsecheckout true") os.system("git config advice.detachedHead false")