This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F28M35x关于M3核位绑定的操作



有个问题需要请教一下,关于M3核的位带别名区地址的问题。我如果对GPIO70这个管脚进行位操作,现在知道GPIOC的基址为0x40006000,GPIODATA的偏移地址为0x00,根据手册中的公式bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number × 4),bit_band_base为0x42000000,byte_offset为0x40006000,现在不知道bit_number的值应为多少?

  • GPIO70是PC6,bit_number是  0x00000040   ,请参考下面的程序,:

    void
    GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal)
    {
        // Check the arguments.
        ASSERT(GPIOBaseValid(ulPort));

        // Write the pins.
        HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))) = ucVal;
    }

    #define GPIO_PIN_0                0x00000001    // GPIO pin 0
    #define GPIO_PIN_1                0x00000002    // GPIO pin 1
    #define GPIO_PIN_2                0x00000004    // GPIO pin 2
    #define GPIO_PIN_3                0x00000008    // GPIO pin 3
    #define GPIO_PIN_4                0x00000010    // GPIO pin 4
    #define GPIO_PIN_5                0x00000020    // GPIO pin 5
    #define GPIO_PIN_6                0x00000040    // GPIO pin 6
    #define GPIO_PIN_7                0x00000080    // GPIO pin 7

     

  • 谢谢Forrest,还有几个问题需要请教一下ucPins<<2代表什么意思呢?还有就是bit_number的范围不是0~7吗?那0x00000040是否代表bit_number=6呢?

  • <<2代表左移2位。

    GPIO本身就有bit-mask,不需要用bit-band,上面谈到的例程是bit-mask。(bit-mask的原理请参考Technical Reference Manual的GPIO章节的Data Register Operation。)

    如果一定要用bit-band。那么bit-mask的GPIODATA的通用地址的offset是0x003FC,GPIOC的地址是0x40006000,对应的bit-band是

    0x42000000+0x063FC*32+7*4=0x420C7F9C

  • Forrest,

    谢谢您的耐心指点,1、ucPins为什么要左移两位呢?2、关于GPIODATA的偏移地址手册中给出的是0x00(341页是这样描述的),0x3FC的偏移地址没有在手册中找到。3、如果使用bit-band的话操作速度是不是要快于bit-mask?4、bit-mask的原理还不是很理解,比如说如何实现修改GPIODATA的数值实现对gpio某个管脚的操作的。

  • 不客气,这一块稍微有点小搞。

    bit-mask速度快。

    关于第一个,第二个,第四个问题请看下面这幅图,请再看看文档中的Figure4-2上面的说明。3FC的ADDR[9:2]=11 1111 1100

  • 谢谢Forrest,我再看看。