<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>--bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/28872/--bitband-compiler-switch-fails-very-strange</link><description> 
Look at this (Controller: STM32F407I, uVision 4.23, Armcc
4.1.0.894): 

 
struct __attribute__((bitband)){
 unsigned int Bit1:1;
 unsigned int Bit2:1;
}Bits __attribute__((at(0x20000100)));

int main( void){

 Bits.Bit1= 1;

 while(1);
}
 

 
 
This</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: --bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/thread/131024?ContentTypeID=1</link><pubDate>Thu, 16 Aug 2012 23:29:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bcda0738-1953-4476-babb-b1373abfa4ba</guid><dc:creator>nice day</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sorry, the first statement of my last post is wrong, it should
say:&lt;/p&gt;

&lt;p&gt;
In C++ for bitband variables defined inside a class, bitband will
ONLY work if the bitband struct is defined static (so with fixed
global address).&lt;/p&gt;

&lt;p&gt;
(It is NOT required that the class functions invoking this bitband
access are static - this is very convenient).&lt;/p&gt;

&lt;p&gt;
So for &amp;quot;one-time&amp;quot; classes this is a nice way to access to
bits.&lt;/p&gt;

&lt;p&gt;
For classes with multiple instances, you can proceed as I
described in my last post, using the PPBADR macro... .&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: --bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/thread/127577?ContentTypeID=1</link><pubDate>Thu, 16 Aug 2012 22:35:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ba0c12ad-9ba8-4788-808d-3cb5594ed262</guid><dc:creator>nice day</dc:creator><description>&lt;p&gt;&lt;p&gt;
In C++ for bitband variables defined inside a class, bitband will
ONLY work in static functions, not in class member functions
(presumably as in non-static class member functions there always the
&amp;quot;this&amp;quot; pointer is present).&lt;/p&gt;

&lt;p&gt;
So if you use C++ classes, which occur only once, it is an
advantage to use them completely static (all functions + variables
static).&lt;/p&gt;

&lt;p&gt;
If I want to use bitband in non-static C++ functions, I current
use the following workaround, requiring an additional pointer
variable to the bitband base variable:&lt;/p&gt;

&lt;pre&gt;
Required macros:
typedef int* PBB;

#define BITNR(x) (x&amp;amp;0x1?0:x&amp;amp;0x2?1:x&amp;amp;0x4?2:x&amp;amp;0x8?3: \ 
x&amp;amp;0x10?4:x&amp;amp;0x20?5:x&amp;amp;0x40?6:x&amp;amp;0x80?7: \ 
x&amp;amp;0x100?8:x&amp;amp;0x200?9:x&amp;amp;0x400?10:x&amp;amp;0x800?11: \ 
x&amp;amp;0x1000?12:x&amp;amp;0x2000?13:x&amp;amp;0x4000?14:x&amp;amp;0x8000?15: \ 
x&amp;amp;0x10000?16:x&amp;amp;0x20000?17:x&amp;amp;0x40000?18:x&amp;amp;0x80000?19: \ 
x&amp;amp;0x100000?20:x&amp;amp;0x200000?21:x&amp;amp;0x400000?22:x&amp;amp;0x800000?23: \ 
x&amp;amp;0x1000000?24:x&amp;amp;0x2000000?25:x&amp;amp;0x4000000?26:x&amp;amp;0x8000000?27: \ 
x&amp;amp;0x10000000?28:x&amp;amp;0x20000000?29:x&amp;amp;0x40000000?30:x&amp;amp;0x80000000?31:32)

#define PBBADR0(Var)       \ 
((PBB) ( ( ((uint32_t)&amp;amp;(Var)) &amp;amp; BB_SRAMMASK) | BB_OFFSET | (( ((uint32_t)&amp;amp;(Var)) &amp;amp; (BB_OFFSET-1)) &amp;lt;&amp;lt; 5) ) )

#define PBBADR(pbb, BitMask)       \ 
          ((PBB) ( (BYTE*)pbb + (BITNR(BitMask) &amp;lt;&amp;lt; 2) ) )

#define MASK_Bit1  0x1
#define MASK_Bit2  0x2
#define MASK_Bit3  0x4
#define MASK_Bit4  0x8
#define MASK_Bit5  0x10
#define MASK_Bit6  0x20
...
int iBits;
PBB pbbBits;

... during class initialisation ...:
pbbBits= PBBADR0(iBits);

... and to work with the bits:
if( *PBBADR(pbbBits, MASK_Bit1)){
  *PBBADR(pbbBits, MASK_Bit2)= 0;
  *PBBADR(pbbBits, MASK_Bit3)= 1;
}

&lt;/pre&gt;

&lt;p&gt;
This creates very efficient code, just it has the drawback that
you need this pointer variable, and you should check this pointer
variable from time to time in your software, as of course terrible
things would happen, if this pointer changes.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: --bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/thread/116878?ContentTypeID=1</link><pubDate>Mon, 25 Jun 2012 00:47:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cd287e5b-acea-4323-8e71-26fda2cc9082</guid><dc:creator>Edmund Player</dc:creator><description>&lt;p&gt;&lt;p&gt;
I am not aware of any other current issues with armcc and
bitbanding.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: --bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/thread/106094?ContentTypeID=1</link><pubDate>Fri, 22 Jun 2012 04:44:02 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:76ea1c3b-ea8a-4601-bd91-e1828ade2f40</guid><dc:creator>nice day</dc:creator><description>&lt;p&gt;&lt;p&gt;
Can you give some information about some typical situations, where
the --bitband access would fail?&lt;/p&gt;

&lt;p&gt;
I use --bitband in my project now (which is quite large, and
meanwhile also C++), and it seems to work nicely (Processor
STM32F407).&lt;/p&gt;

&lt;p&gt;
I would be happy, if you could tell me which typical situations I
should avoid when using --bitband.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: --bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/thread/80318?ContentTypeID=1</link><pubDate>Fri, 22 Jun 2012 03:13:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:26f46ce0-411a-4dde-927c-f074d46f2376</guid><dc:creator>Edmund Player</dc:creator><description>&lt;p&gt;&lt;p&gt;
There is currently an issue where any use of the embedded
assembler and bitbanded accesses in the same translation unit will
cause incorrect output to be generated. This should hopefully be
fixed in a future release of the MDK ARM Compiler.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: --bitband compiler switch fails (very strange!!!)</title><link>https://community.arm.com/thread/60810?ContentTypeID=1</link><pubDate>Tue, 12 Jun 2012 15:36:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3ef79069-0895-4c4e-8360-53abff004634</guid><dc:creator>nice day</dc:creator><description>&lt;p&gt;&lt;p&gt;
... finally I use my own core_cm4.h - I commented out the line
&amp;quot;#include &amp;lt;core_cmInstr.h&amp;gt;&amp;quot;, further then I had to comment out
the inline function NVIC_SystemReset in core_cm4.h (as this used the
macro/function __DSB() which is defined in core_cmInstr.h).&lt;/p&gt;

&lt;p&gt;
After this, my large software works now nicely - it had a very
strange and very seldom bit access problem before ... I am really
reliefed now.&lt;/p&gt;

&lt;p&gt;
... just if anyway anybody has some reasonable explanation for
this strange coupling between function definition and bitband
operation, I would possibly be a bit more reliefed (as it is not a
nice feeling that the compiler seems to have some strange
behaviour).&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>