搜索
bottom↓
回复: 1

C++ 调用JlinkARM.dll编程读写STM32F103芯片,能读但不能写,跪求原因

[复制链接]

出0入0汤圆

发表于 2010-10-29 16:03:24 | 显示全部楼层 |阅读模式
想写个软件用JlinkARM的动态库直接刷写flash程序,但出现了以下问题:
使用JLINKARM_WriteMem和JLINKARM_WriteU32或者JLINKARM_WriteU16 或者JLINKARM_WriteU8这几个函数都不能往flash(芯片内自身flash)中写数据。
但是使用JLINKARM_ReadMemU8或者JLINKARM_ReadMemU32又可以读取flash中的内容。
觉得非常怪异!

           CString        m_sFileName;
        FILE *fbin;
        U8 data[1024*40];
        U32 readdata[1024*40];
        U8  readbyte[1024*40];
        U8 * pdata;
        U32 dataLenth;
        U32 flashAddress;
        U8 pStatus;
        //JLINKARM_Reset();
        //JLINKARM_Halt();
        JLINKARM_Open();
        //flashAddress = JLINKARM_GetId();
        //JLINKARM_Go();
        JLINKARM_Halt();


        CString sFilter="HEX文件(*.bin)|*.bin||";
        CFileDialog dlgFileLoad(TRUE,"bin","Project",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,sFilter,NULL);
        if(dlgFileLoad.DoModal()==IDOK)                //读取文件
        {
                m_sFileName=dlgFileLoad.GetPathName();
                UpdateData(FALSE);
        }
        UpdateData(FALSE);

        fbin = fopen(m_sFileName, "rb");
        if (0==fbin)
        {
                MessageBox("file open error!" , NULL , MB_OK);
                return ;
        }
        fseek(fbin,0,SEEK_END);                //文件指针到文件尾
    dataLenth = ftell(fbin);               //读取文件长度

    pdata = data;      
    //读取文件到分配的内存
    fseek(fbin,0,SEEK_SET);            //文件指针到文件头
    fread(pdata,1,dataLenth,fbin);        //读取文件到申请的内存中
        fclose(fbin);
        pdata = data;
       

        flashAddress = 0x08000000;
        U32 temp;
        U32 tempData;
       
        for(int i= 0 ;i< 8; i++)
        {
                JLINKARM_WriteMem(flashAddress,1,&data);
                JLINKARM_ReadMemU8(flashAddress,1,&readbyte,&pStatus);
                fbin ++;
                flashAddress ++;
        }

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2011-7-5 10:33:32 | 显示全部楼层
flash 写入是 Flash program and erase controller (FPEC) 控制的.
不能直接通过 JLINKARM_WriteMem(flashAddress,1,&data); 写入

1. Unlocking the Flash memory

2. The main Flash memory programming sequence in standard mode is as follows:
Check that no main Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register.
Set the PG bit in the FLASH_CR register.
Perform the data write (half-word) at the desired address.
Wait for the BSY bit to be reset.
Read the programmed value and verify.

写入之前可能需要先擦除

The Flash memory can be erased page by page or completely (Mass Erase).

Page Erase
A page of the Flash memory can be erased using the Page Erase feature of the FPEC. To
erase a page, the procedure below should be followed:
Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_CR register
Set the PER bit in the FLASH_CR register
Program the FLASH_AR register to select a page to erase
Set the STRT bit in the FLASH_CR register
Wait for the BSY bit to be reset
Read the erased page and verify

Mass Erase
The Mass Erase command can be used to completely erase the user pages of the Flash
memory. The information block is unaffected by this procedure. The following sequence is
recommended:
Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register
Set the MER bit in the FLASH_CR register
Set the STRT bit in the FLASH_CR register
Wait for the BSY bit to be reset
Read all the pages and verify

详情参考

PM0042
Programming manual
STM32F10xxx Flash programming
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-18 12:08

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表