Skip to content

Commit 817d64d

Browse files
author
Amanda Butler
authored
Merge pull request #15 from linlingao/f_blinky-baremetal
Added Baremetal-Blinky example
2 parents 6592765 + 0b91f94 commit 817d64d

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Baremetal-Blinky/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Baremetal Blinky example using Mbed OS
2+
3+
This guide reviews the steps required to build and run a baremetal Blinky application on TI's CC3220SF LaunchXL platform without using DigitalOut class and timers.
4+
5+
Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
6+
7+
This example retrieves code from https://github.com/ARMmbed/mbed-os-ti-port. It's a private repo; please contact [email protected] to request access.
8+
9+
### Import the example application
10+
11+
From the command-line, import the example:
12+
13+
```
14+
git clone https://github.com/ARMmbed/mbed-os-examples-docs_only.git
15+
cd Baremetal-Blinky
16+
mbed config root .
17+
mbed deploy
18+
```
19+
20+
#### Now compile
21+
22+
23+
```
24+
mbed compile -m cc3220sf -t gcc_arm
25+
```
26+
27+
#### Program your board
28+
29+
1. Connect your Mbed device to the computer over USB.
30+
2. Copy the binary file to the Mbed device.
31+
3. Observe the red LED blinking.
32+

Baremetal-Blinky/main.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "mbed.h"
2+
3+
// Port A0: 0x40004000 GPIO0 to GPIO7
4+
// Port A1: 0x40005000 GPIO8 to GPIO15 Use GPIO13 (SW2) as input, GPIO9(D10 Red) as output
5+
// Port A2: 0x40006000 GPIO16 to GPIO23
6+
// Port A3: 0x40007000 GPIO24 to GPIO31
7+
8+
#define WAIT_CYCLES_LONG 10000000
9+
#define WAIT_CYCLES_SHORT 1000000
10+
#define INPUT_PIN_PORTA1 5
11+
#define OUTPUT_PIN_PORTA1 1
12+
#define GPIO_PORTA1_ADDRESS 0x40005000
13+
#define GPIO_PAD_CONFIG_9_ADDRESS 0x4402E0C4
14+
#define OFFSET_DIR 0x400
15+
#define OFFSET_DATA 0
16+
#define ARCM_BASE 0x44025000
17+
#define PRCM_RUN_MODE_CLK 0x00000001
18+
#define PRCM_SLP_MODE_CLK 0x00000100
19+
#define GPIO_PAD_CONFIG_9 0x4402E0C4
20+
#define PAD_MODE_MASK 0x0000000F
21+
22+
static void set_gpio_dir()
23+
{
24+
// Configure direction Bit 7:0 DIR, 0 = input, 1 = output
25+
*((volatile unsigned long*)(GPIO_PORTA1_ADDRESS + OFFSET_DIR)) &= ~0x20; // Configure SW2 as input
26+
*((volatile unsigned long*)(GPIO_PORTA1_ADDRESS + OFFSET_DIR)) |= 0x2; // Configure D10 as output
27+
28+
}
29+
30+
static const unsigned long g_ulPinToPadMap[64] =
31+
{
32+
10,11,12,13,14,15,16,17,255,255,18,
33+
19,20,21,22,23,24,40,28,29,25,255,
34+
255,255,255,255,255,255,255,255,255,255,255,
35+
255,255,255,255,255,255,255,255,255,255,255,
36+
31,255,255,255,255,0,255,32,30,255,1,
37+
255,2,3,4,5,6,7,8,9
38+
};
39+
40+
void PinModeSet(unsigned long ulPin,unsigned long ulPinMode)
41+
{
42+
unsigned long ulPad;
43+
44+
// Get the corresponding Pad
45+
ulPad = g_ulPinToPadMap[ulPin & 0x3F];
46+
47+
// Calculate the register address
48+
ulPad = ((ulPad << 2) + (0x4402E000+0x000000A0));
49+
50+
// Set the mode.
51+
*((volatile unsigned long*)(ulPad)) = (((*((volatile unsigned long*)(ulPad))) & ~PAD_MODE_MASK) | ulPinMode) & ~(3<<10);
52+
}
53+
54+
int main()
55+
{
56+
PinModeSet(0x0000003F,0x000000000);
57+
*((volatile unsigned long*)(ARCM_BASE + 0x58)) |= PRCM_RUN_MODE_CLK || PRCM_SLP_MODE_CLK;
58+
59+
unsigned long wait_cycles_in_use = WAIT_CYCLES_SHORT;
60+
volatile unsigned long delay = 0;
61+
62+
set_gpio_dir();
63+
*((volatile unsigned long*)(GPIO_PAD_CONFIG_9))|= 0x220;
64+
65+
while (true)
66+
{
67+
68+
// Check if SW2 is pressed
69+
if (*(volatile unsigned long *)(GPIO_PORTA1_ADDRESS + OFFSET_DATA + ((1 << INPUT_PIN_PORTA1) << 2)))
70+
{
71+
wait_cycles_in_use = WAIT_CYCLES_LONG;
72+
}
73+
74+
*(volatile unsigned long *)(GPIO_PORTA1_ADDRESS + OFFSET_DATA + ((1 << OUTPUT_PIN_PORTA1) << 2)) = (OUTPUT_PIN_PORTA1 << 1);
75+
delay = wait_cycles_in_use;
76+
while (delay--);
77+
*(volatile unsigned long *)(GPIO_PORTA1_ADDRESS + OFFSET_DATA + ((1 << OUTPUT_PIN_PORTA1) << 2)) = 0;
78+
delay = wait_cycles_in_use;
79+
while (delay--);
80+
}
81+
}
82+

Baremetal-Blinky/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os-ti-port/#1304ebdb5e8d1e6d13aabe1360813b75f58c0828

0 commit comments

Comments
 (0)