Thanks to visit codestin.com
Credit goes to github.com

Skip to content

windows/bluetooth: Add support for nimble BLE to windows port. #7781

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

@andrewleech andrewleech commented Sep 13, 2021

This was developed in conjunction with #7780 to provide support for nimble BLE on windows to the unix port.

This allows a usb/serial HCI controller to be used on windows to test and run bluetooth micropython code.

This has only been added to minwg / make based builds at this stage. The MSVC project has not been updated to match.
I suspect nimble builds may not be possible with MSVC due to a struct size issue that took quite a long time to debug.

Nimble uses struct size to test whether the correct HCI packet has been received, eg.

struct ble_hci_ev_command_complete {
    uint8_t  num_packets;
    uint16_t opcode;
    uint8_t  status;
    uint8_t  return_params[0];
} __attribute__((packed));

...

ble_hs_hci_rx_cmd_complete(const void *data, int len,
                           struct ble_hs_hci_ack *out_ack)
{
    const struct ble_hci_ev_command_complete *ev = data;
    const struct ble_hci_ev_command_complete_nop *nop = data;
    uint16_t opcode;

    if (len < sizeof(*ev)) {
        if (len < sizeof(*nop)) {
            return BLE_HS_ECONTROLLER;
        }
...

On linux/unix/arm builds sizeof(struct ble_hci_ev_command_complete) == 4 as the uint8_t return_params[0]; is essentially ignored.

On MSVC apparently this null array is apparently included as size 1, eg. sizeof(struct ble_hci_ev_command_complete) == 5 - and by default mingw matches MSVC behavior on this. This was causing the code above to return BLE_HS_ECONTROLLER error instead of correctly processing the hci packet.

I had to add the compiler flag -mno-ms-bitfields to make mingw match "regular" gcc behavior - I don't know if a similar compile flag exists to make MSVC match gcc packed struct size - let alone whether the rest of the nimble codebase is at all compilable under msvc.

@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2021

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (2dada06) to head (25c277d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7781   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21898    21898           
=======================================
  Hits        21579    21579           
  Misses        319      319           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@projectgus
Copy link
Contributor

This is an automated heads-up that we've just merged a Pull Request
that removes the STATIC macro from MicroPython's C API.

See #13763

A search suggests this PR might apply the STATIC macro to some C code. If it
does, then next time you rebase the PR (or merge from master) then you should
please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if
you have any questions about this.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants