Accuracy of the sleep clock in the BLE (Bluetooth® low energy) sub-system may influence the stability of the BLE connection. On a case-by-case basis, the system designer may have to use a different clock source for the BLE part. This article explains how to configure the LF (low frequency) clock source (sleep clock) of the BLE sub-system (EM9304) of the Apollo2 Blue to be the clock generated from the Apollo2’s CLKOUT signal.
(All tools used in this article and documents referenced are listed at the end of the article.)
Hardware used in this article is the Ambiq Micro Apollo2 Blue EVB.
If you are using different hardware, make sure that the BSP settings for project “em9304_test_bridge” and your test application are modified accordingly and the projects can run correctly on your board.
Software version used in this article:
Ambiq Micro SDK: Ambiqsuite release 1.2.10-hotfix2
EM9304 Configuration Editor: version 0.3.7 (or later)
Segger J-Flash Lite: version 6.12c (or later)
Python: version 3.6.2 (or later).
Step 1: Load the “em9304_test_bridge” firmware into the target Apollo2 Blue device.
This can be done with Segger J-Flash Lite.
Binary located at ..\AmbiqMicro\AmbiqSuite\boards\apollo2_blue_evb\examples\em9304_test_bridge\keil\bin
Once programming is done, reset the device.
Step 2: Start the EM9304 Configuration Editor
Select the right serial communication interface and parameters.
Select [Read from device]
If you get an error message like “DVK is not responding”, make sure the COM port communication is working correctly.
Upon successful connection, select [Power Management] tab and the following view is shown:
Step 3: Select “External Square Wave” for the [LF Clock Source] option, and the right clock accuracy for [LF Clock Accuracy] according to the actual 32 kHz crystal accuracy of the system (the one that is connected to Apollo2 Blue).
Note: The Apollo2 Blue internal digital XT calibration cannot be applied to a 32 kHz CLKOUT. Therefore, if 32 kHz is selected as recommended, make sure the accuracy is selected according to the actual crystal circuit specification and not the accuracy after Apollo2 Blue internal calibration.
E.g. if the crystal circuit accuracy is 101ppm~150ppm, the setting looks like this:
Step 4: Upload the patch to the chip.
Select [Upload Configuration…] from the [File] drop down menu.
Upload patch window will pop up.
“Patch Type” is “Diff”.
“Destination” is “OTP”
“User Build” is 4, which is used to determine the source of the patch.
=> 0, 1: Reserved by EM
=> 2, 3: Reserved by Ambiq Micro
=> 4+ : Available for customer
(Check the README.txt under ..\AmbiqMicro\AmbiqSuite\tools\emp2include)
“Patch ID” can be defined at will, this is used to identify the patch for users.
Click “Upload” to load the patch into the OTP.
Step 5: Save the patch into a *.emp file.
Select [Save Diff Patch…], and save the *.emp file generated into the following directory:
Now we have the patch file generated as a binary file.
The next steps convert the file into *.c and *.h files so that we can load them into our application project as source.
Before doing so, it is recommended to back up the “em9304_patches.c” and “em9304_patches.h” files in the directory:
Step 1: Open a command line environment and navigate to the directory:
Run “em2include.py -o OTP” command.
Step 2: Verify that the new patch is converted.
Go to ..\AmbiqMicro\AmbiqSuite\third_party\exactle\sw\hci\ambiq\em9304 and check the new “em9304_patches.c” and “em9304_patches.h”.
(The back-up file is on the left and the new file is on the right.)
Step 3: Include the patch into your project.
(If your project is based on any of our BLE examples, the “em9304_patches.c” file should already be included.)
Step 4: Build and Run.
Once the project is built and run, the new patch(es) will be applied at runtime when initializing the BLE device.
If you would like to verify the patch from the EM9304 Configuration Editor, you will need to first invalidate the patch in this particular part, since at step 4 of “Prepare the patches” it is already patched to it, or just use another board/part without the patch to verify the result.
Patches with the same ID and type will not be patched multiple times in the OTP of EM9304 during the initialization process.
The Apollo2 Blue device has an internal connection between the Apollo2 MCU part and the BLE sub-system, and it is shown in the diagram below.
GPIO24/CLKOUT of Apollo2 is connected to LF_XIN of the EM9304 sub-system.
Configuration on the Apollo2 side can be done as coded below:
If, as in this example, the external crystal is just enabled here, a proper delay should be considered to be added here to allow stabilization of the oscillation.
Configure GPIO24 as the CLKOUT function and enable the CLKOUT output at XT frequency before the lower level driver initializes EM9304 by calling "HciDrvRadioBoot(0)".
This is done because EM9304 will check the availability of the alternative LF clock source at boot-up, if other than internal RC is selected. If this 32 kHz clock signal is not valid at EM9304 boot-up, the internal RC with a clock accuracy of 251~500 ppm will be used.
Note: Driving a 32 kHz clock (square wave) at the CLKOUT pin of the Apollo2 will draw extra current by the device.
CLKOUT from GPIO24 of the Apollo2 MCU will not be stopped ever during BLE operation, but it will be stopped when BLE/EM9304 is shut down to save power.
Ambiqsuite SDK 1.2.10-hotfix2:
Segger J-Flash Lite:
(Links below may need registration before you can download/access.)
EM9304 Configuration Editor:
EM9304 Application Note - Low-Frequency Clock Configuration and Calibration v1.2:
Discussion: LF Clock for EM9304: