/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / How do I use bit banding to manipulate variables in SRAM?

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 Family
  •  » How do I use bit banding to manipulate variables in SRAM?

# 1   2009-02-12 11:29:34 How do I use bit banding to manipulate variables in SRAM?

sima
Member
Registered: 2008-12-10
Posts: 16

How do I use bit banding to manipulate variables in SRAM?

How do I effectively use bit banding to manipulate variables that I have declared in C?

Should I assign a fixed memory region to those variables which I want to bit band (and how do I do that)?

Offline

 

# 2   2009-02-12 11:46:44 How do I use bit banding to manipulate variables in SRAM?

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: How do I use bit banding to manipulate variables in SRAM?

We don't use it, but it should be very powerfull in many cases.
To use it in C, you have to cast your the address of the object into 'long integer', then to convert the resulting integer in bit address, then to cast it again into pointer. Finally you can use this pointer (*) to operate on the bit.
The reference  manual says:

RefMan :

The following example shows how to map bit 2 of the byte located at SRAM address
0x20000300 in the alias region:
0x22006008 = 0x22000000 + (0x300*32) + (2*4).
Writing to address 0x22006008 has the same effect as a read-modify-write operation on bit
2 of the byte at SRAM address 0x20000300.

I will suggest:

#define WRITEBIT(byte, ofs, val)   (*((unsigned char*) (0x22000000 + ( (((long) (&(byte) ))-0x20000000)*32) + ((ofs)*4))) = (val))

unsigned char c1;
WRITEBIT(c1,3,0); //would clear bit 3 of c1

I didn't test it but I hope it works (if I didn't miss a parenthesis).

Offline

 

# 3   2009-02-12 12:57:16 How do I use bit banding to manipulate variables in SRAM?

sima
Member
Registered: 2008-12-10
Posts: 16

Re: How do I use bit banding to manipulate variables in SRAM?

I tried something similar. But unfortunately at compile time the address of the variable is unknown (if we don’t place it at a fixed address).

So the define inserts a computation of the address. When I look at the list file the code looks long.

Offline

 

# 4   2009-02-12 13:49:48 How do I use bit banding to manipulate variables in SRAM?

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: How do I use bit banding to manipulate variables in SRAM?

It's a pity... Therefore, it will work only if you relocate the byte value at an absolute address.

Offline

 

# 5   2009-05-11 05:10:04 How do I use bit banding to manipulate variables in SRAM?

hivmoacchbhgj
New member
Registered: 2009-03-10
Posts: 7

Re: How do I use bit banding to manipulate variables in SRAM?

Francis :

It's a pity... Therefore, it will work only if you relocate the byte value at an absolute address.

I think it would work using pointers (I haven't tested it,) as far as I know you can do addition and substraction arithmetic on pointers.

Offline

 

  • Index
  •  » STM32 Family
  •  » How do I use bit banding to manipulate variables in SRAM?

Board footer