Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22006

Why assigning will be error with Address offset on stm32f7?

$
0
0

The problem I encountered was very weird.First I'm sorry for my English and thank you for your patience! I want to make PB0 and PB1 generate low level to light LED.

First my code is this:

RCC->AHB1ENR|=1<<1;  //enble GPIOB clock

GPIOB->MODER&=~(3<<(0*2));   //configure PB0 and PB1 General purpose Output mode
GPIOB->MODER|=1<<(0*2); 
GPIOB->MODER&=~(3<<(1*2));  
GPIOB->MODER|=1<<(1*2); 



GPIOB->OSPEEDR&=~(3<<(0*2));    //very high speed
GPIOB->OSPEEDR|=(3<<(0*2));
GPIOB->OSPEEDR&=~(3<<(1*2));    
GPIOB->OSPEEDR|=(3<<(1*2));



GPIOB->PUPDR&=~(3<<(0*2));  //pull-up
GPIOB->PUPDR|=1<<(0*2); 
GPIOB->PUPDR&=~(3<<(1*2));  
GPIOB->PUPDR|=1<<(1*2);

*(unsigned int*)(0x40020400+0x14) &= ~(1<<0); //PB0 and PB1 is low to light up the LED
*(unsigned int*)(0x40020400+0x14) &= ~(1<<1);

the result is that led is on.

than I modified a bit:

ps:GPIOB baseaddr:0x40020400 
MODER offset addr :0x00 
OSPEEDR offset addr:0x08 
OTYPER offset addr:0x04 
ODR offset addr:0x14

RCC->AHB1ENR|=1<<1;  

*(unsigned int*)(0x40020400+0x00)&=~(3<<(0*2)); 
*(unsigned int*)(0x40020400+0x00)|=1<<(0*2);     
*(unsigned int*)(0x40020400+0x00)&=~(3<<(1*2)); 
*(unsigned int*)(0x40020400+0x00)|=1<<(1*2);     



*(unsigned int*)(0x40020400+0x08)&=~(3<<(0*2)); 
*(unsigned int*)(0x40020400+0x08)|=(3<<(0*2));
*(unsigned int*)(0x40020400+0x08)&=~(3<<(1*2)); 
*(unsigned int*)(0x40020400+0x08)|=(3<<(1*2));


*(unsigned int*)(0x40020400+0x04)&=~(1<<0) ;        
*(unsigned int*)(0x40020400+0x04)|=0<<0;        
*(unsigned int*)(0x40020400+0x04)&=~(1<<1) ;        
*(unsigned int*)(0x40020400+0x04)|=0<<1;    

*(unsigned int*)(0x40020400+0x14) &= ~(1<<0);
*(unsigned int*)(0x40020400+0x14) &= ~(1<<1);   

the LED is off.The two codes are exactly the same.I am confused.so I use JLINK to view registers:

(MODER)   0x40020400: 00000280
(OSPEEDR) 0x40020408: 00000000
(OTYPER)  0x40020404: 00000000
(ODR)     0x40020414: 00000280

then I try following code:

RCC->AHB1ENR|=1<<1;  

*(unsigned int*)(0x40020400+0x00)&=~(3<<(0*2)); 
*(unsigned int*)(0x40020400+0x00)|=1<<(0*2);     
*(unsigned int*)(0x40020400+0x00)&=~(3<<(1*2)); 
*(unsigned int*)(0x40020400+0x00)|=1<<(1*2);     



*(unsigned int*)(0x40020400+0x08)&=~(3<<(0*2)); 
*(unsigned int*)(0x40020400+0x08)|=(3<<(0*2));
*(unsigned int*)(0x40020400+0x08)&=~(3<<(1*2)); 
*(unsigned int*)(0x40020400+0x08)|=(3<<(1*2));


GPIOB->PUPDR&=~(3<<(0*2));  //pull-up
GPIOB->PUPDR|=1<<(0*2); 
GPIOB->PUPDR&=~(3<<(1*2));  
GPIOB->PUPDR|=1<<(1*2);

*(unsigned int*)(0x40020400+0x14) &= ~(1<<0);
*(unsigned int*)(0x40020400+0x14) &= ~(1<<1);   

the LED is on!!

the registers:

    (MODER)   0x40020400: 00000285
    (OSPEEDR) 0x40020408: 000000CF
    (OTYPER)  0x40020404: 00000000
    (ODR)     0x40020414: 00000000

I think the function of the three codes is the same,but the registers is different. my compiler:arm-none-eabi-gcc (from arm.com )

who can tell me why?


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>