diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-05-24 20:10:57 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-05-24 20:10:57 +0000 |
commit | c0c9fe70b0dbce03d83d0c5b5c2177c01e7faa91 (patch) | |
tree | b152a2e9500d2836bbaabae2bef5786ac3ebca9d | |
parent | 8c8a1441fd198586aa1abd0e4b1231ac3445355b (diff) | |
download | ChibiOS-c0c9fe70b0dbce03d83d0c5b5c2177c01e7faa91.tar.gz ChibiOS-c0c9fe70b0dbce03d83d0c5b5c2177c01e7faa91.tar.bz2 ChibiOS-c0c9fe70b0dbce03d83d0c5b5c2177c01e7faa91.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9519 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | os/ex/Micron/m25q.c | 130 | ||||
-rw-r--r-- | testhal/STM32/STM32L4xx/QSPI-N25Q128/debug/QSPI-N25Q128 (OpenOCD, Flash and Run).launch | 2 |
2 files changed, 131 insertions, 1 deletions
diff --git a/os/ex/Micron/m25q.c b/os/ex/Micron/m25q.c index 84a67f2cc..ac93a4f54 100644 --- a/os/ex/Micron/m25q.c +++ b/os/ex/Micron/m25q.c @@ -565,21 +565,151 @@ static flash_error_t program(void *instance, flash_address_t addr, } static flash_error_t start_erase_all(void *instance) { + M25QDriver *devp = (M25QDriver *)instance; + + osalDbgCheck(instance != NULL); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* Bus acquired.*/ + flash_bus_acquire(devp); + + /* FLASH_ERASE state while the operation is performed.*/ + devp->state = FLASH_ERASE; + + /* Enabling write operation.*/ + flash_cmd(devp, M25Q_CMD_WRITE_ENABLE); + + /* Bulk erase command.*/ + flash_cmd(devp, M25Q_CMD_BULK_ERASE); + + /* Ready state again.*/ + devp->state = FLASH_READY; + + /* Bus released.*/ + flash_bus_release(devp); return FLASH_NO_ERROR; } static flash_error_t start_erase_sector(void *instance, flash_sector_t sector) { + M25QDriver *devp = (M25QDriver *)instance; + flash_address_t addr = (flash_address_t)(sector * SECTOR_SIZE); + + osalDbgCheck(instance != NULL); + osalDbgCheck(sector < descriptor.sectors_count); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* Bus acquired.*/ + flash_bus_acquire(devp); + + /* FLASH_ERASE state while the operation is performed.*/ + devp->state = FLASH_ERASE; + + /* Enabling write operation.*/ + flash_cmd(devp, M25Q_CMD_WRITE_ENABLE); + + /* Sector erase command.*/ + flash_cmd_addr(devp, M25Q_CMD_SECTOR_ERASE, addr); + + /* Ready state again.*/ + devp->state = FLASH_READY; + + /* Bus released.*/ + flash_bus_release(devp); return FLASH_NO_ERROR; } static flash_error_t verify_erase(void *instance, flash_sector_t sector) { + M25QDriver *devp = (M25QDriver *)instance; + unsigned i; + + osalDbgCheck(instance != NULL); + osalDbgCheck(sector < descriptor.sectors_count); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* Bus acquired.*/ + flash_bus_acquire(devp); + + /* FLASH_READY state while the operation is performed.*/ + devp->state = FLASH_READ; + + /* Read command.*/ + + /* Ready state again.*/ + devp->state = FLASH_READY; + + /* Bus released.*/ + flash_bus_release(devp); return FLASH_NO_ERROR; } static flash_error_t query_erase(void *instance, uint32_t *msec) { + M25QDriver *devp = (M25QDriver *)instance; + uint8_t sts; + + osalDbgCheck(instance != NULL); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + /* If there is an erase in progress then the device must be checked.*/ + if (devp->state == FLASH_ERASE) { + + /* Bus acquired.*/ + flash_bus_acquire(devp); + + /* Read status command.*/ + flash_cmd_receive(devp, M25Q_CMD_READ_FLAG_STATUS_REGISTER, 1, &sts); + + /* If the P/E bit is zero (busy) or the flash in a suspended state then + report that the operation is still in progress.*/ + if (((sts & M25Q_FLAGS_PROGRAM_ERASE) == 0U) || + ((sts & M25Q_FLAGS_ERASE_SUSPEND) != 0U)) { + + /* Bus released.*/ + flash_bus_release(devp); + + /* Recommended time before polling again, this is a simplified + implementation.*/ + if (msec != NULL) { + *msec = 1U; + } + + return FLASH_BUSY_ERASING; + } + + /* The device is ready to accept commands.*/ + devp->state = FLASH_READY; + + /* Checking for errors.*/ + if ((sts & M25Q_FLAGS_ALL_ERRORS) != 0U) { + + /* Clearing status register.*/ + flash_cmd(devp, M25Q_CMD_CLEAR_FLAG_STATUS_REGISTER); + + /* Erase operation failed.*/ + return FLASH_ERROR_ERASE; + } + + /* Bus released.*/ + flash_bus_release(devp); + } return FLASH_NO_ERROR; } diff --git a/testhal/STM32/STM32L4xx/QSPI-N25Q128/debug/QSPI-N25Q128 (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32L4xx/QSPI-N25Q128/debug/QSPI-N25Q128 (OpenOCD, Flash and Run).launch index 573a54f12..9187ae1d8 100644 --- a/testhal/STM32/STM32L4xx/QSPI-N25Q128/debug/QSPI-N25Q128 (OpenOCD, Flash and Run).launch +++ b/testhal/STM32/STM32L4xx/QSPI-N25Q128/debug/QSPI-N25Q128 (OpenOCD, Flash and Run).launch @@ -33,7 +33,7 @@ <intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
-<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="CCR-qspi-qspip-qspi_lld_receive-(format)" val="4"/><content id="cfg-cmdp-qspi_lld_receive-(format)" val="4"/><content id="id[2]-id-m25qStart-(format)" val="4"/><content id="id[1]-id-m25qStart-(format)" val="4"/><content id="id[0]-id-m25qStart-(format)" val="4"/><content id="AFRL-gpiop-initgpio-(format)" val="4"/><content id="AFRH-gpiop-initgpio-(format)" val="4"/><content id="ODR-gpiop-initgpio-(format)" val="4"/><content id="IDR-gpiop-initgpio-(format)" val="4"/><content id="PUPDR-gpiop-initgpio-(format)" val="4"/><content id="OSPEEDR-gpiop-initgpio-(format)" val="4"/><content id="MODER-gpiop-initgpio-(format)" val="4"/><content id="afrh-config-initgpio-(format)" val="4"/><content id="moder-config-initgpio-(format)" val="4"/><content id="config-initgpio-(format)" val="4"/><content id="r2-(format)" val="4"/><content id="cfg-cmdp-qspiReceive-(format)" val="4"/><content id="CCR-qspi-qspip-qspi_lld_send-(format)" val="4"/><content id="CR-qspi-qspip-qspi_lld_send-(format)" val="4"/><content id="cfg-cmdp-qspiSend-(format)" val="4"/><content id="CR2-adc-adcp-adc_lld_start_conversion-(format)" val="4"/><content id="CR2-adc-null-port_wait_for_interrupt-(format)" val="4"/><content id="cr2-adc_lld_start_conversion-(format)" val="4"/><content id="cmd-flash_cmd_receive-(format)" val="4"/></contentList>"/>
+<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="cmd-flash_cmd_receive-(format)" val="4"/><content id="cr2-adc_lld_start_conversion-(format)" val="4"/><content id="CR2-adc-null-port_wait_for_interrupt-(format)" val="4"/><content id="CR2-adc-adcp-adc_lld_start_conversion-(format)" val="4"/><content id="cfg-cmdp-qspiSend-(format)" val="4"/><content id="CR-qspi-qspip-qspi_lld_send-(format)" val="4"/><content id="CCR-qspi-qspip-qspi_lld_send-(format)" val="4"/><content id="cfg-cmdp-qspiReceive-(format)" val="4"/><content id="r2-(format)" val="4"/><content id="config-initgpio-(format)" val="4"/><content id="moder-config-initgpio-(format)" val="4"/><content id="afrh-config-initgpio-(format)" val="4"/><content id="MODER-gpiop-initgpio-(format)" val="4"/><content id="OSPEEDR-gpiop-initgpio-(format)" val="4"/><content id="PUPDR-gpiop-initgpio-(format)" val="4"/><content id="IDR-gpiop-initgpio-(format)" val="4"/><content id="ODR-gpiop-initgpio-(format)" val="4"/><content id="AFRH-gpiop-initgpio-(format)" val="4"/><content id="AFRL-gpiop-initgpio-(format)" val="4"/><content id="id[0]-id-m25qStart-(format)" val="4"/><content id="id[1]-id-m25qStart-(format)" val="4"/><content id="id[2]-id-m25qStart-(format)" val="4"/><content id="cfg-cmdp-qspi_lld_receive-(format)" val="4"/><content id="CCR-qspi-qspip-qspi_lld_receive-(format)" val="4"/></contentList>"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList/> "/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
|