【发布时间】:2017-05-22 09:21:35
【问题描述】:
我正在尝试在 Windows 7 上使用 JTAG ST-Link/V2 写入 STM32L476 的闪存。无需上传软件,我只需将数据写入可读取和删除的非易失性位置.
作为一个硬件新手,只有在编写非嵌入式常规 C 时才高效,我担心我可能会损坏或不可撤销地修改闪存。另外,我不确定我能做什么或不能做什么。
我在阅读manual 时发现,在0x08000000 内存位置写入似乎是个好主意。使用C代码调用ST-Link_Utility:
const char CMD_ACCESS_ST_UTILITY[] = "cd C:/Program Files (x86)/STMicroelectronics/STM32 ST-LINK Utility/ST-LINK Utility&&ST-LINK_CLI.exe ";
bool STLINKWriteSystemCalls(void)
{
char cmd[200] = "";
strcpy(cmd, CMD_ACCESS_ST_UTILITY); // cmd to access utility
strcat(cmd, "-c"); // Then connect with ST-Link
if (system(cmd) != 0)
return false; // If failed exit
strcpy(cmd, CMD_ACCESS_ST_UTILITY);
strcat(cmd, "-r8 0x08000000 0x100"); // Read to check if there is data already
// I haven't managed yet how I'll compare the result of read
// To FFFF but that's not the main issue
if (system(cmd) != 0)
return false; // If failed exit
strcpy(cmd, CMD_ACCESS_ST_UTILITY);
strcat(cmd, "-w8 0x08000000 0x00"); // Write data into 0x080000000
if (system(cmd) != 0)
return false; // If failed exit
return true;
}
有没有更好的方法来解决在哪里写以及如何写(错误检查、使用的资源等)?
【问题讨论】:
-
你可以使用 openocd 并且应该能够在终端 (telnet) 上运行命令来刷机,对于 SWD,我专门使用 openocd,对于引导加载程序,另一个故事(编写我自己的工具)。
标签: c embedded stm32 flash-memory jtag