OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3169|回复: 2

请教一个stm32f0的指针使用问题

[复制链接]

48

主题

132

帖子

0

精华

初级会员

Rank: 2

积分
172
金钱
172
注册时间
2014-12-26
在线时间
120 小时
发表于 2020-12-13 10:42:19 | 显示全部楼层 |阅读模式
10金钱
最近在调试CLRC663程序时,把程序从stm32f1移植到stm32f0遇到一个问题:发生hard fault错误!这是很少遇见的错误呀!最后定位在一句代码:*ppRxBuffer = pDataParams->pRxBuffer;注释掉这句代码就不会产生hard fault。

这句代码在stm32f1上没问题,但在tm32f0上有问题。

相关定义:
#pragma pack(4)
uint8_t ** ppData = (uint8_t**)&pData[0];
#pragma pack()


ppData是ppRxBuffer的实参。

        #pragma pack(4)
        typedef struct
        {
                uint16_t wId;                                       /**< Layer ID for this component, NEVER MODIFY! */
                void  * pBalDataParams;                             /**< Pointer to the lower layers parameter structure. */
                uint8_t bLoadRegMode;                               /**< Whether LoadReg-Mode is enabled or not. */
                uint8_t * pLoadRegConfig;                           /**< Pointer to configuration buffer for LoadReg mode; Refer to \ref phhalHw_Rc663_Init. */
                uint8_t * pTxBuffer;                                /**< Pointer to global transmit buffer used by the Exchange() function. */
                uint16_t wTxBufSize;                                /**< Size of the global transmit buffer. */
                uint16_t wTxBufLen;                                 /**< Number of valid bytes within the transmit buffer. */
                uint8_t * pRxBuffer;                                /**< Pointer to global receive buffer used by the Exchange() function. */
                uint16_t wRxBufSize;                                /**< Size of the global receive buffer. */
                uint16_t wRxBufLen;                                 /**< Number of valid bytes within the receive buffer. */
                uint16_t wRxBufStartPos;                            /**< Starting position within the global receive buffer. */
                uint16_t wMaxPrecachedBytes;                        /**< Holds the max. number of bytes which are precached prior to command execution. */
                uint8_t bCardType;                                  /**< Type of card for which the hal is configured for. */
                uint16_t wCfgShadow[PHHAL_HW_RC663_SHADOW_COUNT];   /**< Configuration shadow; Stores configuration for current cardtype. */
                uint16_t wTimingMode;                               /**< Current timing measurement mode. */
                uint8_t bTimeoutUnit;                               /**< Unit of current timeout value (either #PHHAL_HW_TIME_MICROSECONDS or #PHHAL_HW_TIME_MILLISECONDS). */
                uint32_t dwTimingUs;                                /**< Current timing value. */
                uint16_t wFieldOffTime;                             /**< Field-Off-Time in milliseconds. */
                uint16_t wFieldRecoveryTime;                        /**< Field-Recovery-Time in milliseconds. */
                uint8_t bSymbolStart;                               /**< Preamble of a frame. */
                uint8_t bSymbolEnd;                                 /**< Trailer symbol of a frame. */
                uint8_t bFifoSize;                                  /**< Fifo-Size setting. */
                uint16_t wAdditionalInfo;                           /**< Storage for additional error information. */
                uint8_t bBalConnectionType;                         /**< Type of the underlying BAL connection. Refer to #PHHAL_HW_CONFIG_BAL_CONNECTION. */
                uint8_t bRfResetAfterTo;                            /**< Storage for #PHHAL_HW_CONFIG_RFRESET_ON_TIMEOUT setting. */
        } phhalHw_Rc663_DataParams_t;
        #pragma pack()


pRxBuffer是以上结构体的一个元素。

查了网上资料,有可能是非对称内存读取,就是stm32f0只能从偶数地址读取数据,不能从奇数地址读取数据,否则引发hard fault。可是已经设定字节对齐了啊。

请教各位大神,这是什么问题?怎么才能避免?


最佳答案

查看完整内容[请看2#楼]

u8指针就不存在对齐的问题, 在watch看看ppRxBuffer的值, 问题在它身上。有可能是ppRxBuffer的值是指向F1有的内存块而F0是没有的
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

3

主题

1907

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
4106
金钱
4106
注册时间
2018-8-14
在线时间
696 小时
发表于 2020-12-13 10:42:20 | 显示全部楼层
本帖最后由 edmund1234 于 2020-12-13 11:08 编辑

u8指针就不存在对齐的问题, 在watch看看ppRxBuffer的值, 问题在它身上。有可能是ppRxBuffer的值是指向F1有的内存块而F0是没有的
回复

使用道具 举报

48

主题

132

帖子

0

精华

初级会员

Rank: 2

积分
172
金钱
172
注册时间
2014-12-26
在线时间
120 小时
 楼主| 发表于 2020-12-14 09:19:11 | 显示全部楼层
本帖最后由 xiong2088 于 2020-12-14 09:22 编辑

感谢大神的回复,问题找到了。问题就出现在uint8_t ** ppData = (uint8_t**)&pData[0];
其实最初的初始化时这样的:uint8_t ** ppData = (uint8_t**)&pData;很多人认为是给数组的地址取地址。

这个初始化是错的,pData,  &pData和&pData[0]的地址是一样的。

这样指向指针的指针就被初始化成指向数组的指针了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-23 20:40

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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