当前位置: 代码迷 >> 单片机 >> stm32 中地址的懂得
  详细解决方案

stm32 中地址的懂得

热度:613   发布时间:2016-04-28 14:44:52.0
stm32 中地址的理解
小弟最近对stm32的地址分配理解不了,很是疑惑,请大神指点~~~(我尽量把问题描述清楚哈)
如下为什么STM32官方库文件中摘取的一部分
问题1:STM32的中地址是按Bit,Byte,还是Word作为单位的?    例如0x8000000,它后面的单位是什么?
问题2:为什么有的地址是按照uint16_t,有的是按照uint32_t,这个是为什么?
问题3:如GPIOC和DMA1_Channel1,它们其实都是一个指针,按我的理解,在32位系统下,所有的指针都是占用4个Byte,那干嘛还需要区分 ((GPIO_TypeDef *) 类型指针和 ((DMA_Channel_TypeDef *)指针?
#define GPIO_Pin_0                 ((uint16_t)0x0001)  /*!< Pin 0 selected */
#define GPIO_Pin_1                 ((uint16_t)0x0002)  /*!< Pin 1 selected */
#define GPIO_Pin_2                 ((uint16_t)0x0004)  /*!< Pin 2 selected */

#define FLASH_BASE             ((uint32_t)0x08000000) /*!< FLASH base address in the alias region */
#define SRAM_BASE              ((uint32_t)0x20000000) /*!< SRAM base address in the alias region */
#define PERIPH_BASE           ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */

#define GPIOC                      ((GPIO_TypeDef *) GPIOC_BASE)
#define DMA1_Channel1       ((DMA_Channel_TypeDef *) DMA1_Channel1_BASE)
------解决思路----------------------
引用:
小弟最近对stm32的地址分配理解不了,很是疑惑,请大神指点~~~(我尽量把问题描述清楚哈)
如下为什么STM32官方库文件中摘取的一部分
问题1:STM32的中地址是按Bit,Byte,还是Word作为单位的?    例如0x8000000,它后面的单位是什么?
问题2:为什么有的地址是按照uint16_t,有的是按照uint32_t,这个是为什么?
问题3:如GPIOC和DMA1_Channel1,它们其实都是一个指针,按我的理解,在32位系统下,所有的指针都是占用4个Byte,那干嘛还需要区分 ((GPIO_TypeDef *) 类型指针和 ((DMA_Channel_TypeDef *)指针?
#define GPIO_Pin_0                 ((uint16_t)0x0001)  /*!< Pin 0 selected */
#define GPIO_Pin_1                 ((uint16_t)0x0002)  /*!< Pin 1 selected */
#define GPIO_Pin_2                 ((uint16_t)0x0004)  /*!< Pin 2 selected */

#define FLASH_BASE             ((uint32_t)0x08000000) /*!< FLASH base address in the alias region */
#define SRAM_BASE              ((uint32_t)0x20000000) /*!< SRAM base address in the alias region */
#define PERIPH_BASE           ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */

#define GPIOC                      ((GPIO_TypeDef *) GPIOC_BASE)
#define DMA1_Channel1       ((DMA_Channel_TypeDef *) DMA1_Channel1_BASE)



建议你好好研究下memory map这一章。
1.byte
2.uint16_t和uint32_t不是描述地址的,是描述变量的长度的。
3.问题和2类似。楼主要明白,指针的长度都是一样的,指针指向的变量长度才是有不一样的。

你有见过 void类型的指针没? void *p,那sizeof(p)又该是多少呢。

楼主,你的C语言感觉基础还不够牢固,这些问题和单片机没有关系,你得好好把书再看看。