AnsweredAssumed Answered

bit-banding GPIO->ODR not possible?

Question asked by gregor on Sep 26, 2014
Latest reply on Sep 26, 2014 by Clive One
Hello everyone,

since I'm toggling quite often some outputs, I try to access them via bit-banding. Unfortunately I can not access the GPIOs. I tested bit-banding for SRAM and RCC configuration without any problems. 
First of all, lets have a look at the code snippet:

01.// prepare bit-banding
02.#define PERIPH_BB_BASE        ((uint32_t)0x42000000) /*!< Peripheral base address in the bit-band region */
03.#define PERIPH_BASE           ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */

04.#define BITBAND_PERIPH(address, bit)         ((__IO uint32_t *)(PERIPH_BB_BASE + (((uint32_t)address) - PERIPH_BASE) * 32 + (bit) * 4))
05.typedef volatile uint32_t * const bitband_t;
06.  
07.// activate clk
08.  RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
09.  
10.// init two GPIOs
11.  GPIOA->MODER          |= GPIO_MODER_MODER0_0 + GPIO_MODER_MODER1_0;
12.  GPIOA->OTYPER         &= ~(GPIO_OTYPER_OT_0 + GPIO_OTYPER_OT_1);
13.  GPIOA->OSPEEDR        |= GPIO_OSPEEDER_OSPEEDR0_0 + GPIO_OSPEEDER_OSPEEDR1_0;
14.  GPIOA->PUPDR          &= ~(GPIO_PUPDR_PUPDR0 + GPIO_PUPDR_PUPDR1);
15.  
16.// Set pin1
17.  GPIOA->ODR           |= GPIO_ODR_1;
18.// set pin 0 using bit-banding
19.  bitband_t gpioa_pin0 = BITBAND_PERIPH(&GPIOA->ODR, 0);
20.  *gpioa_pin0 = 1;

That's not the whole code, but the interesting steps. Line 2 and 3 are from stm32f30x.h
Setting pin1 is no big deal, but setting pin0 doesn't.

When building the alias address for the GPIOA->ODR register I realise an overflow. here my calculation for the final address (according to line4):

The address of  GPIOA->ODR is 0x48000014.
Minus the PERIPH_BASE remains 0x08000014.
Multiplied by 32 leads to an overflow 0x00000280 remains
Adding  PERIPH_BB_BASE and bit*4 results in the final address is 0x42000284.

I've no idea which bit I'm manipulating, but that's not part of GPIOA.
Is there any mistake? does anyone know how to access the GPIO?

I'm working on a stm32f303cbt, using IAR Workbench.

Thanks for your help!
Gregor

Outcomes