Skip to content

Fix nRF52 race condition / hard lock - #857

Merged
focalintent merged 3 commits into
FastLED:masterfrom
henrygab:MinFix840
Aug 13, 2019
Merged

focalintent merged 3 commits into
FastLED:masterfrom
henrygab:MinFix840

Conversation

@henrygab

@henrygab henrygab commented Aug 6, 2019

Copy link
Copy Markdown
Contributor

Fixes #840.

A textbook case of where `volatile` is necessary

The variable s_SequenceBufferInUse is modified in an ISR.
However, the variable was not marked volatile:

virtual void showPixels(PixelController<_RGB_ORDER> & pixels) {
    while (s_SequenceBufferInUse != 0);

Because it wasn't marked volatile, the compiler was allowed to use the first value it read. Using compiler explorer set to ARM gcc 7.2.1 (none) with optimizations (e.g., -O5), you would get something similar to:

.L10
        .word .LANCHOR0 // address of .LC0
        .word .LC0             // s_SequenceBufferInUse
showPixels():
        ldr     r3, .L10
        ldr     r3, [r3]
        cmp     r3, #0
        beq     .L6
.L7:
        b       .L7 // Note this doesn't re-read the value.....
.L6:
        // remainder of function

@henrygab henrygab changed the title Fix race condition / add textbook use of 'volatile' Fix nRF52 race condition Aug 6, 2019
@henrygab henrygab changed the title Fix nRF52 race condition Fix nRF52 race condition / hard lock Aug 6, 2019
@henrygab

henrygab commented Aug 6, 2019

Copy link
Copy Markdown
Contributor Author

@focalintent
focalintent merged commit 535188d into FastLED:master Aug 13, 2019
@henrygab
henrygab deleted the MinFix840 branch August 13, 2019 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SparkFun Pro nRF52840 Mini + Neopixels locking up when calling FastLED.show() too quickly

2 participants