Skip to content

Commit

Permalink
Merge pull request #813 from spark/feature/electron/bl-dfu-err-propag…
Browse files Browse the repository at this point in the history
…ation

Feature/electron/bl dfu err propagation
  • Loading branch information
m-mcgowan committed Jan 15, 2016
2 parents 8180006 + e548e56 commit 35e8aef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 15 additions & 2 deletions platform/MCU/STM32F2xx/STM32_USB_Device_Driver/src/usbd_dfu_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "usbd_desc.h"
#include "usbd_req.h"
#include "usb_bsp.h"
#include "usbd_dfu_mal.h"


/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
Expand Down Expand Up @@ -567,7 +568,13 @@ static uint8_t EP0_TxSent (void *pdev)
Pointer += MAL_Buffer[2] << 8;
Pointer += MAL_Buffer[3] << 16;
Pointer += MAL_Buffer[4] << 24;
MAL_Erase(usbd_dfu_AltSet, Pointer);
uint16_t status = MAL_Erase(usbd_dfu_AltSet, Pointer);
if (status != MAL_OK) {
/* Call the error management function (command will be nacked) */
req.bmRequest = 0;
req.wLength = 1;
USBD_CtlError (pdev, &req);
}
}
else
{
Expand All @@ -587,7 +594,13 @@ static uint8_t EP0_TxSent (void *pdev)
Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer;

/* Preform the write operation */
MAL_Write(usbd_dfu_AltSet, Addr, wlength);
uint16_t status = MAL_Write(usbd_dfu_AltSet, Addr, wlength);
if (status != MAL_OK) {
/* Call the error management function (command will be nacked) */
req.bmRequest = 0;
req.wLength = 1;
USBD_CtlError (pdev, &req);
}
}
/* Reset the global lenght and block number */
wlength = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ uint16_t FLASH_If_Erase(uint32_t Add)

/* Check which sector has to be erased */
uint16_t FLASH_Sector = FLASH_SectorToErase(FLASH_INTERNAL, Add);
FLASH_EraseSector(FLASH_Sector, VoltageRange_3);
FLASH_Status status = FLASH_EraseSector(FLASH_Sector, VoltageRange_3);

#elif defined(STM32F10X_CL)
/* Call the standard Flash erase function */
Expand All @@ -113,6 +113,8 @@ uint16_t FLASH_If_Erase(uint32_t Add)
/* Lock the internal flash */
FLASH_Lock();

if (status != FLASH_COMPLETE) return MAL_FAIL;

return MAL_OK;
}

Expand Down Expand Up @@ -141,15 +143,18 @@ uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len)
FLASH_ClearFlags();

/* Data received are Word multiple */
for (idx = 0; idx < Len; idx = idx + 4)
FLASH_Status status = FLASH_COMPLETE;
for (idx = 0; idx < Len && status == FLASH_COMPLETE; idx = idx + 4)
{
FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx));
status = FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx));
Add += 4;
}

/* Lock the internal flash */
FLASH_Lock();

if (status != FLASH_COMPLETE) return MAL_FAIL;

return MAL_OK;
}

Expand Down

0 comments on commit 35e8aef

Please sign in to comment.