STM32F10x_StdPeriph_Examples/CortexM3/BitBand/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    CortexM3/BitBand/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup CortexM3_BitBand
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 #define RAM_BASE       0x20000000
00035 #define RAM_BB_BASE    0x22000000
00036  
00037 /* Private macro -------------------------------------------------------------*/
00038 #define  Var_ResetBit_BB(VarAddr, BitNumber)    \
00039           (*(__IO uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 0)
00040    
00041 #define Var_SetBit_BB(VarAddr, BitNumber)       \
00042           (*(__IO uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 1)
00043 
00044 #define Var_GetBit_BB(VarAddr, BitNumber)       \
00045           (*(__IO uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)))
00046    
00047 /* Private variables ---------------------------------------------------------*/
00048 
00049 __IO uint32_t Var, VarAddr = 0, VarBitValue = 0;
00050 
00051 /* Private function prototypes -----------------------------------------------*/
00052 /* Private functions ---------------------------------------------------------*/
00053 
00054 /**
00055   * @brief   Main program.
00056   * @param  None
00057   * @retval None
00058   */
00059 int main(void)
00060 {
00061   /*!< At this stage the microcontroller clock setting is already configured, 
00062        this is done through SystemInit() function which is called from startup
00063        file (startup_stm32f10x_xx.s) before to branch to application main.
00064        To reconfigure the default setting of SystemInit() function, refer to
00065        system_stm32f10x.c file
00066      */     
00067          
00068   Var = 0x00005AA5;
00069 
00070 /* A mapping formula shows how to reference each word in the alias region to a 
00071    corresponding bit in the bit-band region. The mapping formula is:
00072    bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number + 4)
00073 
00074 where:
00075    - bit_word_addr: is the address of the word in the alias memory region that 
00076                     maps to the targeted bit.
00077    - bit_band_base is the starting address of the alias region
00078    - byte_offset is the number of the byte in the bit-band region that contains 
00079      the targeted bit
00080    - bit_number is the bit position (0-7) of the targeted bit */
00081 
00082 /* Get the variable address --------------------------------------------------*/ 
00083   VarAddr = (uint32_t)&Var; 
00084 
00085 /* Modify variable bit using bit-band access ---------------------------------*/
00086   /* Modify Var variable bit 0 -----------------------------------------------*/
00087   Var_ResetBit_BB(VarAddr, 0);  /* Var = 0x00005AA4 */
00088   Var_SetBit_BB(VarAddr, 0);    /* Var = 0x00005AA5 */
00089   
00090   /* Modify Var variable bit 11 ----------------------------------------------*/
00091   Var_ResetBit_BB(VarAddr, 11);             /* Var = 0x000052A5 */
00092   /* Get Var variable bit 11 value */
00093   VarBitValue = Var_GetBit_BB(VarAddr, 11); /* VarBitValue = 0x00000000 */
00094   
00095   Var_SetBit_BB(VarAddr, 11);               /* Var = 0x00005AA5 */
00096   /* Get Var variable bit 11 value */
00097   VarBitValue = Var_GetBit_BB(VarAddr, 11);    /* VarBitValue = 0x00000001 */
00098   
00099   /* Modify Var variable bit 31 ----------------------------------------------*/
00100   Var_SetBit_BB(VarAddr, 31);               /* Var = 0x80005AA5 */
00101   /* Get Var variable bit 31 value */
00102   VarBitValue = Var_GetBit_BB(VarAddr, 31); /* VarBitValue = 0x00000001 */
00103     
00104   Var_ResetBit_BB(VarAddr, 31);             /* Var = 0x00005AA5 */
00105   /* Get Var variable bit 31 value */
00106   VarBitValue = Var_GetBit_BB(VarAddr, 31); /* VarBitValue = 0x00000000 */
00107         
00108   while (1)
00109   {
00110   }
00111 }
00112 
00113 #ifdef  USE_FULL_ASSERT
00114 /**
00115   * @brief  Reports the name of the source file and the source line number
00116   *         where the assert_param error has occurred.
00117   * @param  file: pointer to the source file name
00118   * @param  line: assert_param error line source number
00119   * @retval None
00120   */
00121 void assert_failed(uint8_t* file, uint32_t line)
00122 { 
00123   /* User can add his own implementation to report the file name and line number,
00124      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00125 
00126   /* Infinite loop */
00127   while (1)
00128   {
00129   }
00130 }
00131 #endif
00132 
00133 /**
00134   * @}
00135   */ 
00136 
00137 /**
00138   * @}
00139   */ 
00140 
00141 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32