Papalymo
Papalymo
人生苦短,及时行乐

注册于 1 year ago

回答
68
文章
16
关注者
16

在项目管理器,鼠标右键工程,点击更新软件包

init 是初始化信号量。

换成create:

key_it_sem = rt_sem_create("ksem", 100, RT_IPC_FLAG_PRIO);

或者修改信号量类型为:

struct rt_semaphore key_it_sem;

信号量参考例程:https://github.com/RT-Thread/rt-thread/blob/master/examples/utest/testcases/kernel/semaphore_tc.c

信号量文档:https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc1/ipc1?id=%e4%bf%a1%e5%8f%b7%e9%87%8f

打开你工程的 CJSON 软件包,使用 git bash 输入 git reset --hard

修改 sconscript 文件,把你想添加的 C 文件放在里面;鼠标右键工程,更新软件包,重新生成一下工程。

image.png

参考 ART-PI 代码:

/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author        Notes
 * 2018-12-13     balanceTWK    add sdcard port file
 * 2019-06-11     WillianChan   Add SD card hot plug detection
 */

#include <rtthread.h>

#ifdef BSP_USING_FS
#if DFS_FILESYSTEMS_MAX < 4
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
#endif
#if DFS_FILESYSTEM_TYPES_MAX < 4
#error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4"
#endif

#ifdef BSP_USING_SPI_FLASH_FS
#include "fal.h"
#endif

#include <dfs_fs.h>
#include "dfs_romfs.h"
#include "drv_sdio.h"

#define DBG_TAG "app.filesystem"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

static const struct romfs_dirent _romfs_root[] = {
    {ROMFS_DIRENT_DIR, "flash1", RT_NULL, 0},
    {ROMFS_DIRENT_DIR, "flash2", RT_NULL, 0},
    {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0}};

const struct romfs_dirent romfs_root = {
    ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])};

#ifdef BSP_USING_SDCARD_FS

/* SD Card hot plug detection pin */
#define SD_CHECK_PIN GET_PIN(D, 5)

static void _sdcard_mount(void)
{
    rt_device_t device;

    device = rt_device_find("sd0");
    if (device == NULL)
    {
        mmcsd_wait_cd_changed(0);
        sdcard_change();
        mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
        device = rt_device_find("sd0");
    }
    if (device != RT_NULL)
    {
        if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
        {
            LOG_I("sd card mount to '/sdcard'");
        }
        else
        {
            LOG_W("sd card mount to '/sdcard' failed!");
        }
    }
}

static void _sdcard_unmount(void)
{
    rt_thread_mdelay(200);
    dfs_unmount("/sdcard");
    LOG_I("Unmount \"/sdcard\"");

    mmcsd_wait_cd_changed(0);
    sdcard_change();
    mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
}

static void sd_mount(void *parameter)
{
    rt_uint8_t re_sd_check_pin = 1;
    rt_thread_mdelay(200);
    if (rt_pin_read(SD_CHECK_PIN))
    {
        _sdcard_mount();
    }
    while (1)
    {
        rt_thread_mdelay(200);
        if (!re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) != 0)
        {
            _sdcard_mount();
        }

        if (re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) == 0)
        {
            _sdcard_unmount();
        }
    }
}

#endif /* BSP_USING_SDCARD_FS */

#ifdef BSP_USING_FASTFS_FOMAT
extern int lpm_init(void);
#endif


int mount_init(void)
{
#ifdef RT_USING_DFS_ROMFS
    if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) != 0)
    {
        LOG_E("rom mount to '/' failed!");
    }
#endif
#ifdef BSP_USING_SPI_FLASH_FS
    struct rt_device *flash1_dev = RT_NULL;
    struct rt_device *flash2_dev = RT_NULL;

#ifndef RT_USING_WIFI
    fal_init();
#endif

    flash1_dev = fal_mtd_nor_device_create("filesystem");

    if (flash1_dev)
    {
        //mount filesystem
        if (dfs_mount(flash1_dev->parent.name, "/flash1", "elm", 0, 0) != 0)
        {
            LOG_W("mount to '/flash1' failed! try to mkfs %s", flash1_dev->parent.name);
            dfs_mkfs("lfs", flash1_dev->parent.name);
            if (dfs_mount(flash1_dev->parent.name, "/flash1", "lfs", 0, 0) == 0)
            {
                LOG_I("mount to '/flash1' success!");
            }
        }
        else
        {
            LOG_I("mount to '/flash1' success!");
        }
    }

    flash2_dev = fal_mtd_nor_device_create("easyflash");
    if (flash2_dev)
    {
        //mount filesystem
        if (dfs_mount(flash2_dev->parent.name, "/flash2", "elm", 0, 0) != 0)
        {
            LOG_W("mount to '/flash2' failed! try to mkfs %s", flash2_dev->parent.name);
            dfs_mkfs("lfs", flash2_dev->parent.name);
            if (dfs_mount(flash2_dev->parent.name, "/flash2", "lfs", 0, 0) == 0)
            {
                LOG_I("mount to '/flash2' success!");
            }
        }
        else
        {
            LOG_I("mount to '/flash2' success!");
        }
    }

#endif

#ifdef BSP_USING_SDCARD_FS
    rt_thread_t tid;

    rt_pin_mode(SD_CHECK_PIN, PIN_MODE_INPUT_PULLUP);

    tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
                           2048, RT_THREAD_PRIORITY_MAX - 2, 20);
    if (tid != RT_NULL)
    {
        rt_thread_startup(tid);
    }
    else
    {
        LOG_E("create sd_mount thread err!");
    }
#endif
    return RT_EOK;
}
INIT_APP_EXPORT(mount_init);

#endif /* BSP_USING_FS */

 \ | /
- RT -     Thread Operating System
 / | \     4.0.3 build Mar 19 2021
 2006 - 2020 Copyright by rt-thread team
[I/SDIO] SD card capacity 123008 KB.
[I/SDIO] switching card to high speed failed!
[I/SFUD] Find a Winbond flash chip. Size is 16777216 bytes.
[I/SFUD] norflash0 flash device is initialize success.
[I/SFUD] Probe SPI flash norflash0 by SPI device spi10 success.
[D/FAL] (fal_flash_init:63) Flash device |                norflash0 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name       | flash_dev |   offset   |    length  |
[I/FAL] -------------------------------------------------------------
[I/FAL] | wifi_image | norflash0 | 0x00000000 | 0x00080000 |
[I/FAL] | bt_image   | norflash0 | 0x00080000 | 0x00080000 |
[I/FAL] | download   | norflash0 | 0x00100000 | 0x00200000 |
[I/FAL] | easyflash  | norflash0 | 0x00300000 | 0x00100000 |
[I/FAL] | filesystem | norflash0 | 0x00400000 | 0x00c00000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer (V0.5.0) initialize success.
[I/FAL] The FAL MTD NOR device (filesystem) created successfully
The sector size of device is greater than the sector size of FAT.
[W/app.filesystem] mount to '/flash1' failed! try to mkfs filesyst
msh />[I/app.filesystem] mount to '/flash1' success!
[I/FAL] The FAL MTD NOR device (easyflash) created successfully
The sector size of device is greater than the sector size of FAT.
[W/app.filesystem] mount to '/flash2' failed! try to mkfs easyflas
[I/app.filesystem] sd card mount to '/sdcard'

msh />
msh />ls
Directory /:
flash1              <DIR>
flash2              <DIR>
sdcard              <DIR>

image.png
打开你的设备管理器,看看有没有串口设备

什么问题?问题是啥?啥是问题?

section `.text' will not fit in region `ROM' 

这种工具链编译的错误,百度都可以百度的到。flash 太小了。
https://blog.csdn.net/weixin_42566346/article/details/108406808

AC5:
rt_uint8_t ucHeap[64*1024] __attribute__((at(0x24000000)));

AC6:
rt_uint8_t ucHeap[64*1024] __attribute__((section(".ARM.__at_0x24000000")));

修改 SConscript 文件,添加这两个文件:
image.png

回到
顶部

发布
问题

投诉
建议