Skip to main content

Transfer data from SPI-flash to a client

2 weeks ago

Transfer data from SPI-flash to a client

Posted byPsomvanshi45 points 3 replies
0 upvotes

Hey!

I'm new to the DA 14531 Pro Development Kit and kind of lost on which documentation to follow.

Problem: A series of data is stored in SPI-flash with their starting and ending address known. I have to send the data to a client (E.g. Lightblue app on a smartphone) whenever the client requests it.

Work done so far: I've set up SDK6.0.14.1114 environment and gone through theBlinky & Barebone BLE example,BLE Advertising TutorialandCreating GATT profile characteristic.

I know how to create a new characteristic but I don't know how to write a function that reads data successively from SPI flash and then sends that to the client via the characteristic.

I understand that this is an open-ended question. So, I'd be grateful if you could point me towards relevant documentation that demonstrates a similar application.

2 weeks ago

MHv_Dialog

Hi,

I suggest that you take a look at how our CodeLess implementation transfers data between a client and server. CodeLess uses three characteristics for data transfer:

  1. A characteristic that the client writes to when it sends a command to the client
  2. A characteristic that the server populates when it has a reply ready
  3. A simple one byte characteristic that the server uses to notify the client when a response is ready and can be read by the client

It is worth mentioning that this could all be achieved with just one characteristic, but this would make the implementation much more convoluted.

I suggest that you use the CodeLess methodology. The client can then send commands to the server to read a certain section of the flash, and the server can notify the server when data is ready. You could even implement a command structure where the client can specify the address that the server should start reading from.

I hope this helps.

/MHv

2 weeks ago

Psomvanshi 45 points

Thank you for your reply. But due to multiple reasons (one of them being that this design is a part of a larger project), I can't use the CodeLess implementation.

I'm thinking of creating a new characteristic (say, FLASH_READ) as explained inCreating GATT profile characteristic. Next, I'm thinking to write handler function (say, user_svc1_flash_rd_ind_handler) that reads the flash memory when a read request is received. I'll then combine this handler function with the reception of request to read flash memory by modifying the user_catch_rest_hndl function in the user_peripheral.c file. A similar implementation is shownhere.

Is the above method correct? If yes, then the only problem is to write the definition of handler function user_svc1_flash_rd_ind_handler. I don't know how to read the flash memory in this case. Is there any function/API used to do so? Alternately, is there any example or tutorial that demonstrates a similar implementation?

2 weeks ago

MHv_Dialog

Hi,

I wasn't really suggesting that you use CodeLess in your application. I was suggesting that you use the same data exchange mechanism. Depending on how much data you intend to read from the flash, you will need some sort of handshaking mechanism because a characteristic can only hold 512 bytes. You will also need this type of mechanism to inform the client device that data is ready for a read - unless you also implement a service on the central device that the peripheral device can write data to directly.

Using the catch_rest handler is the proper way to implement handling of incoming data/requests. I do not recommend implementing a read handler as you suggest. A read should pertain to data already populated in the GATT database and the SDK handles that automatically.

The SDK contains a nice little flash demonstration project that I think will provide you everything you need: ..\DA145xx_SDK\6.0.14.1114\projects\target_apps\peripheral_examples\spi\spi_flash\Keil_5\spi_flash.uvprojx

/MHv