搜索
bottom↓
回复: 9

移植LittleLS出现报错lfs.c:1228:error: Corrupted dir pair at {0x0, 0x1}

[复制链接]

出0入0汤圆

发表于 2022-4-26 10:41:05 | 显示全部楼层 |阅读模式
按照官网的代码移植,https://github.com/littlefs-project/littlefs
  1. #include "lfs.h"

  2. // variables used by the filesystem
  3. lfs_t lfs;
  4. lfs_file_t file;

  5. // configuration of the filesystem is provided by this struct
  6. const struct lfs_config cfg = {
  7.     // block device operations
  8.     .read  = user_provided_block_device_read,
  9.     .prog  = user_provided_block_device_prog,
  10.     .erase = user_provided_block_device_erase,
  11.     .sync  = user_provided_block_device_sync,

  12.     // block device configuration
  13.     .read_size = 16,
  14.     .prog_size = 16,
  15.     .block_size = 4096,
  16.     .block_count = 128,
  17.     .cache_size = 16,
  18.     .lookahead_size = 16,
  19.     .block_cycles = 500,
  20. };

  21. // entry point
  22. int main(void) {
  23.     // mount the filesystem
  24.     int err = lfs_mount(&lfs, &cfg);

  25.     // reformat if we can't mount the filesystem
  26.     // this should only happen on the first boot
  27.     if (err) {
  28.         lfs_format(&lfs, &cfg);
  29.         lfs_mount(&lfs, &cfg);
  30.     }

  31.     // read current count
  32.     uint32_t boot_count = 0;
  33.     lfs_file_open(&lfs, &file, "boot_count", LFS_O_RDWR | LFS_O_CREAT);
  34.     lfs_file_read(&lfs, &file, &boot_count, sizeof(boot_count));

  35.     // update boot count
  36.     boot_count += 1;
  37.     lfs_file_rewind(&lfs, &file);
  38.     lfs_file_write(&lfs, &file, &boot_count, sizeof(boot_count));

  39.     // remember the storage is not updated until the file is closed successfully
  40.     lfs_file_close(&lfs, &file);

  41.     // release any resources we were using
  42.     lfs_unmount(&lfs);

  43.     // print the boot count
  44.     printf("boot_count: %d\n", boot_count);
  45. }
复制代码


其中三个Flash操作的代码都换成了自已的代码,操作Flash没有问题,但是运行的时候会在串口输出提示:



放狗搜了很多也有类似报错的,但是没有解决方法。我这个把别人移植好的代码直接拷过来换成自已Flash操作代码,一样的堤示,不明白是哪里的问题。有人移值碰到过同样的问题吗?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2022-4-26 10:45:37 | 显示全部楼层
代码直接抄这个:
http://45.63.87.5/blog/001615860 ... 84e4dc7efd49e4a2000

报错是一样的。

出0入0汤圆

 楼主| 发表于 2022-4-28 16:13:09 | 显示全部楼层
发现这个问题是因为调用malloc,系统进入hardfault造成的。我这个芯片是STM32F103VET6,heap size和stack size都设为0x6000,24K的空间了还是一样出错!不懂为什么网上移植这个的他们没有报错呢?看了坛内朋友移植的,是STM32F407上的,用的是自已写的malloc函数。这个有能用系统自带malloc实现的方法,或者有可靠的malloc实现吗?谢谢各位大佬!

出0入8汤圆

发表于 2022-5-30 13:48:20 | 显示全部楼层



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2022-5-30 14:35:57 | 显示全部楼层
heap设置小了吧?可以参考一下FREEERTOS里的代码。

出0入90汤圆

发表于 2022-5-30 14:59:17 | 显示全部楼层
你用默认的malloc申请的内存是不会free的,然后很快堆栈就爆了,所以需要改成自定义的malloc。

出0入0汤圆

 楼主| 发表于 2022-6-1 12:50:11 | 显示全部楼层
astankvai 发表于 2022-5-30 14:35
heap设置小了吧?可以参考一下FREEERTOS里的代码。
(引用自5楼)

heap设置多大都会报错

出0入0汤圆

 楼主| 发表于 2022-6-1 12:51:26 | 显示全部楼层
honami520 发表于 2022-5-30 14:59
你用默认的malloc申请的内存是不会free的,然后很快堆栈就爆了,所以需要改成自定义的malloc。 ...
(引用自6楼)


对,我见网上放出来的代码,都是自定义的malloc,stm32f103有什么好用的mallock吗?

出0入8汤圆

发表于 2022-6-1 13:53:48 | 显示全部楼层


之前练习时用过的,用自带的malloc ,free测试是正常的。

源码:
链接:https://pan.baidu.com/s/1LEjAuTO84N087qU0WJMNqA
提取码:1234

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2022-6-1 16:44:22 | 显示全部楼层
skype 发表于 2022-6-1 13:53
之前练习时用过的,用自带的malloc ,free测试是正常的。

源码:
(引用自9楼)

谢谢,我看看
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-14 23:07

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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