Skip to content

Changed to K64F example #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Baremetal-Blinky/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
## Baremetal Blinky example using Mbed OS

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.
This guide reviews the steps required to build and run a baremetal Blinky application on FRDM-K64F without using DigitalOut class and timers.

Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).

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.

### Import the example application

From the command-line, import the example:

```
git clone https://github.com/ARMmbed/mbed-os-examples-docs_only.git
cd Baremetal-Blinky
cd mbed-os-examples-docs_only/Baremetal-Blinky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnotherButler could confirm, but the way this is linked in the docs, the directory change isn't needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, the README.md isn't used within the docs, only the source.

So this should be fine.

mbed config root .
mbed deploy
```
Expand All @@ -21,12 +19,12 @@ mbed deploy


```
mbed compile -m cc3220sf -t gcc_arm
mbed compile -m k64f -t gcc_arm
```

#### Program your board

1. Connect your Mbed device to the computer over USB.
2. Copy the binary file to the Mbed device.
3. Observe the red LED blinking.
3. Observe LED blinking.

85 changes: 18 additions & 67 deletions Baremetal-Blinky/main.cpp
Original file line number Diff line number Diff line change
@@ -1,82 +1,33 @@
#include "mbed.h"
#include "MK64F12.h"

// Port A0: 0x40004000 GPIO0 to GPIO7
// Port A1: 0x40005000 GPIO8 to GPIO15 Use GPIO13 (SW2) as input, GPIO9(D10 Red) as output
// Port A2: 0x40006000 GPIO16 to GPIO23
// Port A3: 0x40007000 GPIO24 to GPIO31

#define WAIT_CYCLES_LONG 10000000
#define WAIT_CYCLES_SHORT 1000000
#define INPUT_PIN_PORTA1 5
#define OUTPUT_PIN_PORTA1 1
#define GPIO_PORTA1_ADDRESS 0x40005000
#define GPIO_PAD_CONFIG_9_ADDRESS 0x4402E0C4
#define OFFSET_DIR 0x400
#define OFFSET_DATA 0
#define ARCM_BASE 0x44025000
#define PRCM_RUN_MODE_CLK 0x00000001
#define PRCM_SLP_MODE_CLK 0x00000100
#define GPIO_PAD_CONFIG_9 0x4402E0C4
#define PAD_MODE_MASK 0x0000000F

static void set_gpio_dir()
void bm_gpio_init(void)
{
// Configure direction Bit 7:0 DIR, 0 = input, 1 = output
*((volatile unsigned long*)(GPIO_PORTA1_ADDRESS + OFFSET_DIR)) &= ~0x20; // Configure SW2 as input
*((volatile unsigned long*)(GPIO_PORTA1_ADDRESS + OFFSET_DIR)) |= 0x2; // Configure D10 as output

SIM->SCGC5 = SIM_SCGC5_PORTB_MASK;
PORTB->PCR[22] = PORT_PCR_MUX(1U);
PTB->PDDR = (1U << 22U);
}

static const unsigned long g_ulPinToPadMap[64] =
void bm_delay(void)
{
10,11,12,13,14,15,16,17,255,255,18,
19,20,21,22,23,24,40,28,29,25,255,
255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,
31,255,255,255,255,0,255,32,30,255,1,
255,2,3,4,5,6,7,8,9
};

void PinModeSet(unsigned long ulPin,unsigned long ulPinMode)
{
unsigned long ulPad;

// Get the corresponding Pad
ulPad = g_ulPinToPadMap[ulPin & 0x3F];

// Calculate the register address
ulPad = ((ulPad << 2) + (0x4402E000+0x000000A0));
volatile unsigned int i,j;

// Set the mode.
*((volatile unsigned long*)(ulPad)) = (((*((volatile unsigned long*)(ulPad))) & ~PAD_MODE_MASK) | ulPinMode) & ~(3<<10);
for (i = 0U; i < 100000U; i++) {
for (j = 0U; j < 100U; j++) {
__asm__("nop");
}
}
}

int main()
int main(void)
{
PinModeSet(0x0000003F,0x000000000);
*((volatile unsigned long*)(ARCM_BASE + 0x58)) |= PRCM_RUN_MODE_CLK || PRCM_SLP_MODE_CLK;

unsigned long wait_cycles_in_use = WAIT_CYCLES_SHORT;
volatile unsigned long delay = 0;
bm_gpio_init();

set_gpio_dir();
*((volatile unsigned long*)(GPIO_PAD_CONFIG_9))|= 0x220;

while (true)
{

// Check if SW2 is pressed
if (*(volatile unsigned long *)(GPIO_PORTA1_ADDRESS + OFFSET_DATA + ((1 << INPUT_PIN_PORTA1) << 2)))
{
wait_cycles_in_use = WAIT_CYCLES_LONG;
}
PTB->PSOR = (1U << 22U);

*(volatile unsigned long *)(GPIO_PORTA1_ADDRESS + OFFSET_DATA + ((1 << OUTPUT_PIN_PORTA1) << 2)) = (OUTPUT_PIN_PORTA1 << 1);
delay = wait_cycles_in_use;
while (delay--);
*(volatile unsigned long *)(GPIO_PORTA1_ADDRESS + OFFSET_DATA + ((1 << OUTPUT_PIN_PORTA1) << 2)) = 0;
delay = wait_cycles_in_use;
while (delay--);
while (1) {
PTB->PTOR = (1U << 22U);
bm_delay();
}
}

2 changes: 1 addition & 1 deletion Baremetal-Blinky/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ti-port/#1304ebdb5e8d1e6d13aabe1360813b75f58c0828
https://github.com/ARMmbed/mbed-os/#2fd0c5cfbd83fce62da6308f9d64c0ab64e1f0d6