写入SDRAM时出错

时间:2015-09-29 15:39:35

标签: microcontroller

我正在研究STM32F7xxx微控制器。我对整个微控制器编程都很陌生。我正在使用最新的STM32F7xxx库来构建我的代码。我正在将这个微控制器用于SLAM应用程序。由于它没有足够的内存,我想将机器人的姿势信息保存在SDRAM中。我使用以下网址提供的库:http://stm32f4-discovery.com/2015/07/hal-library-11-sdram-for-stm32fxxx/

将浮点值写入SDRAM的代码非常简单,只需一行:

    #define TM_SDRAM_WriteFloat(address, value)    (*(__IO float *) (SDRAM_START_ADR + (address)) = (value))

我使用它的代码如下:

    void write_Landmark()
    {
    int address = uwIndex_lm;
    SDRAM_Write8(LANDMARK_START_ADR+address,lm_head->landmark_index);
    address = address +1;
    SDRAM_WriteFloat(LANDMARK_START_ADR+address,lm_head->pos_x);
    address = address +4;
    SDRAM_WriteFloat(LANDMARK_START_ADR+address,lm_head->pos_y);
    address = address +4;
    SDRAM_WriteFloat(LANDMARK_START_ADR+address,lm_head->pos_theta);
    address = address +4;
    SDRAM_Write16(LANDMARK_START_ADR+address,lm_head->jump_point);
    address = address +2;
    SDRAM_Write8(LANDMARK_START_ADR+address,lm_head->landmark_detected);
    address = address +1;
    SDRAM_Write8(LANDMARK_START_ADR+address,lm_head->landmark_corrected);
    address = address +1;
    SDRAM_WriteFloat(LANDMARK_START_ADR+address,lm_head->hall_angle);
    address = address +4;
    SDRAM_WriteFloat(LANDMARK_START_ADR+address,lm_head->hall_distance);
    address = address +4;
    SDRAM_Write8(LANDMARK_START_ADR+address,lm_head->on_curve);
    address = address +1;
    uwIndex_lm = address;
   }

代码执行卡在我写入float到SDRAM的行。但如果不是

    SDRAM_WriteFloat(LANDMARK_START_ADR+address,lm_head->pos_x);

我写,

    SDRAM_Write32(LANDMARK_START_ADR+address,lm_head->pos_x);

它工作正常。我知道我在这里遇到了一个严重的错误,但我真的没有办法解决这个问题。任何建议都会非常有用。感谢

1 个答案:

答案 0 :(得分:0)

我刚刚意识到对齐是罪魁祸首。所以我为所有要写入Sdram的变量分配了4个空格,它运行正常