FLASH 다운로드시 로그를 심플하게 정리해 본다.
프로젝트 파일
출력 로그를 정리 한다.
if (ymodemReceive(&ymodem) == true)
{
switch(ymodem.type)
{
case YMODEM_TYPE_START:
printf("\\n");
printf("FLASH Begin \\n");
printf(" %s %ld\\n", ymodem.file_name, ymodem.file_length);
{
FLASH_EraseInitTypeDef EraseInit;
uint32_t SectorError;
HAL_StatusTypeDef status;
uint8_t sector_cnt = 0;
sector_cnt = (ymodem.file_length / (128*1024)) + 1;
EraseInit.Sector = 1;
EraseInit.NbSectors = sector_cnt;
EraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_4;
EraseInit.Banks = FLASH_BANK_1;
HAL_FLASH_Unlock();
printf("FLASH Erase\\n");
printf(" Addr 0x%X\\n", 0x08020000);
printf(" Size %ldB\\n", ymodem.file_length);
printf(" Ret ");
status = HAL_FLASHEx_Erase(&EraseInit, &SectorError);
if (status == HAL_OK)
{
printf("OK\\n");
}
else
{
printf("Fail\\n");
}
HAL_FLASH_Lock();
}
break;
case YMODEM_TYPE_DATA:
{
HAL_StatusTypeDef status;
uint32_t flash_cnt;
uint32_t flash_addr;
if (ymodem.file_addr == 0)
{
printf("FLASH Write \\n");
}
printf(" %ld %% \\r", ymodem.file_received*100 / ymodem.file_length);
fflush(stdout);
if (ymodem.file_buf_length%32 == 0)
flash_cnt = ymodem.file_buf_length / 32;
else
flash_cnt = (ymodem.file_buf_length / 32) + 1;
HAL_FLASH_Unlock();
for (int i=0; i<flash_cnt; i++)
{
flash_addr = 0x08020000 + ymodem.file_addr + i*32;
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, flash_addr , (uint32_t)&ymodem.file_buf[i*32]);
if (status == HAL_OK)
{
}
}
HAL_FLASH_Lock();
}
break;
case YMODEM_TYPE_END:
printf("\\n");
printf("FLASH End \\n");
break;
case YMODEM_TYPE_CANCEL:
printf("YMODEM_TYPE_CANCEL \\n");
break;
case YMODEM_TYPE_ERROR:
printf("YMODEM_TYPE_ERROR \\n");
break;
default:
break;
}
ymodemAck(&ymodem);
}
실행 결과