cancel
Showing results for 
Search instead for 
Did you mean: 

Bit-band - via a linker.

AVI-crak
Senior
Posted on June 29, 2015 at 00:33

Can anyone come in handy ...

Code for linker GCC.

xxx_sram/flash.ld

MEMORY

{

    ROM  (rx) : ORIGIN = 0x08000000, LENGTH = __

    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = __

    BITRAM (rw) : ORIGIN = 0x22000000, LENGTH = 2048K // - LENGTH(RAM) * 128

}

----

/* SRAM base address in the bit-band region*/

   _sramflag = .;

   sflagadres =  ((_sramflag - ORIGIN(RAM)) << 5 );

    .flag  (NOLOAD):

    {

       . += sflagadres;

       . = ALIGN(4);

       _sflag = .;

       KEEP(*(.flag))

       . = ALIGN(128);

       _eflag = .;

    } > BITRAM

    _eramflag = ((_eflag - _sflag) >> 5);

/* SRAM base address in the bit-band region*/

   .bss (NOLOAD):

   {

      __bss_start__ = .;

        . += _eramflag;

      *(.bss*)

      *(COMMON)

      __bss_end__ = .;

   } > RAM

&sharpdefine _FLAG __attribute__ ((section(''.flag'')))

After that, any global flag automatically becomes atomic. In addition - reduced memory consumption. But the main thing - the simplicity of the ad.

volatile uint32_t tmp_name_flag _FLAG;

Translated from Russian by Google,????? ????????? ????? ??????????.

#bit-band #bitband
2 REPLIES 2
jpeacock
Associate III
Posted on June 29, 2015 at 14:17

I use the same linker mapping to define single bit variables with bitband but I use a slightly different format:

MEMORY 
{ 
FLASH0 (rx): ORIGIN = 0x08000000, LENGTH = 32K 
FLASH1 (w): ORIGIN = 0x08008000, LENGTH = 32K 
FLASH (rx): ORIGIN = 0x08010000, LENGTH = 960K 
CCM (w): ORIGIN = 0x10000000, LENGTH = 64K 
OTP (w): ORIGIN = 0x1FFF7800, LENGTH = 512 
OTPLOCK (w): ORIGIN = 0x1FFF7A00, LENGTH = 16 
SRAM1 (wx): ORIGIN = 0x20000000, LENGTH = 0x1AF00 
SRAM2 (w): ORIGIN = 0x2001C000, LENGTH = 16K 
SRAMBB (w): ORIGIN = 0x2235E000, LENGTH = 8K 
BKPSRAM (w): ORIGIN = 0x40024000, LENGTH = 0xF80 
BKPREG (w): ORIGIN = 0x40002850, LENGTH = 0x4c 
SNMPBB (w): ORIGIN = 0x4249F000, LENGTH = 4K 
BKPBB (w): ORIGIN = 0x42051380, LENGTH = 128 
}

I reserve a small area in SRAM and backup SRAM (this is for an 'F4) and define those regions for bitband access. That gives me single bit non-volatile flags in the battery backup area (SNMPBB), handy for status tracking across power fails. The linker will also warn if I exceed the region size or try toplace code ina bitband region. Jack Peacock
AVI-crak
Senior
Posted on June 29, 2015 at 15:13

Too complicated, it's easier not to think about the placement.