Hi expert,
My customer would like read/write Flash in application. They did a simple test by using gpio_led_blink_am243x-lp_r5fss0-0_nortos_ti-arm-clang in SDK8.6.
1. import demo project gpio_led_blink_am243x-lp_r5fss0-0_nortos_ti-arm-clang
2. Add Flash support in syscfg. use default setup for FLASH and OSPI.
3. Add FLASH access codes in gpio_led_blink.c basically it merge some code in ospi_flash_io demo codes.
/* * Copyright (C) 2021 Texas Instruments Incorporated * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <drivers/gpio.h> #include <kernel/dpl/AddrTranslateP.h> #include <kernel/dpl/DebugP.h> #include <kernel/dpl/ClockP.h> #include "ti_drivers_config.h" #include "ti_drivers_open_close.h" #include "ti_board_open_close.h" #include <board/flash.h> #define APP_OSPI_FLASH_OFFSET_BASE (0x40000U) #define APP_OSPI_DATA_SIZE (256) uint8_t gOspiTxBuf[APP_OSPI_DATA_SIZE]; /* read buffer MUST be cache line aligned when using DMA, we aligned to 128B though 32B is enough */ uint8_t gOspiRxBuf[APP_OSPI_DATA_SIZE] __attribute__((aligned(128U))); void ospi_flash_io_fill_buffers(); int32_t ospi_flash_io_compare_buffers(); /* * This example configures a GPIO pin connected to an LED on the EVM in * output mode. * The application toggles the LED on/off for 10 seconds and exits. */ void gpio_led_blink_main(void *args) { uint32_t loopcnt = 5, delaySec = 1; uint32_t gpioBaseAddr, pinNum; int32_t status = SystemP_SUCCESS; uint32_t i, offset; uint32_t blk, sector, page; Flash_Attrs *flashAttrs; /* Fill buffers with known data, * find block number from offset, * erase block, write the data, read back from a specific offset * and finally compare the results. */ offset = APP_OSPI_FLASH_OFFSET_BASE; ospi_flash_io_fill_buffers(); status = Flash_offsetToBlkPage(gFlashHandle[CONFIG_FLASH0], offset, &blk, &page); status = Flash_eraseBlk(gFlashHandle[CONFIG_FLASH0], blk); DebugP_log("Flash Erase status %d\r\n", status); status = Flash_write(gFlashHandle[CONFIG_FLASH0], offset, gOspiTxBuf, APP_OSPI_DATA_SIZE); DebugP_log("Flash write status %d\r\n", status); Flash_read(gFlashHandle[CONFIG_FLASH0], offset, gOspiRxBuf, APP_OSPI_DATA_SIZE); status |= ospi_flash_io_compare_buffers(); DebugP_log("Flash IO test status %d\r\n", status); for(i=0;i<APP_OSPI_DATA_SIZE;i++) DebugP_log("gOspiRxBuf[%d]=%d\r\n",i,gOspiRxBuf[i]); /* Open drivers to open the UART driver for console */ Drivers_open(); Board_driversOpen(); flashAttrs = Flash_getAttrs(CONFIG_FLASH0); DebugP_log("GPIO LED Blink Test Started ...\r\n"); DebugP_log("LED will Blink for %d seconds ...\r\n", (loopcnt * delaySec * 2)); /* Get address after translation translate */ gpioBaseAddr = (uint32_t) AddrTranslateP_getLocalAddr(GPIO_LED_BASE_ADDR); pinNum = GPIO_LED_PIN; while(loopcnt > 0) { GPIO_pinWriteHigh(gpioBaseAddr, pinNum); ClockP_sleep(delaySec); GPIO_pinWriteLow(gpioBaseAddr, pinNum); ClockP_sleep(delaySec); loopcnt--; } DebugP_log("GPIO LED Blink Test Passed!!\r\n"); DebugP_log("All tests have passed!!\r\n"); Board_driversClose(); Drivers_close(); } void ospi_flash_io_fill_buffers() { uint32_t i; for(i = 0U; i < APP_OSPI_DATA_SIZE; i++) { gOspiTxBuf[i] = i % 256; gOspiRxBuf[i] = 0U; } } int32_t ospi_flash_io_compare_buffers() { int32_t status = SystemP_SUCCESS; uint32_t i; for(i = 0U; i < APP_OSPI_DATA_SIZE; i++) { if(gOspiTxBuf[i] != gOspiRxBuf[i]) { status = SystemP_FAILURE; DebugP_logError("OSPI read data mismatch !!!\r\n"); break; } } return status; }
But after program executes, they always get erase error return from status = Flash_eraseBlk(gFlashHandle[CONFIG_FLASH0], blk);
They have some questions:
1. Anything missing so flash block erase fail? Why they can't erase and write to Flash in user application?
2. Do they need to turn on firewall/MPU or something else before they use Flash?
3. Can they use sector erase instead of block ease before they write data? (Sector Erase also fail in the test)
Regards
Andre