Question
bit-banding GPIO->ODR not possible?
Posted on September 26, 2014 at 10:46
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 SRAMand RCC configuration without any problems. First of all, lets have a look atthe code snippet:
// prepare bit-banding
#define PERIPH_BB_BASE ((uint32_t)0x42000000) /*!<
Peripheral
base address in the bit-band region */
#define PERIPH_BASE ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */
#define BITBAND_PERIPH(address, bit) ((__IO uint32_t *)(PERIPH_BB_BASE + (((uint32_t)address) - PERIPH_BASE) * 32 + (bit) * 4))
typedef volatile uint32_t * const bitband_t;
// activate clk
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
// init two GPIOs
GPIOA->MODER |= GPIO_MODER_MODER0_0 + GPIO_MODER_MODER1_0;
GPIOA->OTYPER &= ~(GPIO_OTYPER_OT_0 + GPIO_OTYPER_OT_1);
GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR0_0 + GPIO_OSPEEDER_OSPEEDR1_0;
GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR0 + GPIO_PUPDR_PUPDR1);
// Set pin1
GPIOA->ODR |= GPIO_ODR_1;
// set pin 0 using bit-banding
bitband_t gpioa_pin0 = BITBAND_PERIPH(&GPIOA->ODR, 0);
*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 toline4):
The address of GPIOA->ODR is 0x48000
Minus the
PERIPH_BASE
remains 0x08000 Multiplied by 32 leads to an overflow 0x00000280 remains AddingPERIPH_BB_BASE
andbit*4
results in the final address is 0x42000 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 #gpio #stm32f303 #bit-banding