diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index d08d156098..fe3f0b0898 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -15,7 +15,6 @@ add_subdirectory(${LIBS_DIR}/InvestigationDay/LekaRFID) add_subdirectory(${LIBS_DIR}/InvestigationDay/LekaWifi) add_subdirectory(${LIBS_DIR}/InvestigationDay/LekaTouch) add_subdirectory(${LIBS_DIR}/InvestigationDay/LekaScreen) -add_subdirectory(${LIBS_DIR}/InvestigationDay/LekaFirmware) add_subdirectory(${LIBS_DIR}/InvestigationDay/LekaBluetooth) add_subdirectory(${LIBS_DIR}/LKAnimationKit) diff --git a/libs/InvestigationDay/LekaFirmware/CMakeLists.txt b/libs/InvestigationDay/LekaFirmware/CMakeLists.txt deleted file mode 100644 index c4bd545de6..0000000000 --- a/libs/InvestigationDay/LekaFirmware/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Leka - LekaOS -# Copyright 2020 APF France handicap -# SPDX-License-Identifier: Apache-2.0 - -add_library(lib_LekaFirmware STATIC) - -target_include_directories(lib_LekaFirmware - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/include/internal -) - -target_sources(lib_LekaFirmware - PRIVATE - source/LekaFirmware.cpp -) - -target_link_libraries(lib_LekaFirmware mbed-os) diff --git a/libs/InvestigationDay/LekaFirmware/include/LekaFirmware.h b/libs/InvestigationDay/LekaFirmware/include/LekaFirmware.h deleted file mode 100644 index b48070add2..0000000000 --- a/libs/InvestigationDay/LekaFirmware/include/LekaFirmware.h +++ /dev/null @@ -1,54 +0,0 @@ -// Leka - LekaOS -// Copyright 2020 APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -#ifndef _LEKA_OS_LIB_FIRMWARE_H_ -#define _LEKA_OS_LIB_FIRMWARE_H_ - -#include - -#include "PinNames.h" - -#include "drivers/DigitalOut.h" -#include "drivers/QSPI.h" -#include "rtos/ThisThread.h" -#include "rtos/Thread.h" - -#include "IS25LP016D.h" - -typedef enum ext_flash_status -{ - EXTERNAL_FLASH_STATUS_ERROR = 1, /**< Generic error >*/ - EXTERNAL_FLASH_STATUS_INVALID_PARAMETER = 2, /**< The parameter is invalid >*/ - EXTERNAL_FLASH_STATUS_OK = 0, /**< Function executed sucessfully >*/ -} ext_flash_status_t; - -class Firmware -{ - public: - Firmware(); - ~Firmware() {}; - - void init(); - ext_flash_status_t initExternalFlash(); - - void selectMemory(uint8_t memory_number); - bool memoryIsReady(); - - ext_flash_status writeEnable(); - ext_flash_status_t eraseSector(uint8_t address); - ext_flash_status_t write(uint8_t address, const char *buffer, size_t buffer_length, bool priorErase = false); - ext_flash_status_t read(uint8_t address, char *buffer, size_t buffer_length); - - void checkActiveFlash(); - void start(void); - - private: - mbed::QSPI _interface; - uint8_t _selected_memory; - mbed::DigitalOut _disable_ext_memory_1; - mbed::DigitalOut _disable_ext_memory_2; - mbed::DigitalOut _disable_ext_memory_3; -}; - -#endif diff --git a/libs/InvestigationDay/LekaFirmware/include/internal/IS25LP016D.h b/libs/InvestigationDay/LekaFirmware/include/internal/IS25LP016D.h deleted file mode 100644 index 38af114711..0000000000 --- a/libs/InvestigationDay/LekaFirmware/include/internal/IS25LP016D.h +++ /dev/null @@ -1,24 +0,0 @@ -// Leka - LekaOS -// Copyright 2020 APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -#ifndef _LEKA_OS_LIB_QSPI_IS25LP016D_H_ -#define _LEKA_OS_LIB_QSPI_IS25LP016D_H_ - -#include - -constexpr uint8_t CMD_READ = 0x03; -constexpr uint8_t CMD_WRITE = 0x02; -constexpr uint8_t CMD_ERASE = 0x20; -constexpr uint8_t CMD_RDSR = 0x5; -constexpr uint8_t CMD_WREN = 0x6; -constexpr uint8_t CMD_RSTEN = 0x66; -constexpr uint8_t CMD_RST = 0x99; - -constexpr uint8_t STATUS_REG_SIZE = 2; -constexpr uint8_t BIT_WIP = 0x01; -constexpr uint8_t BIT_WEL = 0x02; - -constexpr int ExtFlashSize = 0x00200000; - -#endif diff --git a/libs/InvestigationDay/LekaFirmware/source/LekaFirmware.cpp b/libs/InvestigationDay/LekaFirmware/source/LekaFirmware.cpp deleted file mode 100644 index a0b4af5124..0000000000 --- a/libs/InvestigationDay/LekaFirmware/source/LekaFirmware.cpp +++ /dev/null @@ -1,285 +0,0 @@ -// Leka - LekaOS -// Copyright 2020 APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -#if !DEVICE_QSPI - #error[NOT_SUPPORTED] QSPI not supported for this target -#endif - -#include "LekaFirmware.h" - -using namespace mbed; -using namespace std::chrono; - -Firmware::Firmware() - : _interface(QSPI_FLASH_IO0, QSPI_FLASH_IO1, QSPI_FLASH_IO2, QSPI_FLASH_IO3, QSPI_FLASH_CLK, QSPI_FLASH_nCS), - _disable_ext_memory_1(QSPI_FLASH_nCS, 1), - _disable_ext_memory_2(QSPI_FLASH_nCS, 1), - _disable_ext_memory_3(QSPI_FLASH_nCS, 1) -{ - rtos::ThisThread::sleep_for(10ms); - init(); -} - -void Firmware::init() -{ - qspi_status_t qspi_status = QSPI_STATUS_OK; - ext_flash_status_t external_flash_status = EXTERNAL_FLASH_STATUS_OK; - - /* Set QSPI interface configuration */ - qspi_status = _interface.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, - QSPI_CFG_BUS_SINGLE, QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0); - if (qspi_status != QSPI_STATUS_OK) { - printf("Config format failed\n"); - return; - } - - /* Init 3 flash external memory */ - for (uint8_t memory_number = 1; memory_number < 4; memory_number++) { - selectMemory(memory_number); - external_flash_status = initExternalFlash(); - } - - if (external_flash_status != EXTERNAL_FLASH_STATUS_OK) { - printf("Init failed\n"); - return; - } - - return; -} - -ext_flash_status_t Firmware::initExternalFlash() -{ - qspi_status_t status = QSPI_STATUS_OK; - char status_value[STATUS_REG_SIZE] = {0}; - - /* Read the Status Register from device */ - status = _interface.command_transfer(CMD_RDSR, -1, NULL, 0, status_value, STATUS_REG_SIZE); - if (status != QSPI_STATUS_OK) { - printf("Reading Status Register failed: value = 0x%x\n", (int)status_value[0]); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - /* Send Reset Enable */ - status = _interface.command_transfer(CMD_RSTEN, -1, NULL, 0, NULL, 0); - if (status != QSPI_STATUS_OK) { - printf("Sending RSTEN failed \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - if (false == memoryIsReady()) { - printf("Device not ready \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - /* Send Reset */ - status = _interface.command_transfer(CMD_RST, -1, NULL, 0, NULL, 0); - if (status != QSPI_STATUS_OK) { - printf("Sending RST failed \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - if (false == memoryIsReady()) { - printf("Device not ready \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - if (status == QSPI_STATUS_OK) { - return EXTERNAL_FLASH_STATUS_OK; - } else { - return EXTERNAL_FLASH_STATUS_ERROR; - } -} - -void Firmware::selectMemory(uint8_t memory_number) -{ - if (memory_number == _selected_memory) { - return; - } - - _disable_ext_memory_1 = 1; - _disable_ext_memory_2 = 1; - _disable_ext_memory_3 = 1; - - switch (memory_number) { - case 1: - _disable_ext_memory_1 = 0; - _selected_memory = 1; - break; - case 2: - _disable_ext_memory_2 = 0; - _selected_memory = 2; - break; - case 3: - _disable_ext_memory_3 = 0; - _selected_memory = 3; - break; - default: - _selected_memory = 0; - break; - } - - return; -} - -bool Firmware::memoryIsReady() -{ - char status_value[STATUS_REG_SIZE] = {0xFF}; - int retries = 10000; - bool mem_ready = true; - - do { - retries--; - if (QSPI_STATUS_OK != _interface.command_transfer(CMD_RDSR, -1, NULL, 0, status_value, STATUS_REG_SIZE)) { - printf("Reading Status Register failed \n"); - } - rtos::ThisThread::sleep_for(1ms); - } while ((status_value[0] & BIT_WIP) != 0 && retries); - - if ((status_value[0] & BIT_WIP) != 0) { - printf("mem_ready FALSE: status value = 0x%x\n", (int)status_value[0]); - mem_ready = false; - } - return mem_ready; -} - -ext_flash_status_t Firmware::writeEnable() -{ - char status_value[STATUS_REG_SIZE] = {0}; - ext_flash_status_t status = EXTERNAL_FLASH_STATUS_ERROR; - - if (QSPI_STATUS_OK != _interface.command_transfer(CMD_WREN, -1, NULL, 0, NULL, 0)) { - printf("Sending WREN command FAILED \n"); - return status; - } - - if (false == memoryIsReady()) { - printf("Device not ready \n"); - return status; - } - - if (QSPI_STATUS_OK != _interface.command_transfer(CMD_RDSR, -1, NULL, 0, status_value, STATUS_REG_SIZE)) { - printf("Reading Status Register failed \n"); - return status; - } - - if ((status_value[0] & BIT_WEL)) { - status = EXTERNAL_FLASH_STATUS_OK; - } - return status; -} - -ext_flash_status_t Firmware::eraseSector(uint8_t sector_address) -{ - if (0 != writeEnable()) { - printf("Write Enable failed \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - if (QSPI_STATUS_OK != - _interface.command_transfer(CMD_ERASE, (((int)sector_address) & 0x00FFF000), NULL, 0, NULL, 0)) { - printf("Erase failed\n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - if (false == memoryIsReady()) { - printf("Device not ready \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - return EXTERNAL_FLASH_STATUS_OK; -} - -ext_flash_status_t Firmware::write(uint8_t address, const char *buffer, size_t buffer_length, bool priorErase) -{ - qspi_status_t result; - - if (priorErase && eraseSector(address) != EXTERNAL_FLASH_STATUS_ERROR) { - return EXTERNAL_FLASH_STATUS_ERROR; - } - - if (0 != writeEnable()) { - printf("Write Enable failed \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - result = _interface.write(CMD_WRITE, -1, address, buffer, &buffer_length); - if (result != QSPI_STATUS_OK) { - printf("Write failed\n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - // printf("Write done: %s \n", buffer); - - return EXTERNAL_FLASH_STATUS_OK; -} - -ext_flash_status_t Firmware::read(uint8_t address, char *buffer, size_t buffer_length) -{ - qspi_status_t result; - - if (memoryIsReady() == false) { - printf("Device not ready \n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - result = _interface.read(CMD_READ, -1, address, buffer, &buffer_length); - if (result != QSPI_STATUS_OK) { - printf("Read failed\n"); - return EXTERNAL_FLASH_STATUS_ERROR; - } - - // printf(" %04X ", address); - // for (uint8_t j = 0; j < buffer_length; j++) { printf("%02X", buffer[j]); } - // printf("\n"); - - return EXTERNAL_FLASH_STATUS_OK; -} - -void Firmware::checkActiveFlash() -{ - const uint16_t message_size = 0x100; - char message_to_write[message_size] = {0}; - char buffer[message_size] = {0}; - for (uint16_t content = 0x00; content < message_size; content += 0x01) { - message_to_write[content] = (uint8_t)content; - } - - for (uint32_t address = 0x0; address < ExtFlashSize; address += message_size) { - /* Write on flash */ - write(address, message_to_write, message_size); // Do not erase (0x1000) before write - - /* Read to check good writing */ - for (uint16_t i = 0; i < message_size; i++) { - buffer[i] = 0x00; - } - - read(address, buffer, message_size); - if (memcmp(message_to_write, buffer, message_size) != 0) { - printf("Error on external memory #%d at address 0x%lX\n", _selected_memory, address); - return; - } - if (address != 0x0 && address % 0x10000 == 0x0000) { - printf("Block(64kB) from 0x%lX to 0x%lX on external memory #%d is fine\n", address - 0x10000, address, - _selected_memory); - } - } - - printf("External memory #%d is OK!\n", _selected_memory); - return; -} - -void Firmware::start() -{ - printf("Firmware example\n\n"); - - while (true) { - for (uint8_t memoryNumber = 1; memoryNumber < 4; memoryNumber++) { - selectMemory(memoryNumber); - checkActiveFlash(); - } - - rtos::ThisThread::sleep_for(10s); - } - - printf("End of Firmware example\n\n"); -}