~aleteoryx/muditaos

9d94c84cd9b97620c16c9ba7ec5e70abca700c50 — Lukasz Skrzypczak 4 years ago de22ef3
[EGD-6576] Create EEPROM low level driver

Working eeprom driver.
M module-bsp/board/rt1051/bsp/eeprom/M24256.hpp => module-bsp/board/rt1051/bsp/eeprom/M24256.hpp +2 -0
@@ 10,6 10,8 @@ namespace bsp::eeprom
    constexpr inline auto M24256_MEM_DEVICE_ADDR = (0xA0 >> 1);
    constexpr inline auto M24256_ID_DEVICE_ADDR  = (0xB0 >> 1);

    constexpr inline auto M24256_DEV_ID_MASK = 0x07;

    constexpr inline auto M24256_PAGE_SIZE  = 64;
    constexpr inline auto M24256_TOTAL_SIZE = (32 * 1024); // bytes


M module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp => module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp +6 -4
@@ 34,8 34,8 @@ namespace bsp::eeprom
    bool isPresent(int busid)
    {
        std::uint8_t readout;
        addr.deviceAddress |= static_cast<uint32_t>(busid) & 0x7;
        addr.subAddress = 0x00;
        addr.deviceAddress |= static_cast<uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.subAddress = 0x0000;
        return i2c->Read(addr, &readout, 1) > 0;
    }



@@ 44,7 44,7 @@ namespace bsp::eeprom
        size_t written = 0;
        char* ptr = const_cast<char *>(buf);

        addr.deviceAddress |= static_cast<uint32_t>(busid) & 0x7;
        addr.deviceAddress |= static_cast<uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.subAddress = mem_addr;
        
        size_t bl_len = static_cast<size_t>(eeprom_block_size(busid));


@@ 59,6 59,7 @@ namespace bsp::eeprom
            {
                LOG_DEBUG("[EEPROM - W] writing chunk %d of %d", i, chunks);
                written += i2c->Write(addr, reinterpret_cast<uint8_t *>(ptr), static_cast<size_t>(bl_len));
                vTaskDelay(10 / portTICK_PERIOD_MS);
                ptr += bl_len;
                addr.subAddress += bl_len;
            }


@@ 68,6 69,7 @@ namespace bsp::eeprom
        {
            LOG_DEBUG("[EEPROM - W] writing remaining %d bytes", reminder);
            written += i2c->Write(addr, reinterpret_cast<uint8_t *>(ptr), reminder);
            vTaskDelay(10 / portTICK_PERIOD_MS);
        }

        return static_cast<int>(written);


@@ 78,7 80,7 @@ namespace bsp::eeprom
        size_t read = 0;
        char* ptr = const_cast<char *>(buf);

        addr.deviceAddress |= static_cast<uint32_t>(busid) & 0x7;
        addr.deviceAddress |= static_cast<uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.subAddress = mem_addr;
        
        size_t bl_len = static_cast<size_t>(eeprom_block_size(busid));

M module-vfs/board/rt1051/purefs/src/blkdev/disk_emmc.cpp => module-vfs/board/rt1051/purefs/src/blkdev/disk_emmc.cpp +0 -16
@@ 40,22 40,6 @@ namespace purefs::blkdev
            initStatus = err;
            return initStatus;
        }
        //EEPROM test
        auto isEEPPresent = bsp::eeprom::init();
        LOG_DEBUG("EEPROM init %s", isEEPPresent ? "SUCCESS" : "FAIL");
        char buf[256] = {0};
        LOG_DEBUG("EEPROM: writing 16 B");
        auto written = bsp::eeprom::eeprom_write(0, 0x0000, reinterpret_cast<const char*>(const_cast<const char*>(buf)), 16);
        auto read = bsp::eeprom::eeprom_write(0, 0x0000, buf, 16);
        LOG_DEBUG("... w=%d, r=%d %s", written, read, (written == read) ? "SUCCESS" : "FAIL");
        LOG_DEBUG("EEPROM: writing 64 B");
        written = bsp::eeprom::eeprom_write(0, 0x0000, reinterpret_cast<const char*>(const_cast<const char*>(buf)), 64);
        read = bsp::eeprom::eeprom_write(0, 0x0000, buf, 64);
        LOG_DEBUG("... w=%d, r=%d %s", written, read, (written == read) ? "SUCCESS" : "FAIL");
        LOG_DEBUG("EEPROM: writing 256 B");
        written = bsp::eeprom::eeprom_write(0, 0x0000, reinterpret_cast<const char*>(const_cast<const char*>(buf)), 256);
        read = bsp::eeprom::eeprom_write(0, 0x0000, buf, 256);
        LOG_DEBUG("... w=%d, r=%d %s", written, read, (written == read) ? "SUCCESS" : "FAIL");

        return statusBlkDevSuccess;
    }