[活动专区] 【AT-START-F437测评】THREADX + FILEX

[复制链接]
 楼主| aple0807 发表于 2023-1-5 23:06 | 显示全部楼层 |阅读模式
【AT-START-F437测评】THREADX + FILEX

THREADX 作为世界第一梯队的RTOS,如今已归微软旗下,拥有者诸多安全认证:
航空领域 – ED-12B, DO-178B, ED-109, ED-278
医学领域 – IEC-60601, IEC-62304, ISO-14971, FDA 510(k)
工业领域– IEC-61508, and others
运输领域 – CENELEC EN50128, 49CFR236, IEC-61508

该RTOS虽然不是完全免版税,但也有这个趋势,至少在STM32、NXP、瑞萨芯片上已经可以免费使用了。

FILEX做为THREADX的配套组件之一,同样拥有如上安全认证。

这几天拿AT32F437评估板测试THREADX和FILEX,记录一下使用情况。

=========================================================
首先是THREADX,不得不说微软的移植工作做的非常细致,各种常见内核都已做好适配,使用时只需要添加官方移植好的M4文件就可以。
如下图所示部分选择port/cortex_m4下的文件即可。
tx_port.png
其中 tx_initialize_low_level.S 文件内的时钟需要配置一下:

  1. SYSTEM_CLOCK      =   288000000

  2. SYSTICK_CYCLES    =   ((SYSTEM_CLOCK / 500) -1)

AT32F437主频288MHz,上面配置系统TICK为2ms。
THREADX这么一点配置基本就可以跑起来了。

==========================================================
FILEX需要移植一个文件,主要用来实现USB DISK的读写操作,USB 读写参考AT32官方例程即可。
移植内容如下:

  1. #include <string.h>

  2. #include "usbh_user.h"
  3. #include "bsp.h"
  4. #include "tx_api.h"
  5. #include "fx_api.h"
  6. #include "usb_core.h"
  7. #include "usbh_msc_class.h"
  8. #include "common.h"                 

  9. /* Handle for USB Host */
  10. extern otg_core_type otg_core_struct;

  11. UINT  _fx_partition_offset_calculate(void  *partition_sector, UINT partition, ULONG *partition_start, ULONG *partition_size);

  12. static uint8_t sector_read(void *buff, uint32_t sec_site, uint32_t amount);
  13. static uint8_t sector_write(void *buff, uint32_t sec_site, uint32_t amount);


  14. /**
  15.   * [url=home.php?mod=space&uid=247401]@brief[/url] This function is the entry point to the STM32 SDIO disk driver.     */
  16. /*        It relies on the STM32 peripheral library from ST.
  17. * @param None
  18. * @retval None
  19. */
  20. VOID  fx_udisk_driver(FX_MEDIA *media_ptr)
  21. {
  22.     int32_t status;
  23.     ULONG       partition_start;
  24.     ULONG       partition_size;

  25.     /* before performing any operation, check the status of the SDMMC */
  26.     if(usbh_msc_is_ready(&otg_core_struct.host, 0) != MSC_OK)
  27.     {
  28.         media_ptr->fx_media_driver_status = FX_IO_ERROR;
  29.         return;
  30.     }

  31.     /* Process the driver request specified in the media control block.  */
  32.     switch (media_ptr->fx_media_driver_request)
  33.     {
  34.         case FX_DRIVER_INIT:
  35.         {
  36.             if(usbh_msc_is_ready(&otg_core_struct.host, 0) == MSC_OK)
  37.             {
  38.                 media_ptr->fx_media_driver_status = FX_SUCCESS;
  39.             }
  40.             else
  41.             {
  42.                 media_ptr->fx_media_driver_status = FX_IO_ERROR;
  43.             }

  44.             break;
  45.         }

  46.         case FX_DRIVER_UNINIT:
  47.         {
  48.             /* Successful driver request.  */
  49.             media_ptr->fx_media_driver_status = FX_SUCCESS;
  50.             break;
  51.         }

  52.         case FX_DRIVER_READ:
  53.         {
  54.             status = sector_read(
  55.                 media_ptr->fx_media_driver_buffer,
  56.                 media_ptr->fx_media_driver_logical_sector + media_ptr->fx_media_hidden_sectors,
  57.                 media_ptr->fx_media_driver_sectors
  58.                 );

  59.             if (status == 0)
  60.                 media_ptr->fx_media_driver_status = FX_SUCCESS;
  61.             else
  62.                 media_ptr->fx_media_driver_status = FX_IO_ERROR;

  63.             break;
  64.         }

  65.         case FX_DRIVER_WRITE:
  66.         {
  67.             status = sector_write(
  68.                 media_ptr->fx_media_driver_buffer,
  69.                 media_ptr->fx_media_driver_logical_sector + media_ptr->fx_media_hidden_sectors,
  70.                 media_ptr->fx_media_driver_sectors
  71.                 );


  72.             if (status == 0)
  73.                 media_ptr->fx_media_driver_status = FX_SUCCESS;
  74.             else
  75.                 media_ptr->fx_media_driver_status = FX_IO_ERROR;

  76.             break;
  77.         }

  78.         case FX_DRIVER_FLUSH:
  79.         {
  80.             /* Return driver success.  */
  81.             media_ptr->fx_media_driver_status = FX_SUCCESS;
  82.             break;
  83.         }

  84.         case FX_DRIVER_ABORT:
  85.         {
  86.             /* Return driver success.  */
  87.             media_ptr->fx_media_driver_status = FX_SUCCESS;
  88.             break;
  89.         }

  90.         case FX_DRIVER_BOOT_READ:
  91.         {
  92.             status = sector_read(
  93.                 media_ptr->fx_media_driver_buffer,
  94.                 0,
  95.                 1);


  96.             if (status == 0)
  97.             {
  98.                 media_ptr->fx_media_driver_status = FX_SUCCESS;
  99.             }
  100.             else
  101.             {
  102.                 media_ptr->fx_media_driver_status = FX_IO_ERROR;
  103.                 break;
  104.             }

  105.             /* Check if the sector 0 is the actual boot sector, otherwise calculate the offset into it.
  106.             Please note that this should belong to higher level of MW to do this check and it is here
  107.             as a temporary work solution */

  108.             partition_start = 0;

  109.             status = _fx_partition_offset_calculate(media_ptr->fx_media_driver_buffer, 0,
  110.                 &partition_start, &partition_size);

  111.             /* Check partition read error.  */
  112.             if (status)
  113.             {
  114.                 /* Unsuccessful driver request.  */
  115.                 media_ptr->fx_media_driver_status = FX_IO_ERROR;
  116.                 return;
  117.             }

  118.             /* Now determine if there is a partition...   */
  119.             if (partition_start)
  120.             {
  121.                 /* Yes, now lets read the actual boot record.  */
  122.                 status = sector_read(
  123.                     media_ptr->fx_media_driver_buffer,
  124.                     partition_start,
  125.                     1);

  126.                 /* Check status of SDIO Read.  */
  127.                 if (status != 0)
  128.                 {

  129.                     /* Unsuccessful driver request.  */
  130.                     media_ptr->fx_media_driver_status = FX_IO_ERROR;
  131.                     return;
  132.                 }
  133.             }

  134.             /* Successful driver request.  */
  135.             media_ptr->fx_media_driver_status = FX_SUCCESS;
  136.             break;
  137.         }
  138.         case FX_DRIVER_BOOT_WRITE:
  139.         {
  140.             status = sector_write(
  141.                 media_ptr->fx_media_driver_buffer,
  142.                 0,
  143.                 1
  144.                 );

  145.             if (status == 0)
  146.                 media_ptr->fx_media_driver_status = FX_SUCCESS;
  147.             else
  148.                 media_ptr->fx_media_driver_status = FX_IO_ERROR;

  149.             break;
  150.         }
  151.         default:
  152.         {
  153.             media_ptr->fx_media_driver_status = FX_IO_ERROR;
  154.             break;
  155.         }
  156.     }
  157. }

  158. uint8_t sector_read(void *buff, uint32_t sec_site, uint32_t count)
  159. {
  160.   usb_sts_type status;
  161.   
  162.   status = usbh_msc_read(&otg_core_struct.host, sec_site, count, buff, 0);
  163.   
  164.   if(status == USB_OK)
  165.     return 0;
  166.   
  167.   return 1;
  168. }

  169. uint8_t sector_write(void *buff, uint32_t sec_site, uint32_t count)
  170. {
  171.   usb_sts_type status;

  172.   status = usbh_msc_write(&otg_core_struct.host, sec_site, count, (uint8_t *)buff, 0);
  173.   
  174.   if(status == USB_OK)
  175.     return 0;
  176.   
  177.   return 1;
  178. }
应用测试代码比较多,不贴在这里了,感兴趣的小伙伴可以从贴尾链接下载代码测试。
下面是测试结果:
烧录程序运行后,插入U盘开始U盘操作。串口显示内容如下:
fl_com.png
U盘操作完后接入电脑,多出两个文件是本测试程序创建的:
fl.png
一个CSV表格,一个PDF文件。

表格文件内容:
fl_exl.png
PDF文件比较长,截取一部分如下:
fl_pdf.png
这就完了,微软出品的软件确实比较容易上手。系统默认配置,底层移植量非常少就能跑起来。后面可以细致研究OS和文件系统的各个API用法了。

代码托管在GITEE:
https://toscode.gitee.com/aple_sun/at32f437-start-threadx


打赏榜单

ArterySW 打赏了 20.00 元 2023-01-06
理由:【AT-START-F437测评】THREADX FILEX,作品优秀。

评论

给楼主点个赞  发表于 2023-1-17 09:03
您需要登录后才可以回帖 登录 | 注册

本版积分规则

77

主题

326

帖子

2

粉丝
快速回复 返回顶部 返回列表