8000 BLE: crash after running gc.collect() · Issue #5226 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
8000

BLE: crash after running gc.collect() #5226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dpgeorge opened this issue Oct 18, 2019 · 2 comments · Fixed by #5240
Closed

BLE: crash after running gc.collect() #5226

dpgeorge opened this issue Oct 18, 2019 · 2 comments · Fixed by #5240
Labels
bug extmod Relates to extmod/ directory in source

Comments

@dpgeorge
Copy link
Member

Issue split off from #5171 (comment)


I did find however, that the garbage collection is deleting something important to do with BLE. This bug can be replicated by using the snippet sample above by @HexVitor [see below] and using the following steps:

  1. Establish a BLE connection using something like Serial Bluetooth Terminal on Android
  2. Send a couple of test messages successfully from Serial Bluetooth Terminal
  3. Type gc.collect() at the REPL
  4. Try to send a few more messages and you should eventually see something like the following...
Guru Meditation Error: Core  0 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x3ffe67b0  PS      : 0x00060530  A0      : 0x80148fdc  A1      : 0x3ffbb4a0  
A2      : 0x3ffc5cbc  A3      : 0x00000010  A4      : 0x00000000  A5      : 0x3ffbb4e0  
A6      : 0x3ffc80ec  A7      : 0x3ffe67b0  A8      : 0x80148fa1  A9      : 0x00000000  
A10     : 0x00000000  A11     : 0x00000010  A12     : 0x3ffbb4e0  A13     : 0x00000002  
A14     : 0x0000cdcd  A15     : 0x00000001  SAR     : 0x00000018  EXCCAUSE: 0x00000014  
EXCVADDR: 0x3ffe67b0  LBEG    : 0x4014d139  LEND    : 0x4014d144  LCOUNT  : 0x00000009  

ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000

Backtrace: 0x3ffe67ad:0x3ffbb4a0 |<-CORRUPTED

Code:

# Import of modules and classes
import bluetooth

# Configuration
ble = bluetooth.BLE()
ble.active(True)

# Event Handling
def ble_irq(event, data):
    # print received data
    print(ble.gatts_read(rx))
        
ble.irq(ble_irq)

# GATT Server
UART_UUID = bluetooth.UUID('6E400001-B5A3-F393-E0A9-E50E24DCCA9E')
UART_TX = (bluetooth.UUID('6E400003-B5A3-F393-E0A9-E50E24DCCA9E'), bluetooth.FLAG_READ | bluetooth.FLAG_NOTIFY,)
UART_RX = (bluetooth.UUID('6E400002-B5A3-F393-E0A9-E50E24DCCA9E'), bluetooth.FLAG_WRITE,)
UART_SERVICE = (UART_UUID, (UART_TX, UART_RX,),)
SERVICES = (UART_SERVICE,)
((tx, rx,), ) = ble.gatts_register_services(SERVICES)

# Advertiser
def adv_encode_name(name):
    name = bytes(name, 'ascii')
    return bytearray((len(name) + 1, 0x09)) + name

ble.gap_advertise(100, bytearray('\x02\x01\x02') + adv_encode_name('ESP32'))
@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Oct 18, 2019
@jimmo
Copy link
Member
jimmo commented Oct 21, 2019

Thanks for the report @sunbeamer !

I can reproduce this on ESP32 but (so far) not on PYBD. Will investigate and get back to you.

@sunbeamer
Copy link

Thanks for the quick fix @jimmo !

I have tested your fix, both using the steps to reproduce the bug I outlined above, as well as in my own application code that first highlighted the bug and all works OK.

@dpgeorge dpgeorge added the bug label Oct 22, 2019
alu96 pushed a commit to alu96/micropython that referenced this issue Mar 23, 2020
NimBLE doesn't actually copy this data, it requires it to stay live.
Only dereference when we register a new set of services.

Fixes micropython#5226

This will allow incrementally adding services in the future, so
rename `reset` to `append` to make it clearer.
c0d3z3r0 pushed a commit to c0d3z3r0/micropython that referenced this issue Apr 5, 2020
NimBLE doesn't actually copy this data, it requires it to stay live.
Only dereference when we register a new set of services.

Fixes micropython#5226

This will allow incrementally adding services in the future, so
rename `reset` to `append` to make it clearer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0