STM32 blinky through bit banding

Dependencies:   mbed

Fork of mbed_blinky by Mbed

Revision:
10:3a480c091e52
Parent:
4:81cea7a352b0
--- a/main.cpp	Thu Oct 29 12:28:39 2015 +0000
+++ b/main.cpp	Wed Jan 27 02:48:46 2016 +0000
@@ -1,12 +1,34 @@
 #include "mbed.h"
 
+//{/*** Bit Banding *******************************************************/
+/* base address for bit banding */
+#define BITBAND_SRAM_REF                    (0x20000000)
+/* base address for bit banding */
+#define BITBAND_SRAM_BASE                   (0x22000000)
+/* base address for bit banding */
+#define BITBAND_PERIPH_REF                  (0x40000000)
+/* base address for bit banding */
+#define BITBAND_PERIPH_BASE                 (0x42000000)
+
+/* sram bit band */
+#define BITBAND_SRAM(address, bit)   ((void*)(BITBAND_SRAM_BASE + (((uint32_t)address) - BITBAND_SRAM_REF) * 32 + (bit) * 4))
+
+/* periph bit band */
+#define BITBAND_PERIPH(address, bit) ((void*)(BITBAND_PERIPH_BASE + (((uint32_t)address) - BITBAND_PERIPH_REF) * 32 + (bit) * 4))
+//}/***********************************************************************/
+
+
+// Initialise LED1 gpio
 DigitalOut myled(LED1);
 
+/* bit-band definition, LED1 is PA_5 */
+#define LED_BB *((volatile unsigned char *)BITBAND_PERIPH(&GPIOA->ODR, 5))
+
 int main() {
     while(1) {
-        myled = 1;
+        LED_BB = 1; // set led on
         wait(0.2);
-        myled = 0;
+        LED_BB = 0; // clear led
         wait(0.2);
     }
 }