summaryrefslogtreecommitdiff
path: root/src/Components/Ble/DfuService.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-05-11 18:50:37 +0200
committerJF <jf@codingfield.com>2020-05-11 18:50:37 +0200
commitee05577dd62c64d0e6a2e497b75710c7a1351557 (patch)
tree36d36462bd1c3aaa06df46b0bf6086111c83df2b /src/Components/Ble/DfuService.cpp
parent0b8e6c3fa20457bce931b1d289f187e46fc68307 (diff)
Fix race conditions on SPI and integrate the SPI NOR Flash driver into DFUService (WIP)
Diffstat (limited to 'src/Components/Ble/DfuService.cpp')
-rw-r--r--src/Components/Ble/DfuService.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Components/Ble/DfuService.cpp b/src/Components/Ble/DfuService.cpp
index 22983a83..0c8d357c 100644
--- a/src/Components/Ble/DfuService.cpp
+++ b/src/Components/Ble/DfuService.cpp
@@ -15,9 +15,10 @@ int DfuServiceCallback(uint16_t conn_handle, uint16_t attr_handle,
return dfuService->OnServiceData(conn_handle, attr_handle, ctxt);
}
-DfuService::DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController) :
+DfuService::DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController, Pinetime::Drivers::SpiNorFlash& spiNorFlash) :
systemTask{systemTask},
bleController{bleController},
+ spiNorFlash{spiNorFlash},
characteristicDefinition{
{
.uuid = (ble_uuid_t *) &packetCharacteristicUuid,
@@ -104,6 +105,15 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) {
applicationSize = om->om_data[8] + (om->om_data[9] << 8) + (om->om_data[10] << 16) + (om->om_data[11] << 24);
NRF_LOG_INFO("[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", softdeviceSize, bootloaderSize, applicationSize);
+ for(int erased = 0; erased < applicationSize; erased += 0x1000) {
+ spiNorFlash.SectorErase(erased);
+
+ auto p = spiNorFlash.ProgramFailed();
+ auto e = spiNorFlash.EraseFailed();
+ NRF_LOG_INFO("[DFU] Erasing sector %d - %d-%d", erased, p, e);
+
+ }
+
uint8_t data[] {16, 1, 1};
SendNotification(connectionHandle, data, 3);
state = States::Init;
@@ -128,10 +138,15 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) {
case States::Data: {
nbPacketReceived++;
+
+ spiNorFlash.Write(bytesReceived, om->om_data, om->om_len);
+
bytesReceived += om->om_len;
bleController.FirmwareUpdateCurrentBytes(bytesReceived);
NRF_LOG_INFO("[DFU] -> Bytes received : %d in %d packets", bytesReceived, nbPacketReceived);
+
+
if((nbPacketReceived % nbPacketsToNotify) == 0) {
uint8_t data[5]{static_cast<uint8_t>(Opcodes::PacketReceiptNotification),
(uint8_t)(bytesReceived&0x000000FFu),(uint8_t)(bytesReceived>>8u), (uint8_t)(bytesReceived>>16u),(uint8_t)(bytesReceived>>24u) };