[INFO] Flash Driver model

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: [INFO] Flash Driver model

Postby Tabulous » Fri Mar 10, 2017 1:21 pm

Hi there is an error on this driver.

When JESD216_BUS_MODE is defined as SPI i.e.

Code: Select all

#if !defined(JESD216_BUS_MODE) || defined(__DOXYGEN__)
#define JESD216_BUS_MODE                    JESD216_BUS_MODE_SPI
#endif


the driver will not compile, there are errors in hal_jesd216_flash.c like this one where addr is used undeclared as it does not exist.

Code: Select all

void jesd216_cmd_addr(BUSDriver *busp,
                      uint32_t cmd,
                      flash_offset_t offset) {
#if JESD216_BUS_MODE != JESD216_BUS_MODE_SPI
  qspi_command_t mode;

  mode.cfg = QSPI_CFG_CMD(cmd) |
#if JESD216_BUS_MODE == JESD216_BUS_MODE_QSPI1L
             QSPI_CFG_CMD_MODE_ONE_LINE |
             QSPI_CFG_ADDR_MODE_ONE_LINE |
             QSPI_CFG_ADDR_SIZE_24;
#elif JESD216_BUS_MODE == JESD216_BUS_MODE_QSPI2L
             QSPI_CFG_CMD_MODE_TWO_LINES |
             QSPI_CFG_ADDR_MODE_TWO_LINES |
             QSPI_CFG_ADDR_SIZE_24;
#else
             QSPI_CFG_CMD_MODE_FOUR_LINES |
             QSPI_CFG_ADDR_MODE_FOUR_LINES |
             QSPI_CFG_ADDR_SIZE_24;

#endif
  mode.addr = offset;
  mode.alt  = 0U;
  qspiCommand(busp, &mode);
#else
  uint8_t buf[4];

  spiSelect(busp);
  buf[0] = cmd;
  buf[1] = (uint8_t)(addr >> 16);
  buf[2] = (uint8_t)(addr >> 8);
  buf[3] = (uint8_t)(addr >> 0);
  spiSend(busp, 4, buf);
  spiUnselect(busp);
#endif
}

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: [INFO] Flash Driver model

Postby Tabulous » Fri Mar 10, 2017 3:11 pm

Also think the demo code is wrong i.e.

flashRead in teh demo passes driver object, sector offset, pointer to buffer and byte count

/* Reading back for confirmation.*/
err = flashRead(&flash, 0, buffer, 128);
if (err != FLASH_NO_ERROR)
chSysHalt("read error");


but the the definition / prototype is different, the byte count and pointer to buffer are swapped ???


/**
* @brief Read operation.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @param[in] offset flash offset
* @param[in] n number of bytes to be read
* @param[out] rp pointer to the data buffer
* @return An error code.
* @retval FLASH_NO_ERROR if there is no erase operation in progress.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_READ if the read operation failed.
*
* @api
*/
#define flashRead(ip, offset, n, rp) \
(ip)->vmt->program(ip, offset, n, pp)

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: [INFO] Flash Driver model

Postby Giovanni » Fri Mar 10, 2017 3:51 pm

Hi,

Thanks, I will give it a try again, I stopped working on it.

Giovanni

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: [INFO] Flash Driver model

Postby Tabulous » Fri Mar 10, 2017 4:01 pm

Giovanni wrote:Hi,

Thanks, I will give it a try again, I stopped working on it.

Giovanni


Am just in th process of getting it working with cyprus s25fl116 flash chip, once ive got it done i'll post it back hear.
Last edited by Tabulous on Fri Mar 10, 2017 4:55 pm, edited 1 time in total.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: [INFO] Flash Driver model

Postby Giovanni » Fri Mar 10, 2017 4:18 pm

OK thanks.

Giovanni

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: [INFO] Flash Driver model

Postby Tabulous » Sat Mar 11, 2017 10:13 am

Hi Giovanni
Here is updated driver that is now working.

There is a bit of difference between the Micron and the Cypress flash, mainly to do with the status reg.

Think the overall struct is good :-)

Cheers

PS i have FatFS and Eprom Emulation running over this too, FAT on flash with out FTL/wear leveling is not ideal, but the application will not write alot, mainly read.

I'll post the fatfs_diskio interface soon, as just need to tidy it up lol.
Attachments
Spi Flash Driver.zip
(17.22 KiB) Downloaded 267 times

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: [INFO] Flash Driver model

Postby Tabulous » Thu Mar 16, 2017 5:04 pm

Here is fatfs_diskio and also wrapper files :-)
Attachments
fatfs_diskio.zip
(2.93 KiB) Downloaded 247 times

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: [INFO] Flash Driver model

Postby Giovanni » Sun Jan 06, 2019 4:54 pm

Hi,

Now there is a new flash infrastructure so probably all this is no more actual. Are you planning to port this work to the new trunk code? adding flash devices should be much easier now.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 42 guests