Can the PDM on the Redboard Artemis be set up to Achieve 48/16/44.1 KHz Audio Data?

Per the article “How to Set up the PDM to Achieve 48/16/44.1 KHz Audio Data”, from the support.ambiqmicro.com website, the following code will fine tune the Apollo 3 PDM to produce nearly exact PCM audio sampling rates of 48/16/44. 1 KHz:

case AM_HAL_CLKGEN_CONTROL_HFADJ_ENABLE:

_VAL2FLD(CLKGEN_HFADJ_HFXTADJ, 0x5DC) /* 49.152 MHz */

or

_VAL2FLD(CLKGEN_HFADJ_HFXTADJ, 0x562) /* 45.1584 MHz */

The case statement comes from the function “uint32_t am_hal_clkgen_control(am_hal_clkgen_control_e eControl, void *pArgs)” that can be found in the file “am_hal_clkgen.c” from the ambiq sdk.

Will the referenced function work on the Redboard Artemis?

I have tried adding “#include <am_hal_clkgen_h>” and calling the function from within the Arduino IDE but it isn’t recognizing the function and treats my call as an improper function definition. Is it possible to “#include” the am_hal_clkgen.h and gain access to the functions in am_hal_clkgen.c from within the Arduino IDE or do I need to use a different interface for this?

I was able to upload the command am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_HFADJ_ENABLE, _VAL2FLD(CLKGEN_HEADJ_HFXTADJ, 0x5DC)) via the AmbiqSDK environment but I think it bricked my board. I can no longer upload anything even with the Arduino IDE. Even “Burn Bootloader” fails. Is there a way to reset the clock to its factory value?

seggar j-link edu mini with download of seggar Ozone. Ambiq Apollo 3 is selectable. Should work…~$20 same as the price of a new board. If your doing that stuff you might want one anyway??

KHE - thanks for the suggestion, I was wondering whether the J-link edu programmers could be used and as you implied the mini is a bargain. I also just came across your post on developing the AndroidArtemisBleUartClient and believe the information you provided on GitHub about using the J-link will be invaluable. And as a bonus your project is one that I wanted to create for the Redboard Artemis and hopefully I can use most of your work without too much modification being needed. One thing I still may need in order to get the bricked board going again is the binary file for the boards firmware in the event it needs to be reflashed. Do you have any idea as to whether that is available and how I could get it?

It is a selectable item in a drop-down list in the ozone software for Ambiqmicro boards. Use AMA3B1KK-KBR.

helping someone else with phone <> artemis BLE…

Let’s make you successful quickly…Phone <> SparkFun Artemis board via BLE

My UserName on my computer is kerry so my directory locations on Windows 10 are:

c;/Users/kerry/Documents/AmbiqSuiteSDK SDK Location

c:/Users/kerry/AppData/Local/Arduino15/packages/SparkFun/hardware/apollo3/1.0.29 Arduino CORE

c:Users/kerry/Documents/Arduino Arduino Sketch directory

I have backup directories under Documents of SDK2.2.0, SDK2.3.2, SDK2.4.2, Arduino1.0.29

I am currently configured with SDK2.4.2 and Arduino1.0.29 modified using SDK2.4.2

I will now switch to your setup which is SDK2.3.2 and Arduino 1.0.29 (probably??)

Time: Action

4:02 am Delete SDK 2.4.2

4:03 am Copy SDK 2.3.2 to SDK Directory

4:04 am Delete CORE 1.0.29 Modified

4:05 am Copy Standard CORE 1.0.29 to Core Directory

4:06 am Download repo: https://github.com/kerryeven/AMDTPS-Por … ified_core

4:07 am Unzip download and copy amdtps folder to Arduino Sketch directory

4:08 am double click amdtps.ino to open Arduino then Verify/Compile

4:10 am Arduino Upload…5 sec’s max

4:11 am Start Nrf Connect on tablet, select amdtps…click unknown charachteristic 3 down arrows

they get a line through them…select Unknown Charachteristic Up Arrow…

click down arrow to right of BYTE and scroll to select TEXT…Enter 1 on New

value line … click send…BUILTIN_LED lights.

So, you don’t need anything to do with the SDK etc. Just use my amdtps files in the amdtps folder on the

repo. The extensive step-by-step stuff I documented was just for those curious as to what was changed to get it to work. Once again, the Arduino magic is documented in the amdtps.ino file in the repo:

https://github.com/kerryeven/AMDTPS-Por … .3.2-files

amdtps is a full-featured application meant to work with amdtpc (client) When client is run on one board and connected to a terminal, it will present a menu on the terminal allowing one to select the server board and send or receive “fake” data. Nrf Connect or my phone app is acting as the client and sending a message to the amdtps server which sends back the same message (could send anything back) and sends the received command to Arduino. NO SDK NEEDED other that to get the base files. The full app implements security and error checking etc. Those are some of the items I turned off to get to work with the SparkFun Arduino CORE. The full implementation can be gotten in that second repo but the Arduino CORE needs to be modified.

Hope that helps…that is as clear and easy as I think I can make it although who knows…

Kerry

Kerry - thanks again for your assistance and the trouble you went to in order to streamline the implementation of your project. I won’t be able to get started on this until late next week but when I do I’ll let you know how it went. Even if I can’t get my bricked board going, I have another one ordered, since they are so cheap, that I should get tomorrow. And having two of them might be an advantage.

Kerry - I was able to restore the “bricked board” using a J-Link EDU mini and Ozone IDE. It was tricky because I only had 4 seconds to connect to the board following power on and then overwrite a memory value used by the HFADJ register. Once the memory value was corrected the board continued to operate without disconnecting. I then used J-Flash Lite to erase the chip memory followed by uploading a known good program. The board is working as it should now. Your write-up on using the J-Link tools was very helpful in making this happen.

Regarding your “AndroidArtemisBleUartClient” project, I successfully compiled the server and client programs after a few misstarts involving the use of incorrect SDK versions. However, I was not able to load either of these onto my Redboard Artemis using the “make bootload_svl” command. I suspect that I have to use the “make bootload_asb” command instead, but I didn’t want to do this with my new board until I had the bricked board working again (in case I would brick the new one!). And before I try using the _asb version I want to modify any of the source files that would have incompatible settings. I believe you created your files for an Edge2 board or perhaps a Nano board that you mentioned. Can you identify any files and settings that you used that might not be compatible with the Redboard Artemis?

Randy

I believe the only thing I modified from a hrdwr standpoint was turning on and off pin 19 for the built in LED. I tried to comment any changes with KHE so you could search for that in the files to see any changes.

The cleanest build that I was able to achieve was with SDK 2.4.2 from the Ambiqmicro website that opens with a page showing the 5 apollo chips. You click the apollo3_evb and then select software to get the latest version. There are release notes with comments on known bugs. 2.4.2 will work with the earlier referenced makesdk.sh script to install the SDK files to the SparkFun Arduino Core which is currently running SDK 2.2.0 files.

Both amdtpc and amdtps will work with each other in SDK land and both: make BOARD=$XXX works (uses svl by default). I cannot get amdtpc to work with Arduino though.

I have bounced back and forth using asb and svl with the only caveat being that if asb used, need to go to Arduino and do the Load Bootloader thing. Have fun, Kerry

Kerry,

Should you ever “brick” a board, see the recovery method, provided by Ambiq Micro support (I got this shortly after figuring out my method), at the following link:

https://support.ambiqmicro.com/hc/en-us … pins-Help-

In regards to the BLE project, I can upload both the _amdtps and _amdtpc versions using “make bootload_asb” but I think only the _amdtps version actually works. I can see and interact with the board using the “Nrf Connect” app when the _amdtps version is loaded, whereas I can’t when the _amdtpc version is loaded. But I think I’m close and eventually I’ll figure it out. Thanks again for all your help, its greatly appreciated.

Randy

yes. the s version works with phone. c version only works with s version board running. You interact with it via the usb/comm/uart. See amdtp app note under docs in the SDK.

Kerry,

I took advantage of having two boards and loaded the server onto the previously “bricked” board and the client onto the newest board and connected each one to different computers several feet apart. The server was connected to the J-Link and I had the “Seggar SWD Viewer” open to monitor messages from it. The clients messages were being monitored via USB and “Termite” on the other computer. The server displays advertising, connect and disconnect msgs when connections are established by either the client or the “Nrf Connect” app from an android phone. I was disappointed that no msgs were displayed when I sent data via the GATT service through the Nrf app but its obvious the server is working. The client displays messages, with your KHE fingerprint all over them, showing connection to the server but I was disappointed that the “friendly name” of the server is not displayed in the scan results. At this time I have no idea what the numbers in the scan results mean but I was able to figure out which result was associated with the server. Its also obvious that the client works but the “_AMDPT” options 2 & 4 to stop data transmission don’t appear to work. I have to reset the boards to stop the data flow following options 1 & 3. Although both the server and client need some work I think I have a good starting point now for a BLE project of my own.

I’ve only looked over your “Readme” file for the most recent incarnation of your project and if I’m understanding it correctly, you have used features in SDK 2.3.0 that allow you to create an Arduino sketch from the compiled (or maybe source) files and then run them via the Arduino IDE. Is that right?

Randy

Yes. You are on it. Problem is SDK is 2.3.2 but the SparkFun Arduino Core is only 2.2.0. Directory structures are different and several functions have added parameters. Security has also been inmplemented in SDK 2.3.2+ but not in 2.2.0. That is why I wrote script makeSKD.sh - to copy the SDK 2.3.2 or 2.4.2 files to appropriate directories in the Arduino Core (currently 1.0.29).

Server now works great and completely in Arduino. Client works and displays the menu on Mosquito but the app uses an ISR am_uart_isr to trigger an interrupt to handle the user input into Termite. I do not know how to execute that ISR in Arduino but am looking into it.

I know in SDK gcc compiler file startup_gcc.c references am_uart_isr twice:

extern void am_uart_isr(void) __attribute ((weak, alias (“am_default_isr”)));

am_uart_isr, // 15: UART0

Just starting to google how to make that ISR happen in Arduino…Could definately use some help on that. Current Arduino Client files are at:

https://github.com/kerryeven/AMDTPS-Por … .3.2-files

Just copy amdtpc folder/files to Arduino Sketch directory. Server files are in there too.

I have ported the amdtps from Freetos to Arduino IDE (as many others have done) as it was easy. Than I ported the AMDTPC to Linux, running on Bluez (the Bluetooth stack from Linux). I have added to the server and client a menu structure so you can request different tasks/ info from the server : switch led on and off, set or read a digital pin, read an analog pin, read the internal Apollo3 chip temperature, read the battery level, (if connected) read BME280 results, perform a simple chat between client and server, send start and stop testdata. Easy to extend if necessary (in case you interested it is on https://github.com/paulvha/apollo3)

Maybe I can offer my help here. I have spent a TON of time on getting this going with the limited information.

I see you copy the SDK files, so did I as I had to debug an issue. BUT without changing the platform.txt, none of them will be taken into the final object as it will source these routines from /projects/generic/stacklib/gcc/bin-cortex-m4/libstacklib.a. I think this library was created to reduce the compile time as these files do not change. Hopefully the adjust platform.txt is attached for reference.
platform_exactle.txt (11.5 KB)

The set_next_wakeup() setting does not work and is necessary, it can be removed as it does not timeout. When a call is done to update_scheduler_timers(); it will update the WSF and if the WSF-ticks have passed it will set the WSF_TIMER_EVENT, which is executed with the wsfOsDispatcher() call that is following right after that in loop().

You can check by setting a debug message in set_next_wakeup() where it will never reset the timer. BUT even if radio_timer_handler() would called the WsfTaskSetReady(0, 0) call does not trigger any WSF event.

Sending the test data from within the driver did not work as we need to keep feeding wsf-ticks. So I moved that to user level. Next to that a number of other changes ( e.g. to get the name correct advertized)

I run into issue with ADC readings and Serial ouput which i have already passed on Sparkfun for requesting to make changes.

I will try to work on the client side now from an Artemis and see whether I can help. I have 2 Atemis Edge boards (as one was bricked and recovered) and one Artemis Redboard ATP. I would prefer however to NOT set Artemis registers directly (unless not supported by the API)