Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stm32][sdmmc]Optimize execution efficiency and find the right clock division #9276

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wdfk-prog
Copy link
Contributor

@wdfk-prog wdfk-prog commented Aug 5, 2024

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

  1. [stm32][sdmmc]Optimize execution efficiency and find the right clock division
  2. [drivers][sdio]Resolves cid,csd,scr, add CSD Version 3.0 support
  3. add SD Specifications Physical Layer Specification Version 9.10

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • .config:

card_brands

  • 参考如下编写

https://www.usb2sd.com/article/https-wwwcameramemoryspeedcom-sd-memory-card-faq-reading-sd-card-cid-serial-psn-internal-numbers--i00004i1.html

mmcsd_core 栈大小修改原因

  • 使用1024爆栈,执行check_gpt失败

测试结果如下

  • 测试程序
/**
  * @brief  SDCARD速度测试
  * @param  None.
  * @retval None.
  * @note   None.
*/
static void cmd_sdcard_speed_test(uint8_t argc, char **argv)
{
    #define PATH_LEN 128
    const char *dir_path = "/sdcard/test";
    char file_path[PATH_LEN];

    /* check log file directory  */
    if (access(dir_path, F_OK) < 0)
    {
        mkdir(dir_path, 0);
    }
    /* open file */
    rt_snprintf(file_path, PATH_LEN, "%s/%s.txt", dir_path, "test");
    int file_fd = open(file_path, O_CREAT | O_RDWR | O_APPEND);
    if (file_path < 0)
    {
        rt_kprintf("test file(%s) open failed.\n", file_path);
        return;
    }
    char test[1024];
    int last_time = rt_tick_get_millisecond();
    for(rt_uint16_t i = 0; i <1024; i++)
    {
      /* write to the file */
      if (write(file_fd, test, 1024) != 1024)
      {
          rt_kprintf("test file(%s) write failed.\n", file_path);
          return;
      }
      /* flush file cache */
      fsync(file_fd);
    }
    int now_time = rt_tick_get_millisecond();
    rt_kprintf("test file write 1MB time =  %dms.\n", now_time - last_time);

    last_time = rt_tick_get_millisecond();
    rt_size_t file_size = lseek(file_fd, 0, SEEK_SET);
    for(rt_uint16_t i = 0; i <1024; i++)
    {
      /* read to the file */
      read(file_fd, test, 1024);
    }
    now_time = rt_tick_get_millisecond();
    rt_kprintf("test file read 1MB time = %dms.\n", now_time - last_time);

    close(file_fd);
}
MSH_CMD_EXPORT_ALIAS(cmd_sdcard_speed_test,test_sdcard,test sdcard speed);
[2024/8/5 23:40:45 478]    ___  ______  _____         ______  _   ______  _____  _____  _____ 
[2024/8/5 23:40:45 485]   / _ \ | ___ \|_   _|        | ___ \(_)  | ___ \/  _  \/  _  \|_   _|
[2024/8/5 23:40:45 488]  / /_\ \| |_/ /  | |   ______ | |_/ / _   | |_/ /| | | || | | |  | |  
[2024/8/5 23:40:45 502]  |  _  ||    /   | |  |______||  __/ | |  | ___ \| | | || | | |  | |  
[2024/8/5 23:40:45 502]  | | | || |\ \   | |          | |    | |  | |_/ /\ \_/ /\ \_/ /  | |  
[2024/8/5 23:40:45 506]  \_| |_/\_| \_|  \_/          \_|    |_|  \____/  \___/  \___/   \_/  
[2024/8/5 23:40:45 506] 
[2024/8/5 23:40:45 510]  Powered by RT-Thread.
[2024/8/5 23:40:45 510] 
[2024/8/5 23:40:45 768] msh >rcc_rsr = 0x05fe0000(Independent watchdog reset flag)
[2024/8/5 23:40:45 772] 
[2024/8/5 23:40:45 773]  \ | /
[2024/8/5 23:40:45 784] - RT -     Thread Operating System
[2024/8/5 23:40:45 784]  / | \     5.2.0 build Aug  5 2024 23:40:28
[2024/8/5 23:40:45 784]  2006 - 2024 Copyright by RT-Thread team
[2024/8/5 23:40:45 971] 08-05 23:40:21.050 found part[0], begin: 4194304, size: 29.748GB

[2024/8/5 23:40:45 999] 08-05 23:40:21.144 I/main:  \ | /
[2024/8/5 23:40:46 006] 08-05 23:40:21.144 W/main: - HLY -    Version FULL V0.0.1
[2024/8/5 23:40:46 253] 08-05 23:40:21.144 E/main:  / | \     build Aug  5 2024 23:40:21
[2024/8/5 23:40:46 260] 08-05 23:40:21.144 I/main: System Clock information
[2024/8/5 23:40:46 271] 08-05 23:40:21.144 W/main: SYSCLK_Frequency = 480000000 HCLK_Frequency   = 240000000
[2024/8/5 23:40:46 275] 08-05 23:40:21.144 W/main: PCLK1_Frequency  = 120000000 PCLK2_Frequency  = 120000000
[2024/8/5 23:40:46 282] 08-05 23:40:21.144 W/main: SPI1_Frequency   = 480000000
[2024/8/5 23:40:46 287] 08-05 23:40:21.144 W/main: SDMMC_Frequency  = 480000000
[2024/8/5 23:40:46 294] 08-05 23:40:21.144 W/main: HAL version      = V1.11.3
[2024/8/5 23:40:46 309] 08-05 23:40:21.144 W/main: ARMcompiler version = 6220000
[2024/8/5 23:40:46 381] 08-05 23:40:21.160 I/SDIO: SD card MID: SanDisk, OID: SD<𻒄32G, PNM: SD32G, PRV: 8.5, PSN: 0xfcf33c9e, MDT: 3mont
[2024/8/5 23:40:46 390] 08-05 23:40:21.160 I/SDIO: SD card version SDHC or SDXC,class 10, capacity 31178752 KB.
[2024/8/5 23:40:46 395] 08-05 23:40:21.164 I/SDIO: SD spec version 6
[2024/8/5 23:40:46 402] 08-05 23:40:21.164 I/SDIO: sd: switch to High Speed / SDR25 mode
[2024/8/5 23:40:46 414] 08-05 23:40:21.351 I/app.filesystem: sd card mount to '/sdcard'

drv_sdmmc.c修改前后性能对比如下

  • 修改前
[2024/8/5 22:40:00 423] test file write 1MB time =  12919ms.
[2024/8/5 22:40:06 791] test file read 1MB time = 6364ms.
  • 修改后
[2024/8/5 23:36:16 597] test file write 1MB time =  2280ms.
[2024/8/5 23:36:16 969] test file read 1MB time = 368ms.

修改原因

rthw_sdio_iocfg对于div的处理有问题,导致都是使用400khz频率再跑;导致性能低下

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@wdfk-prog
Copy link
Contributor Author

  • 另外,CUBEMX初始化的SDMMC时钟跑在PLL2R上,应该是200mhz;
  • 另一个可选择的是PLL2Q,是480MHZ
  • 但是使用HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SDMMC)获取的只有480mhz
  • 强制将获取时钟频率改为200mhz,测试读写速率并没有提高或降低.
  • 不知道是什么原因,art-pi的原理图上没有注明CLK的电阻是哪一颗,没办法用逻辑分析仪测量频率是否设置正常.

@wdfk-prog
Copy link
Contributor Author

  • 还有SD的性能提不上了,不知道时钟是否达标了,没法测试;
  • 还是因为其他原因导致

@Rbb666 Rbb666 added the BSP: STM32 BSP related with ST/STM32 label Aug 6, 2024
@Rbb666 Rbb666 requested a review from mysterywolf August 6, 2024 01:48
@mysterywolf mysterywolf closed this Sep 2, 2024
@mysterywolf mysterywolf reopened this Sep 2, 2024
@mysterywolf mysterywolf self-requested a review September 2, 2024 04:44
@mysterywolf mysterywolf added the change req change requestion label Sep 2, 2024
@github-actions github-actions bot added BSP Kernel PR has src relate code libcpu Component labels Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BSP: STM32 BSP related with ST/STM32 BSP change req change requestion Component Kernel PR has src relate code libcpu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants