2021-08-11 07:26 PM
I programmed User DFU Boot loader like this,
uint16_t MEM_If_Init_FS(void)
{
/* USER CODE BEGIN 0 */
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR);
return (USBD_OK);
/* USER CODE END 0 */
}
/**
* @brief De-Initializes Memory
* @retval USBD_OK if operation is successful, MAL_FAIL else
*/
uint16_t MEM_If_DeInit_FS(void)
{
/* USER CODE BEGIN 1 */
HAL_FLASH_Lock();
return (USBD_OK);
/* USER CODE END 1 */
}
/**
* @brief Erase sector.
* @param Add: Address of sector to be erased.
* @retval 0 if operation is successful, MAL_FAIL else.
*/
uint16_t MEM_If_Erase_FS(uint32_t Add)
{
/* USER CODE BEGIN 2 */
FLASH_EraseInitTypeDef pEraseInit;
uint32_t SectorError;
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
pEraseInit.NbPages = 1;
pEraseInit.Page = Add;
//pEraseInit.Banks = FLASH_BANK_1;
if(HAL_FLASHEx_Erase(&pEraseInit, &SectorError) != HAL_OK)
{
return (USBD_FAIL);
}
return (USBD_OK);
/* USER CODE END 2 */
}
/**
* @brief Memory write routine.
* @param src: Pointer to the source buffer. Address to be written to.
* @param dest: Pointer to the destination buffer.
* @param Len: Number of data to be written (in bytes).
* @retval USBD_OK if operation is successful, MAL_FAIL else.
*/
uint16_t MEM_If_Write_FS(uint8_t *src, uint8_t *dest, uint32_t Len)
{
/* USER CODE BEGIN 3 */
uint32_t i = 0;
for(i = 0; i<Len; i+=4)
{
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, (uint32_t)(dest + i),*(uint32_t *)(src + i)) == HAL_OK)
{
if(*(uint32_t *)(src + i) != *(uint32_t *)(dest + i))
{
return 2;
}
}
else
{
return 1;
}
}
return (USBD_OK);
/* USER CODE END 3 */
}
/**
* @brief Memory read routine.
* @param src: Pointer to the source buffer. Address to be written to.
* @param dest: Pointer to the destination buffer.
* @param Len: Number of data to be read (in bytes).
* @retval Pointer to the physical address where data should be read.
*/
uint8_t *MEM_If_Read_FS(uint8_t *src, uint8_t *dest, uint32_t Len)
{
/* Return a valid address to avoid HardFault */
/* USER CODE BEGIN 4 */
uint32_t i = 0;
uint8_t *psrc = src;
for(i = 0; i < Len; i++)
{
dest[i] = *psrc++;
}
return (uint8_t *)(dest);
/* USER CODE END 4 */
}
i tried to device memory read in cubeprogrammer, it worked.
i checked this in iar workbench that function MEM_If_Read_FS called
but, when i tried fw download using cubeprogrammer, only the progress bar moved from side to side, the cubeprogrammer did nothing. also, MEM_If_Erase_FS, MEM_If_Write_FS not called.
-> it's stuck in this state.
I want to debug, but I don't know where to look because two functions don't worked.
Why did this problem happen??
---------------------------------------------------------------------------------------------------------------------------------------
[dfu code]
USBD_DFU_APP_DEFAULT_ADD = 0x0800C000
#define FLASH_DESC_STR "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg,04*016Kg,01*064Kg,07*128Kg"
for download, i used this hex file.
2021-09-27 06:06 PM
Interrupt priority was set higher usb than systick. So, the tick did not increase, and remained in the hal_delay function. I was thinking that the function was not called. I hope no one makes the same mistake as me!