平台stm32l072
基于ST官网的例程修改 AN4657
1、示例代码中的Ymodem协议 win7的超级终端支持,手册里提到的Tera Term 新版本的Ymodem不支持
2、示例代码中Ymodem接收部分的RxTimeout给的是1S,UR设置过小波特率,会有接收数据不完整的问题,可改为2S。
3、flash的参数地址修改
/* Define the address from where user application will be loaded.
Note: this area is reserved for the IAP code */
#define FLASH_PAGE_STEP FLASH_PAGE_SIZE /* Size of page : 2 Kbytes */
#define APPLICATION_ADDRESS (uint32_t)0x08008000 /* Start user code address: ADDR_FLASH_PAGE_8 */
/* Notable Flash addresses */
#define FLASH_START_BANK1 FLASH_BASE
#define WORDS_IN_HALF_PAGE ((uint32_t)16)
#define FLASH_HALF_PAGE_SIZE ((uint32_t)WORDS_IN_HALF_PAGE*4)
#define FLASH_LAST_SECTOR_BANK1 ((uint32_t)0x08017000)
#define FLASH_LAST_PAGE_BANK1 ((uint32_t)0x08017F80)
#define FLASH_END_BANK1 FLASH_BANK1_END
#define FLASH_START_BANK2 FLASH_BANK2_BASE
#define USER_FLASH_END_ADDRESS ((uint32_t)0x08030000)
#define FLASH_BANK1_MASK ((uint32_t)0xF0FFFFFF)
/* Define the user application size */
#define USER_FLASH_SIZE ((uint32_t)0x000030000) /* Small default template application */
4、flash写入建议使用HAL_FLASH_Program() ,示例代码中的HAL_FLASHEx_HalfPageProgram()在写入时,会有FLASH_FLAG_FWWERR的错误。原因未知。代码修改如下:
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, destination, *p_actual) == HAL_OK)
{
/* Check if flash content matches memBuffer */
if ((*(uint32_t*)(destination)) != *p_actual)
{
/* flash content doesn't match memBuffer */
status = FLASHIF_WRITINGCTRL_ERROR;
break;
}
/* Increment the memory pointers */
destination += 4;
p_actual += 1;
}
else
{
status = FLASHIF_WRITING_ERROR;
}
5、示例代码中Ymodem上传时会用到APP文件大小,文件大小记录在eeprom为好。
6、Int2Str (astring, length); 注意astring使用前置0.