本帖最后由 简单happy 于 2022-2-28 23:05 编辑
使用以前stm32f103 的宏定义公式操作行不通
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
我又移植库例程里的相关内容,也不成功
/* bit band for sram */
#define RAM_BASE 0x20000000
#define RAM_BITBAND_BASE 0x22000000
#define VARIABLES_RESET_BIT(variables_addr, bit_number) \
(*(uint32_t *)(RAM_BITBAND_BASE + ((variables_addr - RAM_BASE) * 32) + ((bit_number) * 4)) = 0)
#define VARIABLES_SET_BIT(variables_addr, bit_number) \
(*(uint32_t *)(RAM_BITBAND_BASE + ((variables_addr - RAM_BASE) * 32) + ((bit_number) * 4)) = 1)
#define VARIABLES_GET_BIT(variables_addr, bit_number) \
(*(uint32_t *)(RAM_BITBAND_BASE + ((variables_addr - RAM_BASE) * 32) + ((bit_number) * 4)))
/* bit band for peripheral */
#define PERIPHERAL_BASE 0x40000000
#define PERIPHERAL_BITBAND_BASE 0x42000000
#define PERIPHERAL_RESET_BIT(peripheral_addr, bit_number) \
(*(uint32_t *)(PERIPHERAL_BITBAND_BASE + ((peripheral_addr - PERIPHERAL_BASE) * 32) + ((bit_number) * 4)) = 0)
#define PERIPHERAL_SET_BIT(peripheral_addr, bit_number) \
(*(uint32_t *)(PERIPHERAL_BITBAND_BASE + ((peripheral_addr - PERIPHERAL_BASE) * 32) + ((bit_number) * 4)) = 1)
使用库例程,编译下载,是成功的。我看地址起始都是一样的.弄了一晚上也没有找出问题在哪.这个功能我一直是弄得云里雾里的,打算放弃这方法。 |