Skip to content

Commit dcd30a5

Browse files
author
oclyke
committed
partially fixed pdm
added a precompiled math library to cover some arm math functions had to use the non hardware floating point version due to mbed compile/link flags (-mfloat-abi=softfp) still seeing issues when interrupts are enabled - may need to investigate mbed handling of pdm isr
1 parent 933524d commit dcd30a5

File tree

12 files changed

+51
-37
lines changed

12 files changed

+51
-37
lines changed
5.11 MB
Binary file not shown.

libraries/PDM/src/PDM.cpp

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ SOFTWARE.
2121
*/
2222
#include "PDM.h"
2323

24-
AP3_PDM *ap3_pdm_handle = 0;
24+
AP3_PDM* ap3_pdm_handle = NULL;
25+
static void* pdm_handle = NULL; // the apollo3 blue only has one PDM instance so let's keep it simple
2526

2627
// AP3_PDM::AP3_PDM(uint16_t *userBuffer, uint32_t bufferSize)
2728
// {
@@ -34,7 +35,8 @@ AP3_PDM *ap3_pdm_handle = 0;
3435

3536
bool AP3_PDM::begin(pin_size_t pinPDMData, pin_size_t pinPDMClock)
3637
{
37-
_PDMhandle = NULL;
38+
pdm_handle = NULL;
39+
ap3_pdm_handle = NULL;
3840
_PDMconfig = ap3_pdm_config_default;
3941
_pinPDMData = pinPDMData;
4042
_pinPDMClock = pinPDMClock;
@@ -78,7 +80,7 @@ uint32_t AP3_PDM::_begin(void)
7880
}
7981
pincfg.uFuncSel = funcsel; // set the proper function select option for this instance/pin/type combination
8082
retval = am_hal_gpio_pinconfig(_pinPDMData, pincfg);
81-
if (retval != AP3_OK)
83+
if (retval != AM_HAL_STATUS_SUCCESS)
8284
{
8385
return retval;
8486
}
@@ -90,59 +92,70 @@ uint32_t AP3_PDM::_begin(void)
9092
}
9193
pincfg.uFuncSel = funcsel; // set the proper function select option for this instance/pin/type combination
9294
retval = am_hal_gpio_pinconfig(_pinPDMClock, pincfg);
93-
if (retval != AP3_OK)
95+
if (retval != AM_HAL_STATUS_SUCCESS)
9496
{
9597
return retval;
9698
}
9799

98100
// Initialize, power-up, and configure the PDM.
99101

100102
// //User may want to change settings mid-sketch. Only init PDM if it's new.
101-
if (_PDMhandle == NULL)
103+
if (pdm_handle == NULL)
102104
{
103105
// Now that pins are initialized start the actual driver
104-
retval = (uint32_t)am_hal_pdm_initialize(0, &_PDMhandle);
105-
if (retval != AP3_OK)
106+
retval = (uint32_t)am_hal_pdm_initialize(0, &pdm_handle);
107+
if (retval != AM_HAL_STATUS_SUCCESS)
106108
{
107109
return retval;
108110
}
109111
}
110-
retval = (uint32_t)am_hal_pdm_power_control(_PDMhandle, AM_HAL_PDM_POWER_ON, false);
111-
if (retval != AP3_OK)
112+
retval = (uint32_t)am_hal_pdm_power_control(pdm_handle, AM_HAL_PDM_POWER_ON, false);
113+
if (retval != AM_HAL_STATUS_SUCCESS)
112114
{
113115
return retval;
114116
}
115-
retval = (uint32_t)am_hal_pdm_configure(_PDMhandle, &_PDMconfig);
116-
if (retval != AP3_OK)
117+
retval = (uint32_t)am_hal_pdm_configure(pdm_handle, &_PDMconfig);
118+
if (retval != AM_HAL_STATUS_SUCCESS)
117119
{
118120
return retval;
119121
}
120-
retval = (uint32_t)am_hal_pdm_enable(_PDMhandle);
121-
if (retval != AP3_OK)
122+
retval = (uint32_t)am_hal_pdm_enable(pdm_handle);
123+
if (retval != AM_HAL_STATUS_SUCCESS)
122124
{
123125
return retval;
124126
}
125127

128+
Serial.println("pdm initialized and configured. now need to enable interrupts");
129+
126130
//
127131
// Configure and enable PDM interrupts (set up to trigger on DMA
128132
// completion).
129133
//
130-
am_hal_pdm_interrupt_enable(_PDMhandle, (AM_HAL_PDM_INT_DERR | AM_HAL_PDM_INT_DCMP | AM_HAL_PDM_INT_UNDFL | AM_HAL_PDM_INT_OVF));
131-
//am_hal_interrupt_master_enable();
134+
uint32_t ui32Status = 0x00;
135+
am_hal_pdm_interrupt_status_get(pdm_handle, &ui32Status, false);
136+
am_hal_pdm_interrupt_clear(pdm_handle, ui32Status);
137+
am_hal_pdm_interrupt_enable(pdm_handle, (AM_HAL_PDM_INT_DERR | AM_HAL_PDM_INT_DCMP | AM_HAL_PDM_INT_UNDFL | AM_HAL_PDM_INT_OVF));
138+
am_hal_interrupt_master_enable();
132139
NVIC_EnableIRQ(PDM_IRQn);
133140

134-
// Register the class into the local list
141+
Serial.println("interrupts enabled");
142+
135143
ap3_pdm_handle = this;
136144

145+
Serial.println("object registered");
146+
137147
// Configure DMA and set target address of internal buffer.
138148
sTransfer.ui32TargetAddr = (uint32_t)_pdmDataBuffer;
139149
sTransfer.ui32TotalCount = _pdmBufferSize * 2;
140150

141151
// Start the data transfer.
142-
am_hal_pdm_enable(_PDMhandle);
152+
am_hal_pdm_enable(pdm_handle);
143153
am_util_delay_ms(100);
144-
am_hal_pdm_fifo_flush(_PDMhandle);
145-
am_hal_pdm_dma_start(_PDMhandle, &sTransfer);
154+
am_hal_pdm_fifo_flush(pdm_handle);
155+
am_hal_pdm_dma_start(pdm_handle, &sTransfer);
156+
157+
Serial.println("dma transfer started");
158+
Serial.println(retval);
146159

147160
return retval;
148161
}
@@ -230,9 +243,9 @@ uint32_t AP3_PDM::getDecimationRate()
230243
bool AP3_PDM::updateConfig(am_hal_pdm_config_t newConfiguration)
231244
{
232245
_PDMconfig = newConfiguration;
233-
uint32_t retval = (uint32_t)am_hal_pdm_configure(_PDMhandle, &_PDMconfig);
246+
uint32_t retval = (uint32_t)am_hal_pdm_configure(pdm_handle, &_PDMconfig);
234247

235-
am_hal_pdm_enable(_PDMhandle); //Reenable after changes
248+
am_hal_pdm_enable(pdm_handle); //Reenable after changes
236249

237250
if (retval != AP3_OK)
238251
{
@@ -322,14 +335,8 @@ uint32_t AP3_PDM::getData(uint16_t *externalBuffer, uint32_t externalBufferSize)
322335
return (externalBufferSize);
323336
}
324337

325-
inline void AP3_PDM::pdm_isr(void)
338+
inline void AP3_PDM::pdm_isr(uint32_t ui32Status)
326339
{
327-
uint32_t ui32Status;
328-
329-
// Read the interrupt status.
330-
am_hal_pdm_interrupt_status_get(_PDMhandle, &ui32Status, true);
331-
am_hal_pdm_interrupt_clear(_PDMhandle, ui32Status);
332-
333340
if (ui32Status & AM_HAL_PDM_INT_DCMP)
334341
{
335342
uint32_t tempReadAmt = _pdmBufferSize;
@@ -389,7 +396,7 @@ inline void AP3_PDM::pdm_isr(void)
389396
}
390397

391398
//Start next conversion
392-
am_hal_pdm_dma_start(_PDMhandle, &sTransfer);
399+
am_hal_pdm_dma_start(pdm_handle, &sTransfer);
393400
}
394401
}
395402

@@ -400,5 +407,12 @@ inline void AP3_PDM::pdm_isr(void)
400407
//*****************************************************************************
401408
extern "C" void am_pdm_isr(void)
402409
{
403-
ap3_pdm_handle->pdm_isr();
410+
uint32_t ui32Status;
411+
// Read the interrupt status.
412+
am_hal_pdm_interrupt_status_get(pdm_handle, &ui32Status, true);
413+
am_hal_pdm_interrupt_clear(pdm_handle, ui32Status);
414+
415+
if(ap3_pdm_handle){
416+
ap3_pdm_handle->pdm_isr(ui32Status);
417+
}
404418
}

libraries/PDM/src/PDM.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ class AP3_PDM
117117

118118
uint32_t getData(uint16_t *externalBuffer, uint32_t bufferSize);
119119

120-
void pdm_isr(void);
120+
void pdm_isr(uint32_t ui32Status);
121121

122122
private:
123-
void *_PDMhandle;
124123
am_hal_pdm_config_t _PDMconfig;
125124
pin_size_t _pinPDMData;
126125
pin_size_t _pinPDMClock;

platform.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defines.arduino=-DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUIN
1313
defines.mbed=-DMBED_NO_GLOBAL_USING_DIRECTIVE
1414
defines.variant={build.defines}
1515
defines.extra=
16-
defines.all={defines.variant} {defines.arduino} {defines.mbed} {defines.extra} -DCORDIO_ZERO_COPY_HCI
16+
defines.all={defines.variant} {defines.arduino} {defines.mbed} {defines.extra} -DCORDIO_ZERO_COPY_HCI -DARM_MATH_CM4
1717
defines.preproc={defines.all}
1818
defines.asm={defines.all} @{build.variant.path}/mbed/.asm-symbols
1919
defines.c={defines.all} @{build.variant.path}/mbed/.c-symbols
@@ -29,7 +29,7 @@ includes.all={includes.core} {includes.mbed} {includes.variant} {includes.extra}
2929

3030
# libraries
3131
libs.core=-Wl,--whole-archive {archive_file_path} -Wl,--no-whole-archive
32-
libs.mbed={build.variant.path}/mbed/libmbed-os.a
32+
libs.mbed={build.variant.path}/mbed/libmbed-os.a {build.variant.path}/lib/libarm_cortexM4l_math.a
3333
libs.variant={build.libs}
3434
libs.extra=
3535
libs.all={libs.core} {libs.mbed} {libs.variant} {libs.extra}
@@ -42,11 +42,12 @@ compiler.warning_flags.more={compiler.warning_flags.default}
4242
compiler.warning_flags.all={compiler.warning_flags.default} -Wextra
4343

4444
# flags
45+
compiler.c_cxx_ld_common.flags=-mfloat-abi=softfp
4546
compiler.preproc.flags={compiler.cxx.flags} -w -x c++ -E -CC {compiler.preproc.extra_flags}
4647
compiler.asm.flags=-include {build.variant.path}/mbed/mbed_config.h -iprefix{runtime.platform.path}/cores/ @{build.variant.path}/mbed/.asm-flags {compiler.asm.extra_flags}
47-
compiler.c.flags=-iprefix{runtime.platform.path}/cores/ @{build.variant.path}/mbed/.c-flags {compiler.c.extra_flags}
48-
compiler.cxx.flags=-include {build.variant.path}/mbed/mbed_config.h -include {cores.path}/arduino/sdk/ArduinoSDK.h -iprefix{runtime.platform.path}/cores/ @{build.variant.path}/mbed/.cxx-flags {compiler.cxx.extra_flags}
49-
compiler.ld.flags=@{build.variant.path}/mbed/.ld-flags {compiler.ld.extra_flags} --specs=nano.specs -lsupc++ -lstdc++ -lm
48+
compiler.c.flags=-iprefix{runtime.platform.path}/cores/ @{build.variant.path}/mbed/.c-flags {compiler.c_cxx_ld_common.flags} {compiler.c.extra_flags}
49+
compiler.cxx.flags=-include {build.variant.path}/mbed/mbed_config.h -include {cores.path}/arduino/sdk/ArduinoSDK.h -iprefix{runtime.platform.path}/cores/ @{build.variant.path}/mbed/.cxx-flags {compiler.c_cxx_ld_common.flags} {compiler.cxx.extra_flags}
50+
compiler.ld.flags=@{build.variant.path}/mbed/.ld-flags {compiler.c_cxx_ld_common.flags} {compiler.ld.extra_flags} --specs=nano.specs -lsupc++ -lstdc++ -lm
5051
compiler.ar.flags=rcsP {compiler.ar.extra_flags} {compiler.ar.extra_flags}
5152
compiler.axf2bin.flags={compiler.axf2bin.extra_flags} {compiler.axf2bin.extra_flags} -O binary
5253
compiler.axf2hex.flags={compiler.axf2hex.extra_flags} {compiler.axf2hex.extra_flags} -O ihex
5.18 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5.18 MB
Binary file not shown.
5.18 MB
Binary file not shown.

0 commit comments

Comments
 (0)