Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页
    1. Home
    2. funfulzhao
    F
    • Profile
    • Following 1
    • Followers 0
    • my integral 225
    • Topics 2
    • Posts 3
    • Best 0
    • Groups 0

    funfulzhaoLV 3

    @funfulzhao

    225
    integral
    0
    Reputation
    1
    Profile views
    3
    Posts
    0
    Followers
    1
    Following
    Joined Last Online

    funfulzhao Unfollow Follow

    Latest posts made by funfulzhao

    • Reply: 【XR806开发板试用】使用FDCM操作Flash记录开机次数

      @funfulzhao 在 【XR806开发板试用】使用FDCM操作Flash记录开机次数 中说:

      一、寻找系统分配的自定义用户数据地址
      (1)XR806的Flash布局
      d9b423b2-e419-447a-a36e-818449e30c25-image.png
      如图1所示,FLASH的布局有两种:
      1、没有开启OTA模式;Image1+Padding+Sysinfo
      2、开启OTA模式;Image1+Padding+Sysinfo+OTA area +Image2 +Padding
      fa07eb9a-2cee-4fb6-ad75-f861b6248859-image.png 9fad5ccc-1b5a-4488-a518-24ccb92dee9f-image.png

      如图2/3,当前工程采用wlan_ble_demo,未开启OTA模式,
      查看device/xradio/xr806/xr_skylark/project/demo/wlan_ble_demo/gcc/Makefile文件,Flash的cfg文件为IMAGE_CFG := ./image_wlan_ble.cfg
      5b720328-f4b2-4752-9cc2-003f46d192ec-image.png
      (2)查看Sysinfo的地址
      Sysinfo区域是一段用于存储用户自定义数据的区域,紧跟在Image1区域后面,通过device/xradio/xr806/xr_skylark/project/demo/wlan_ble_demo/prj_config.h得知Sysinfo的地址和长度
      368e49bc-fca2-4c5a-b46e-901cfe7cf93d-image.png
      二、使用FDCM操作Sysinfo区域
      FDCM模块与SDK中其他模块之间的关系如下图所示。Sysinfo,OTA和IMAGE等模块中都有使用到FDCM模块接口,保存其对应的数据。
      bf44d439-26a6-4dd9-aba5-63f0763e2202-image.png
      注意:(1)FDCM操作的区域需要与Flash可擦除的Block对齐;
      (2)FDCM模块管理的Flash区域不要与其他模块(如Image)使用的Flash区域产生冲突,避免相互影响
      (3)用FDCM模块管理的Flash区域必须与Flash可擦除的block对齐,即区域起始地址与Flash擦除Block的边缘对齐,并且区域大小为Flash可擦除最小Block大小的整数倍
      三、实现代码

      #include <stdio.h>
      #include <unistd.h>
      #include <string.h>
      #include <stdlib.h>
      #include "ohos_init.h"
      #include "kernel/os/os.h"
      #include "sys/fdcm.h"
      #include "common/framework/platform_init.h"
      #define FLASH_DEVICE_NUM         0
      #define IoT_FLASH 1
      #define FDCM_FLASH_START_ADDR  (1536*1024)
      #define FDCM_SIZE   (4*1024)
      static OS_Thread_t g_main_thread;
      
      static void MainThread(void *arg)
      {
         fdcm_handle_t *fdcm;
         uint8_t write_buf[100];
         uint8_t read_buf[100];
      
         fdcm = fdcm_open(FLASH_DEVICE_NUM, FDCM_FLASH_START_ADDR, FDCM_SIZE);
         if (fdcm == NULL) {
      	printf("fdcm open fail.\n");
      	return ;
         }
         printf("fdcm open success, flash addr:0x%x, flash size:%d\n", FDCM_FLASH_START_ADDR, FDCM_SIZE);
         printf("we can use fdcm to save info to flash.\n");
         fdcm_read(fdcm, &read_buf, sizeof(read_buf));   
         if(strlen(read_buf)==0)
         {
            printf("first power on \r\n");
            sprintf((char *)write_buf,"%d",1);
            fdcm_write(fdcm, &write_buf, sizeof(write_buf));
         }
         else
         {   
             printf("read_buf = %d\r\n",atoi((char *)read_buf));  
             sprintf(write_buf,"%d",atoi((char *)read_buf)+1);
             printf("write_buf = %d\r\n",atoi((char *)write_buf));
             fdcm_write(fdcm, &write_buf, sizeof(write_buf));
         } 
         LOS_Msleep(10);
         fdcm_read(fdcm, &read_buf, sizeof(read_buf));
         LOS_Msleep(20);
         printf("Power-on times:%s\r\n",read_buf);
         fdcm_close(fdcm);
      }
      
      void FlashTestMain(void)
      {
      	printf("FDCM Flash Test \r\n");
      	if (OS_ThreadCreate(&g_main_thread, "MainThread", MainThread, NULL,
      			    OS_THREAD_PRIO_APP, 4 * 1024) != OS_OK) {
      		printf("[ERR] Create MainThread Failed\n");
      	}
      }
      
      SYS_RUN(FlashTestMain);
      

      四:实验现象展示

      ====================================================================
      	Hello! OpenHarmony!
      	System tag : OpenHarmony 1.1.2_LTS
      ====================================================================
      	
      use default flash chip mJedec 0x0
      [FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
      [FD I]: jedec: 0x0, suspend_support: 1
      mode select:e
      
      wlan information ===================================================
      firmware:
          version : R0-XR_C07.08.52.65_02.84 May 27 2021 11:41:33-Y02.84 
          buffer  : 8
      driver:
          version : XR_V02.05
      mac address:
          in use        : cc:6e:48:3e:0d:01
          in use        : cc:6e:48:3e:0d:02
      ====================================================================
      
      wlan mode:a
      [VFS INF] LittleFS mount success.
      
      platform information ===============================================
      XR806 SDK v1.2.0  Jan 23 2022 09:49:52
      
      heap space [0x223230, 0x24bc00), size 166352
      
      cpu  clock 160000000 Hz
      HF   clock  40000000 Hz
      
      sdk option:
          XIP           : enable
          INT LF OSC    : enable
          SIP flash     : enable
      
      mac address:
          efuse         : 80:74:84:05:bb:f9
          in use        : cc:6e:48:3e:0d:01
      ====================================================================
      
      FDCM Flash Test 
      Wifi Test Start
      
      console init success
      fdcm open success, flash addr:0x180000, flash size:4096
      hiview init success.hello world!
      we can use fdcm to save info to flash.
      read_buf = 8
      write_buf = 9
      Power-on times:9
      hello world!
      ====================================================================
      	Hello! OpenHarmony!
      	System tag : OpenHarmony 1.1.2_LTS
      ====================================================================
      	
      use default flash chip mJedec 0x0
      [FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
      [FD I]: jedec: 0x0, suspend_support: 1
      mode select:e
      
      wlan information ===================================================
      firmware:
          version : R0-XR_C07.08.52.65_02.84 May 27 2021 11:41:33-Y02.84 
          buffer  : 8
      driver:
          version : XR_V02.05
      mac address:
          in use        : cc:6e:48:3e:0d:01
          in use        : cc:6e:48:3e:0d:02
      ====================================================================
      
      wlan mode:a
      [VFS INF] LittleFS mount success.
      
      platform information ===============================================
      XR806 SDK v1.2.0  Jan 23 2022 09:49:52
      
      heap space [0x223230, 0x24bc00), size 166352
      
      cpu  clock 160000000 Hz
      HF   clock  40000000 Hz
      
      sdk option:
          XIP           : enable
          INT LF OSC    : enable
          SIP flash     : enable
      
      mac address:
          efuse         : 80:74:84:05:bb:f9
          in use        : cc:6e:48:3e:0d:01
      ====================================================================
      
      FDCM Flash Test 
      Wifi Test Start
      
      console init success
      fdcm open success, flash addr:0x180000, flash size:4096
      hiview init success.hello world!
      we can use fdcm to save info to flash.
      read_buf = 9
      write_buf = 10
      Power-on times:10
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      ====================================================================
      	Hello! OpenHarmony!
      	System tag : OpenHarmony 1.1.2_LTS
      ====================================================================
      	
      use default flash chip mJedec 0x0
      [FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
      [FD I]: jedec: 0x0, suspend_support: 1
      mode select:e
      
      wlan information ===================================================
      firmware:
          version : R0-XR_C07.08.52.65_02.84 May 27 2021 11:41:33-Y02.84 
          buffer  : 8
      driver:
          version : XR_V02.05
      mac address:
          in use        : cc:6e:48:3e:0d:01
          in use        : cc:6e:48:3e:0d:02
      ====================================================================
      
      wlan mode:a
      [VFS INF] LittleFS mount success.
      
      platform information ===============================================
      XR806 SDK v1.2.0  Jan 23 2022 09:49:52
      
      heap space [0x223230, 0x24bc00), size 166352
      
      cpu  clock 160000000 Hz
      HF   clock  40000000 Hz
      
      sdk option:
          XIP           : enable
          INT LF OSC    : enable
          SIP flash     : enable
      
      mac address:
          efuse         : 80:74:84:05:bb:f9
          in use        : cc:6e:48:3e:0d:01
      ====================================================================
      
      FDCM Flash Test 
      Wifi Test Start
      
      console init success
      fdcm open success, flash addr:0x180000, flash size:4096
      hiview init success.hello world!
      we can use fdcm to save info to flash.
      read_buf = 10
      write_buf = 11
      Power-on times:11
      

      五:遗留问题
      (1)Image的max_size为1532K,设置FDCM的起始地址为(15321024)时,本次开机的写入读取未报错,但是数据未保存;FDCM的起始地址改为(15361024),则正常。
      六:参考
      (1)https://harmonyos.51cto.com/posts/8225
      (2)《XR806_FDCM中间件_开发指南》
      (3)《XR806_Flash布局方案_开发指南》
      XR806软件类文档地址:https://open.allwinnertech.com/#/doc?menuID=2
      文档中心
      f1ee350f-c648-440a-a2cf-ed3e50a9f072-image.png

      posted in XR系列-无线互联
      F
      funfulzhao
    • 【XR806开发板试用】使用FDCM操作Flash记录开机次数

      一、寻找系统分配的自定义用户数据地址
      (1)XR806的Flash布局
      d9b423b2-e419-447a-a36e-818449e30c25-image.png
      如图1所示,FLASH的布局有两种:
      1、没有开启OTA模式;Image1+Padding+Sysinfo
      2、开启OTA模式;Image1+Padding+Sysinfo+OTA area +Image2 +Padding
      fa07eb9a-2cee-4fb6-ad75-f861b6248859-image.png 9fad5ccc-1b5a-4488-a518-24ccb92dee9f-image.png

      如图2/3,当前工程采用wlan_ble_demo,未开启OTA模式,
      查看device/xradio/xr806/xr_skylark/project/demo/wlan_ble_demo/gcc/Makefile文件,Flash的cfg文件为IMAGE_CFG := ./image_wlan_ble.cfg
      5b720328-f4b2-4752-9cc2-003f46d192ec-image.png
      (2)查看Sysinfo的地址
      Sysinfo区域是一段用于存储用户自定义数据的区域,紧跟在Image1区域后面,通过device/xradio/xr806/xr_skylark/project/demo/wlan_ble_demo/prj_config.h得知Sysinfo的地址和长度
      368e49bc-fca2-4c5a-b46e-901cfe7cf93d-image.png
      二、使用FDCM操作Sysinfo区域
      FDCM模块与SDK中其他模块之间的关系如下图所示。Sysinfo,OTA和IMAGE等模块中都有使用到FDCM模块接口,保存其对应的数据。
      bf44d439-26a6-4dd9-aba5-63f0763e2202-image.png
      注意:(1)FDCM操作的区域需要与Flash可擦除的Block对齐;
      (2)FDCM模块管理的Flash区域不要与其他模块(如Image)使用的Flash区域产生冲突,避免相互影响
      (3)用FDCM模块管理的Flash区域必须与Flash可擦除的block对齐,即区域起始地址与Flash擦除Block的边缘对齐,并且区域大小为Flash可擦除最小Block大小的整数倍
      三、实现代码

      #include <stdio.h>
      #include <unistd.h>
      #include <string.h>
      #include <stdlib.h>
      #include "ohos_init.h"
      #include "kernel/os/os.h"
      #include "sys/fdcm.h"
      #include "common/framework/platform_init.h"
      #define FLASH_DEVICE_NUM         0
      #define IoT_FLASH 1
      #define FDCM_FLASH_START_ADDR  (1536*1024)
      #define FDCM_SIZE   (4*1024)
      static OS_Thread_t g_main_thread;
      
      static void MainThread(void *arg)
      {
         fdcm_handle_t *fdcm;
         uint8_t write_buf[100];
         uint8_t read_buf[100];
      
         fdcm = fdcm_open(FLASH_DEVICE_NUM, FDCM_FLASH_START_ADDR, FDCM_SIZE);
         if (fdcm == NULL) {
      	printf("fdcm open fail.\n");
      	return ;
         }
         printf("fdcm open success, flash addr:0x%x, flash size:%d\n", FDCM_FLASH_START_ADDR, FDCM_SIZE);
         printf("we can use fdcm to save info to flash.\n");
         fdcm_read(fdcm, &read_buf, sizeof(read_buf));   
         if(strlen(read_buf)==0)
         {
            printf("first power on \r\n");
            sprintf((char *)write_buf,"%d",1);
            fdcm_write(fdcm, &write_buf, sizeof(write_buf));
         }
         else
         {   
             printf("read_buf = %d\r\n",atoi((char *)read_buf));  
             sprintf(write_buf,"%d",atoi((char *)read_buf)+1);
             printf("write_buf = %d\r\n",atoi((char *)write_buf));
             fdcm_write(fdcm, &write_buf, sizeof(write_buf));
         } 
         LOS_Msleep(10);
         fdcm_read(fdcm, &read_buf, sizeof(read_buf));
         LOS_Msleep(20);
         printf("Power-on times:%s\r\n",read_buf);
         fdcm_close(fdcm);
      }
      
      void FlashTestMain(void)
      {
      	printf("FDCM Flash Test \r\n");
      	if (OS_ThreadCreate(&g_main_thread, "MainThread", MainThread, NULL,
      			    OS_THREAD_PRIO_APP, 4 * 1024) != OS_OK) {
      		printf("[ERR] Create MainThread Failed\n");
      	}
      }
      
      SYS_RUN(FlashTestMain);
      

      四:实验现象展示

      ====================================================================
      	Hello! OpenHarmony!
      	System tag : OpenHarmony 1.1.2_LTS
      ====================================================================
      	
      use default flash chip mJedec 0x0
      [FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
      [FD I]: jedec: 0x0, suspend_support: 1
      mode select:e
      
      wlan information ===================================================
      firmware:
          version : R0-XR_C07.08.52.65_02.84 May 27 2021 11:41:33-Y02.84 
          buffer  : 8
      driver:
          version : XR_V02.05
      mac address:
          in use        : cc:6e:48:3e:0d:01
          in use        : cc:6e:48:3e:0d:02
      ====================================================================
      
      wlan mode:a
      [VFS INF] LittleFS mount success.
      
      platform information ===============================================
      XR806 SDK v1.2.0  Jan 23 2022 09:49:52
      
      heap space [0x223230, 0x24bc00), size 166352
      
      cpu  clock 160000000 Hz
      HF   clock  40000000 Hz
      
      sdk option:
          XIP           : enable
          INT LF OSC    : enable
          SIP flash     : enable
      
      mac address:
          efuse         : 80:74:84:05:bb:f9
          in use        : cc:6e:48:3e:0d:01
      ====================================================================
      
      FDCM Flash Test 
      Wifi Test Start
      
      console init success
      fdcm open success, flash addr:0x180000, flash size:4096
      hiview init success.hello world!
      we can use fdcm to save info to flash.
      read_buf = 8
      write_buf = 9
      Power-on times:9
      hello world!
      ====================================================================
      	Hello! OpenHarmony!
      	System tag : OpenHarmony 1.1.2_LTS
      ====================================================================
      	
      use default flash chip mJedec 0x0
      [FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
      [FD I]: jedec: 0x0, suspend_support: 1
      mode select:e
      
      wlan information ===================================================
      firmware:
          version : R0-XR_C07.08.52.65_02.84 May 27 2021 11:41:33-Y02.84 
          buffer  : 8
      driver:
          version : XR_V02.05
      mac address:
          in use        : cc:6e:48:3e:0d:01
          in use        : cc:6e:48:3e:0d:02
      ====================================================================
      
      wlan mode:a
      [VFS INF] LittleFS mount success.
      
      platform information ===============================================
      XR806 SDK v1.2.0  Jan 23 2022 09:49:52
      
      heap space [0x223230, 0x24bc00), size 166352
      
      cpu  clock 160000000 Hz
      HF   clock  40000000 Hz
      
      sdk option:
          XIP           : enable
          INT LF OSC    : enable
          SIP flash     : enable
      
      mac address:
          efuse         : 80:74:84:05:bb:f9
          in use        : cc:6e:48:3e:0d:01
      ====================================================================
      
      FDCM Flash Test 
      Wifi Test Start
      
      console init success
      fdcm open success, flash addr:0x180000, flash size:4096
      hiview init success.hello world!
      we can use fdcm to save info to flash.
      read_buf = 9
      write_buf = 10
      Power-on times:10
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      hello world!
      ====================================================================
      	Hello! OpenHarmony!
      	System tag : OpenHarmony 1.1.2_LTS
      ====================================================================
      	
      use default flash chip mJedec 0x0
      [FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
      [FD I]: jedec: 0x0, suspend_support: 1
      mode select:e
      
      wlan information ===================================================
      firmware:
          version : R0-XR_C07.08.52.65_02.84 May 27 2021 11:41:33-Y02.84 
          buffer  : 8
      driver:
          version : XR_V02.05
      mac address:
          in use        : cc:6e:48:3e:0d:01
          in use        : cc:6e:48:3e:0d:02
      ====================================================================
      
      wlan mode:a
      [VFS INF] LittleFS mount success.
      
      platform information ===============================================
      XR806 SDK v1.2.0  Jan 23 2022 09:49:52
      
      heap space [0x223230, 0x24bc00), size 166352
      
      cpu  clock 160000000 Hz
      HF   clock  40000000 Hz
      
      sdk option:
          XIP           : enable
          INT LF OSC    : enable
          SIP flash     : enable
      
      mac address:
          efuse         : 80:74:84:05:bb:f9
          in use        : cc:6e:48:3e:0d:01
      ====================================================================
      
      FDCM Flash Test 
      Wifi Test Start
      
      console init success
      fdcm open success, flash addr:0x180000, flash size:4096
      hiview init success.hello world!
      we can use fdcm to save info to flash.
      read_buf = 10
      write_buf = 11
      Power-on times:11
      

      五:遗留问题
      (1)Image的max_size为1532K,设置FDCM的起始地址为(15321024)时,本次开机的写入读取未报错,但是数据未保存;FDCM的起始地址改为(15361024),则正常。
      六:参考
      (1)https://harmonyos.51cto.com/posts/8225
      (2)《XR806_FDCM中间件_开发指南》
      (3)《XR806_Flash布局方案_开发指南》

      posted in XR系列-无线互联
      F
      funfulzhao
    • IIC通信问题异常,该怎么解决呢

      XR806在用IIC1(TWI1 /PB14/PB15)通信的时候,初始化函数IoTI2cInit完,一直打印这个错误信息,而且过一段时间还会重启,这个是怎么回事呢

      d6aca154-d7c0-4dda-8f3e-9eb9131466a0-image.png

      posted in XR系列-无线互联
      F
      funfulzhao