Skip to content

Commit cd6fe5e

Browse files
committed
Add library for burst mode support
1 parent 70026f7 commit cd6fe5e

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//Burst Mode example
2+
//TEST_PIN is toggled as fast as possible, with burst mode enable and disabled.
3+
//Use a logic analyzer to view the difference in output
4+
#include "BurstMode.h"
5+
6+
#define TEST_PIN D2 //Change to whatever pin you would like
7+
8+
#define NUM_TOGGLES 20 //Number of times to toggle the gpio as an example task
9+
10+
void setup() {
11+
Serial.begin(115200);
12+
Serial.println("BurstMode Example1 - Enable and Disable");
13+
}
14+
15+
void loop() {
16+
long startTime, endTime;
17+
enableBurstMode(); //Go to 96MHz
18+
//Toggle the with digital write as fast as possible, 20 times
19+
startTime = micros();
20+
for(int i = 0; i < NUM_TOGGLES; i++)
21+
{
22+
digitalWrite(TEST_PIN, HIGH);
23+
digitalWrite(TEST_PIN, LOW);
24+
}
25+
endTime = micros();
26+
Serial.printf("Time (in microseconds) to toggle GPIO %d times = %d, at clock speed %d \r\n",
27+
NUM_TOGGLES, (endTime - startTime), getCpuFreqMHz());
28+
29+
disableBurstMode(); //Go back to 48MHz
30+
//Toggle the with digital write as fast as possible, 20 times
31+
startTime = micros();
32+
for(int i = 0; i < NUM_TOGGLES; i++)
33+
{
34+
digitalWrite(TEST_PIN, HIGH);
35+
digitalWrite(TEST_PIN, LOW);
36+
}
37+
endTime = micros();
38+
Serial.printf("Time (in microseconds) to toggle GPIO %d times = %d, at clock speed %d \r\n",
39+
NUM_TOGGLES, (endTime - startTime), getCpuFreqMHz());
40+
41+
delay(1000);
42+
}

libraries/BurstMode/keywords.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Syntax Coloring Map For 'libraries/BurstMode'
2+
3+
# Datatypes (KEYWORD1)
4+
5+
6+
# Functions (KEYWORD2)
7+
enableBurstMode KEYWORD2
8+
disableBurstMode KEYWORD2
9+
getCpuFreqMHz KEYWORD2
10+
11+
# Structures (KEYWORD3)
12+
13+
# Constants (LITERAL1)
14+
15+
# Properties (LITERAL2)
16+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=BurstMode
2+
version=2.0.0
3+
author=SparkFun Electronics
4+
maintainer=SparkFun Electronics <sparkfun.com>
5+
sentence=Burst Mode library for the SparkFun Artemis
6+
paragraph=Allows for enabling, disabling, and checking status of burst mode which changes the clock from 48Mhz to 96Mhz
7+
category=
8+
url=
9+
architectures=apollo3

libraries/BurstMode/src/BurstMode.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "BurstMode.h"
2+
3+
uint32_t cpuFreq = 48000000; //At POR core is 48MHz
4+
5+
//Turns main processor from 48MHz to 96MHz
6+
//Returns false if burst mode failed to enable
7+
bool enableBurstMode(void)
8+
{
9+
// Check that the Burst Feature is available.
10+
am_hal_burst_avail_e eBurstModeAvailable;
11+
if (AM_HAL_STATUS_SUCCESS != am_hal_burst_mode_initialize(&eBurstModeAvailable))
12+
{
13+
return (false);
14+
}
15+
16+
// Put the MCU into "Burst" mode.
17+
am_hal_burst_mode_e eBurstMode;
18+
if (AM_HAL_STATUS_SUCCESS != am_hal_burst_mode_enable(&eBurstMode))
19+
{
20+
return (false);
21+
}
22+
cpuFreq = 96000000;
23+
return (true);
24+
}
25+
26+
//Turns main processor from 96MHz to 48MHz
27+
//Returns false if disable fails
28+
bool disableBurstMode(void)
29+
{
30+
am_hal_burst_mode_e eBurstMode;
31+
if (AM_HAL_STATUS_SUCCESS == am_hal_burst_mode_disable(&eBurstMode))
32+
{
33+
if (AM_HAL_NORMAL_MODE != eBurstMode)
34+
{
35+
return (false);
36+
}
37+
}
38+
else
39+
{
40+
return (false);
41+
}
42+
cpuFreq = 48000000;
43+
return (true);
44+
}
45+
46+
//Returns the current core speed
47+
uint32_t getCpuFreqMHz(void)
48+
{
49+
return (cpuFreq);
50+
}

libraries/BurstMode/src/BurstMode.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright (c) 2019 SparkFun Electronics
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
#ifndef _AP3_CLOCK_SOURCES_H_
23+
#define _AP3_CLOCK_SOURCES_H_
24+
25+
#include "Arduino.h"
26+
27+
bool enableBurstMode();
28+
bool disableBurstMode();
29+
uint32_t getCpuFreqMHz();
30+
31+
#endif //_AP3_GPIO_H_

0 commit comments

Comments
 (0)