GD32 flash无法正常擦写,wait中返回pgerr,EXMC的坑

exmc(fsmc)设置的不对可能会导致总线忙,无法操作flash 会在wait中返回pgerror(大概是这个),可以去看看exmc的初始化

typedef struct
{
    uint32_t norsram_region;                                            /*!< select the region of EXMC NOR/SRAM bank */
    uint32_t write_mode;                                                /*!< the write mode, synchronous mode or asynchronous mode */
    uint32_t extended_mode;                                             /*!< enable or disable the extended mode */
    uint32_t asyn_wait;                                                 /*!< enable or disable the asynchronous wait function */
    uint32_t nwait_signal;                                              /*!< enable or disable the NWAIT signal while in synchronous bust mode */
    uint32_t memory_write;                                              /*!< enable or disable the write operation */
    uint32_t nwait_config;                                              /*!< NWAIT signal configuration */
    uint32_t wrap_burst_mode;                                           /*!< enable or disable the wrap burst mode */
    uint32_t nwait_polarity;                                            /*!< specifies the polarity of NWAIT signal from memory */
    uint32_t burst_mode;                                                /*!< enable or disable the burst mode */
    uint32_t databus_width;                                             /*!< specifies the databus width of external memory */
    uint32_t memory_type;                                               /*!< specifies the type of external memory */
    uint32_t address_data_mux;                                          /*!< specifies whether the data bus and address bus are multiplexed */
    exmc_norsram_timing_parameter_struct* read_write_timing;            /*!< timing parameters for read and write if the extendedmode is not used or the timing 
                                                                             parameters for read if the extendedmode is used. */
    exmc_norsram_timing_parameter_struct* write_timing;                 /*!< timing parameters for write when the extendedmode is used. */
}exmc_norsram_parameter_struct;

这个是初始化结构体,注意最下面的两个,是以指针的形式设置,也就是说你建立一个变量exmc_norsram_parameter_struct时,只申请了两个exmc_norsram_timing_parameter_struct的指针,此时这两个指针指向的地方是未知的(或者0),如果没注意直接->赋值,指向都是未知的直接赋值肯定会出现问题,最坑的是在我这还没爆硬件错误,直到写flash操作部分的时候才发现怎么写都写不了(返回爆pgerr,应该是因为exmc设置错误导致读写顺序出问题),在代码中一点一点插入flash操作函数debug看内存最后才发现是这个问题,解决方法就是再申请两个exmc_norsram_timing_parameter_struct的变量,让这两个指针指向它们,再进行赋值(我赋值了反而又炸了,不赋值能跑我就没管它了)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值