Skip to content

Commit 6286c78

Browse files
committed
Add enableBurstMode() function and example to core.
1 parent a085660 commit 6286c78

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

cores/arduino/ard_sup/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ extern "C"
7676
#include "ap3_debugging.h"
7777
#include "ap3_uart.h"
7878
#include "ap3_analog.h"
79+
#include "ap3_clock_sources.h"
7980
#include "WMath.h"
8081
#include "WCharacter.h"
8182

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
30+
#endif //_AP3_GPIO_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "ap3_clock_sources.h"
2+
3+
//Turns main processor from 48MHz to 96MHz
4+
//Returns false if burst mode failed to enable
5+
bool enableBurstMode(void)
6+
{
7+
// Check that the Burst Feature is available.
8+
am_hal_burst_avail_e eBurstModeAvailable;
9+
if (AM_HAL_STATUS_SUCCESS != am_hal_burst_mode_initialize(&eBurstModeAvailable))
10+
{
11+
return (false);
12+
}
13+
14+
// Put the MCU into "Burst" mode.
15+
am_hal_burst_mode_e eBurstMode;
16+
if (AM_HAL_STATUS_SUCCESS != am_hal_burst_mode_enable(&eBurstMode))
17+
{
18+
return (false);
19+
}
20+
return (true);
21+
}
22+
23+
//Turns main processor from 96MHz to 48MHz
24+
//Returns false if disable fails
25+
bool disableBurstMode(void)
26+
{
27+
am_hal_burst_mode_e eBurstMode;
28+
if (AM_HAL_STATUS_SUCCESS == am_hal_burst_mode_disable(&eBurstMode))
29+
{
30+
if (AM_HAL_NORMAL_MODE != eBurstMode)
31+
{
32+
return (false);
33+
}
34+
}
35+
else
36+
{
37+
return (false);
38+
}
39+
return (true);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Increasing core speed to 96MHz
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: June 24th, 2019
6+
License: This code is public domain but the prime number function
7+
comes from Ambiq/John Burkardt and has a GNU LGPL license. Additional
8+
code based on Ambiq's burst example.
9+
10+
SparkFun labored with love to create this code. Feel like supporting open source hardware?
11+
Buy a board from SparkFun! https://www.sparkfun.com/products/15376
12+
13+
This example shows how to increase the core speed from 48MHz to 96MHz.
14+
15+
Increasing the core speed will increase current consumption. And increase in core
16+
speed is useful for calculations and minimizing code run time. Burst mode does not increase
17+
the speed at which GPIO can toggle.
18+
*/
19+
20+
long startTime;
21+
long endTime;
22+
int count = 0;
23+
24+
//Make true if you want to print the prime numbers
25+
//Printing output will destroy the accuracy of the timing
26+
bool printThePrimes = false;
27+
28+
void setup() {
29+
Serial.begin(9600);
30+
Serial.println("Calculating primes with burst mode");
31+
32+
startTime = millis();
33+
count = numberOfPrimes(10000); //Find the number of primes in 10,000
34+
endTime = millis();
35+
36+
Serial.printf("Total primes found (should be 1229): %d\n", count);
37+
Serial.printf("Time required at 48MHz: %dms\n", endTime - startTime);
38+
39+
enableBurstMode(); //Go to 96MHz
40+
startTime = millis();
41+
count = numberOfPrimes(10000); //Find the number of primes in 10,000
42+
endTime = millis();
43+
disableBurstMode(); //Return to 48MHz
44+
45+
Serial.printf("Total primes found (should be 1229): %d\n", count);
46+
Serial.printf("Time required in burst mode: %dms\n", endTime - startTime);
47+
}
48+
49+
void loop() {
50+
//Do nothing
51+
}
52+
53+
// Returns the number of primes between 1 and N.
54+
// A naive algorithm is used.
55+
// Input, int N, the maximum number to check.
56+
// Output, int PRIME_NUMBER, the number of prime numbers up to N.
57+
int numberOfPrimes(int maxToSearch)
58+
{
59+
uint32_t ui32Total, ui32Prime;
60+
int32_t ix, jx;
61+
62+
ui32Total = 0;
63+
64+
for ( ix = 2; ix <= maxToSearch; ix++ )
65+
{
66+
ui32Prime = 1;
67+
for ( jx = 2; jx < ix; jx++ )
68+
{
69+
if ( (ix % jx) == 0 )
70+
{
71+
ui32Prime = 0;
72+
break;
73+
}
74+
}
75+
if (ui32Prime == 1 && printThePrimes == true)
76+
{
77+
Serial.printf("Prime found: %d\n", ix);
78+
}
79+
ui32Total += ui32Prime;
80+
}
81+
return ui32Total;
82+
}

0 commit comments

Comments
 (0)