Skip to content

AMY ouputs buffers filled with zeros when compiled with -Ofast #553

@jgartrel

Description

@jgartrel

Issue Summary

Hi all, I think I need some help.

AMY ouputs buffers appear to be filled with zeros when compiled with -Ofast. This creates an issue that is very difficult to debug and is very likely to be seen given that -Ofast is the default for most nRF52 cores. This is because most nRF52 Arduino cores are derived (ultimately) from Adafruit_nRF52_Arduino which at one point decided to use -Ofast.

This sample sketch should duplicate the issue:
https://github.com/jgartrel/amy_synth_nrf52_example/blob/ca18f3237e5c36fa2bd9464379ee585127af28a0

Output should contain viable audio; however, when compiled with -Ofast all of the output buffers are filled with only zeros. In the sample sketch, a counter for I2S write zeros is incremented when a buffer is completely filled with zeros.

Output when compiled with -Ofast (see full output attached further below):

I2S write count : 489     # This is how many times amy_i2s_write() was called
I2S write bytes : 500736  # This is how many bytes were transferred to amy_i2s_write()
I2S write zeros : 489     # This is count of buffers received by amy_i2s_write() that were completely filled with zeros
Amy task count  : 489     # This is how many times amy_update() was called

Output when compiled with -O3 (see full output attached further below):

I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 0       # This means NO buffers were filled with zeros (good!)
Amy task count  : 489

In the -O3 example you can see that NO buffers passed to amy_i2s_write() were filled with zeros (as it should be). I'm not sure where the issue is coming from, but I do suspect that the oscillators are not getting initialized properly leaving them deactivated.

Ultimately, I will probably use the -O3 compilation option, but I think we should have a better understanding of what is going on here, given that anyone who uses this on an nRF52 board will likely stumble over this same issue.


Duplicating the issue

This sample sketch should duplicate the issue. An I2S board is not really required given that the sample sketch analyzes the buffer output from AMY directly. In fact, all of the I2S code could be stripped out and replaced with a simple timer to greatly simplify the sketch if necessary.

I recommend following the README.md instructions included in that repo to setup the appropriate tool chain and cores to make it work properly. Those instructions detail the use of the included Makefile. Obviously you can setup your Arduino environment with the GUI, but this example provides an isolated toolchain and libraries to better duplicate the example.

Changing compile options can done easily by editing the included hardware/shorepine/nrf52/platform.txt file and uncommenting the required line.

make distclean followed by a make all can be useful if you run into caching issues where a previous compiled version of the core is still being used. Use caution though, make distclean will clean out ALL files from the directory that are not checked into git.

So far I have duplicated it on the Seeeduino XIAO nRF52840 Plus, the Nordic nRF52840-DK, and my own nRF52840 based board. I have not tested it on the ProMicro nRF52840, but I will do so as soon as I can get my hands on it. I am sure that you will be able to duplicate it on the ProMicro nRF52840.

Feel free to reach out if you have any questions


Full console output from test sessions

  1. Full Serial output using -Ofast:
$ make monitor
Monitor using port: /dev/cu.usbmodem2101
Using default monitor configuration for board: shorepine:nrf52:xiaonRF52840Plus
Monitor port settings:
  baudrate=9600
  bits=8
  dtr=on
  parity=none
  rts=on
  stop_bits=1

Connecting to /dev/cu.usbmodem2101. Press CTRL-C to exit.
Board ID       : 0x817CCCA36A473E6C1D675EEAEF788915
T - Loop
 ______________________________________________
| Name | Addr 0x2000xxxx | Usage               |
| ---------------------------------------------|
| Stack| 0xF800 - 0xFFFF |   760 /  2048 (37%) |
| Heap | 0xA390 - 0xF7FF | 17236 / 218224 (07%) |
| Bss  | 0x6000 - 0xA38F | 17296               |
| SD   | 0x0000 - 0x5FFF | 24576               |
|______________________________________________|

Task    State   Prio  StackLeft Num
-----------------------------------
loop   	X	1	593	1
IDLE   	R	0	25	3
Callbac	B	2	729	2
BLE    	B	3	1195	6
SOC    	B	3	163	7
usbd   	B	3	132	5
Tmr Svc	B	2	218	4

Iteration count : 1
No sequencer support for this chip / platform
Iteration count : 1
Underrun count  : 14
I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 489
Amy task count  : 489
Amy update ema  : 741
Amy update max  : 13672
Event setup     : 116211
Amy sysclock    : 4022
Amy sample rate : 31250
Heap used       : 67548
No sequencer support for this chip / platform
Heap leaked     : 1233
Heap free       : 199755
WARNING Underrun: 14
T - Loop
 ______________________________________________
| Name | Addr 0x2000xxxx | Usage               |
| ---------------------------------------------|
| Stack| 0xF800 - 0xFFFF |   760 /  2048 (37%) |
| Heap | 0xA390 - 0xF7FF | 18469 / 218224 (08%) |
| Bss  | 0x6000 - 0xA38F | 17296               |
| SD   | 0x0000 - 0x5FFF | 24576               |
|______________________________________________|

Task    State   Prio  StackLeft Num
-----------------------------------
loop   	X	1	318	1
IDLE   	R	0	25	3
BLE    	B	3	1195	6
SOC    	B	3	163	7
usbd   	B	3	132	5
Tmr Svc	B	2	218	4
Callbac	B	2	729	2

Iteration count : 2
No sequencer support for this chip / platform
Iteration count : 2
Underrun count  : 14
I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 489
Amy task count  : 489
Amy update ema  : 710
Amy update max  : 13672
Event setup     : 116211
Amy sysclock    : 4022
Amy sample rate : 31250
Heap used       : 67516
No sequencer support for this chip / platform
Heap leaked     : 1200
Heap free       : 198555
WARNING Underrun: 14
T - Loop
 ______________________________________________
| Name | Addr 0x2000xxxx | Usage               |
| ---------------------------------------------|
| Stack| 0xF800 - 0xFFFF |   760 /  2048 (37%) |
| Heap | 0xA390 - 0xF7FF | 19669 / 218224 (09%) |
| Bss  | 0x6000 - 0xA38F | 17296               |
| SD   | 0x0000 - 0x5FFF | 24576               |
|______________________________________________|

Task    State   Prio  StackLeft Num
-----------------------------------
loop   	X	1	294	1
IDLE   	R	0	25	3
SOC    	B	3	163	7
Tmr Svc	B	2	218	4
usbd   	B	3	132	5
Callbac	B	2	729	2
BLE    	B	3	1195	6

Iteration count : 3
No sequencer support for this chip / platform
Iteration count : 3
Underrun count  : 14
I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 489
Amy task count  : 489
Amy update ema  : 710
Amy update max  : 13672
Event setup     : 116211
Amy sysclock    : 4022
Amy sample rate : 31250
Heap used       : 67516
No sequencer support for this chip / platform
Heap leaked     : 1200
Heap free       : 197355
WARNING Underrun: 14
  1. Full Serial output when using -O3:
$ make monitor
Monitor using port: /dev/cu.usbmodem2101
Using default monitor configuration for board: shorepine:nrf52:xiaonRF52840Plus
Monitor port settings:
  baudrate=9600
  bits=8
  dtr=on
  parity=none
  rts=on
  stop_bits=1

Connecting to /dev/cu.usbmodem2101. Press CTRL-C to exit.
Board ID       : 0x817CCCA36A473E6C1D675EEAEF788915
T - Loop
 ______________________________________________
| Name | Addr 0x2000xxxx | Usage               |
| ---------------------------------------------|
| Stack| 0xF800 - 0xFFFF |   688 /  2048 (33%) |
| Heap | 0xA388 - 0xF7FF | 17236 / 218232 (07%) |
| Bss  | 0x6000 - 0xA387 | 17288               |
| SD   | 0x0000 - 0x5FFF | 24576               |
|______________________________________________|

Task    State   Prio  StackLeft Num
-----------------------------------
loop   	X	1	593	1
IDLE   	R	0	25	3
Callbac	B	2	729	2
BLE    	B	3	1195	6
SOC    	B	3	163	7
usbd   	B	3	132	5
Tmr Svc	B	2	218	4

Iteration count : 1
No sequencer support for this chip / platform
Iteration count : 1
Underrun count  : 1
I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 0
Amy task count  : 489
Amy update ema  : 2893
Amy update max  : 4883
Event setup     : 7812
Amy sysclock    : 4022
Amy sample rate : 31250
Heap used       : 66396
No sequencer support for this chip / platform
Heap leaked     : 540
Heap free       : 200456
WARNING Underrun: 1
T - Loop
 ______________________________________________
| Name | Addr 0x2000xxxx | Usage               |
| ---------------------------------------------|
| Stack| 0xF800 - 0xFFFF |   688 /  2048 (33%) |
| Heap | 0xA388 - 0xF7FF | 17776 / 218232 (08%) |
| Bss  | 0x6000 - 0xA387 | 17288               |
| SD   | 0x0000 - 0x5FFF | 24576               |
|______________________________________________|

Task    State   Prio  StackLeft Num
-----------------------------------
loop   	X	1	286	1
IDLE   	R	0	25	3
BLE    	B	3	1195	6
SOC    	B	3	163	7
usbd   	B	3	132	5
Tmr Svc	B	2	218	4
Callbac	B	2	729	2

Iteration count : 2
No sequencer support for this chip / platform
Iteration count : 2
Underrun count  : 1
I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 0
Amy task count  : 489
Amy update ema  : 2892
Amy update max  : 4883
Event setup     : 7813
Amy sysclock    : 4022
Amy sample rate : 31250
Heap used       : 66364
No sequencer support for this chip / platform
Heap leaked     : 508
Heap free       : 199948
WARNING Underrun: 1
T - Loop
 ______________________________________________
| Name | Addr 0x2000xxxx | Usage               |
| ---------------------------------------------|
| Stack| 0xF800 - 0xFFFF |   688 /  2048 (33%) |
| Heap | 0xA388 - 0xF7FF | 18284 / 218232 (08%) |
| Bss  | 0x6000 - 0xA387 | 17288               |
| SD   | 0x0000 - 0x5FFF | 24576               |
|______________________________________________|

Task    State   Prio  StackLeft Num
-----------------------------------
loop   	X	1	286	1
IDLE   	R	0	25	3
SOC    	B	3	163	7
Tmr Svc	B	2	218	4
usbd   	B	3	132	5
Callbac	B	2	729	2
BLE    	B	3	1195	6

Iteration count : 3
No sequencer support for this chip / platform
Iteration count : 3
Underrun count  : 1
I2S write count : 489
I2S write bytes : 500736
I2S write zeros : 0
Amy task count  : 489
Amy update ema  : 2892
Amy update max  : 4883
Event setup     : 7812
Amy sysclock    : 4022
Amy sample rate : 31250
Heap used       : 66364
No sequencer support for this chip / platform
Heap leaked     : 508
Heap free       : 199440
WARNING Underrun: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions