ESP32 application tutorial (2) - SD NAND (record flight control LOG)

Article Directory

foreword

1 Overview of SD NAND

2 code description

3 Record Log


foreword

This paper uses the ESP32 chip as the main controller to test the SD NAND recording flight control Log function.


Regarding the storage of the MCU , the built-in E2PROM or the external NOR Flash can be basically used in the past . With the rise of the Internet of Things, MCUs are used more and more widely, and gradually MCUs will involve large-capacity storage requirements for storing audio, pictures ( GUI ), video buffers, protocol stacks, etc. Traditional E2PROM and NOR Flash are not enough. At this time, the MCU may need to use NAND Flash .

For MCU needs to use large-capacity storage requirements, we recommend an easy-to-use, stable and reliable NAND FlashSD NAND .

1 Overview of SD NAND

The structure of SD NAND  adopts the NAND Flash ( SLC NAND Flash ) wafer with the longest service life and the most stable performance internally, and its erasing and writing life can reach 50,000 to 100,000 times. Built-in Flash controller and Firmware for NAND Flash management. The most versatile SD interface is used externally (almost all  MCUs have SD interfaces).

SD NAND, SMD TF card, SMD SD card, Beijing Ingenic, nor flash, storage, chip, master control, small capacity emmc, large capacity SLC Nand

This article chooses the CSNP32GCR01-AOW chip.

No need to write drivers, NAND Flash (SMD TF card) with bad block management, small size, easy to use, strong compatibility, stable and reliable, firmware can be customized, LGA-8 package, standard SDIO interface, compatible with SPI , Compatible with plug-in TF card/ SD card, can replace ordinary TF card/ SD card, size 6.2x8mm .

The built-in average reading and writing algorithm has passed 10,000 times of random power-off tests for high and low temperature resistance, and is very convenient for machine stickers and hand stickers. The speed level is Class10 (reading speed 23.5MB/s , writing speed 12.3MB/s ). The standard SD 2.0 protocol enables users to directly transplant the standard driver code, eliminating the need for driver code programming. All SOCs that support TF card booting can use SD NAND , provide STM32 reference routines and original technical support, capacity: 4GB , more stable than TF card, and cheaper than eMMC .

SD NAND, SMD TF card, SMD SD card, Beijing Ingenic, nor flash, storage, chip, master control, small capacity emmc, large capacity SLC Nand

2 code description

1. Macro definition to enable SD card function

#define HAL_ESP32_SDCARD

2. Mount the SD card

bool sdcard_retry(void)
{
    if(!card)
        return mount_sdcard();
    return true;
}
bool mount_sdcard()
{
    printf("............Try mount.\n");
    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;

    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config.flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP;

    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 5,
        .allocation_unit_size = 4 * 1024
    };
    esp_err_t ret = esp_vfs_fat_sdmmc_mount("/SDCARD", &host, &slot_config, &mount_config, &card);

    if (ret == ESP_OK) {
        mkdir("/SDCARD/APM", 0777);
        printf("sdcard is mounted\n");
        update_fw();
        return true;
    } else {
        printf("sdcard is not mounted.\n");
        return false;
    }
}

3. Unmount the SD card

void sdcard_stop(void)
{
    unmount_sdcard();
}
void unmount_sdcard()
{
    if (card != nullptr) {
        esp_vfs_fat_sdmmc_unmount();
    }
}

3 Record Log

1. LOG directory creation

It can be seen that the flight control has  successfully established the LOG directory in SD NAND .

2. LOG analysis

The aircraft is powered on, the fuselage is rolled, and the attitude angle of the aircraft is recorded.

Download logs to load into Mission Planner software. Check Roll and Pitch in the ATT field . It can be seen that the curve follows the aircraft attitude change.

So far, using SD NAND instead of SD card, the test flight control LOG recording function is completed.

Guess you like

Origin blog.csdn.net/qq_20016593/article/details/132558173