cancel
Showing results for 
Search instead for 
Did you mean: 

Optimization of changing bit on port

jerry
Associate
Posted on May 11, 2014 at 00:35

Can the following code be made more efficient other than not having a function. Using a STMF405 and all I am trying to do is set bit 14 on Port C.

#define GPIOC                                0x40020800

#define GPIOC_BSRR_OFFSET   0x18

#define BIT14_ON                         0x00004000

#define GPIOC_BSRR_ADDRESS  GPIOC +  GPIOC_BSRR_OFFSET

unsigned int volatile * GPIOC_BSRR = (unsigned int *)GPIOC_BSRR_ADDRESS;

void rx_tx_on(void)

{

  *GPIOC_BSRR = BIT14_ON;

}
1 REPLY 1
Posted on May 11, 2014 at 04:23

It all depends on what the compiler does with it, adept use of registers in assembler would allow you the ultimate flexibility.

In C

GPIOC->BSRR = GPIO_Pin_14;

Would probably be as efficient, and you could tell the compiler to inline it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..