微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > 硬件电路设计讨论 > 问题:stm32m0 单片机按地址写长整数,地址必须是4的整数倍?

问题:stm32m0 单片机按地址写长整数,地址必须是4的整数倍?

时间:12-13 整理:3721RD 点击:
一段以前用的很多的程序,以前在别的工程用过很多了(stm32 M3系列, 51单片机)
今天拿到m0单片机的工程里一运行就hard fault
找来找去似乎是这么个问题: 用指针往一个地址里写长整数数据, 这个地址必须是4的整数倍?
类似这样:
    {
        int* a;
        int* b;
        a = (int*)(0x20000410);
        *a = 0;                        //okay
        b = (int*)(0x20000421);
        *b = 0;                        //hard fault
    }
我用的是mdk5, 感觉应该是cpu什么模式没设置对吧? 应该怎么解决这个问题?
thx

找到了,还真有这么个说法, 服了
Important
It is important to make sure the memory address accessed is aligned. For example, a word size access can only be carried out on address locations when address bits[1:0] are set to zero, and a half word size access can only be carried out on address locations when an address bit[0] is set to zero. The Cortex-M0 processor does not support unaligned transfers. Any attempt at unaligned memory access results in a hard fault exception. Byte-size transfers are always aligned on the Cortex-M0 processor.

ARM本身默认要求数据按自然边界对齐。

m3不需要

v7M只是部分LDR/STR指令支持非对齐访问,不是全部。

地址对齐
.55

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top