h2zero / n-able-Arduino

An arduino core for ARM based BLE devices supported by the NimBLE stack.
GNU Lesser General Public License v2.1
36 stars 15 forks source link

Add support for nRF52810 #46

Closed positron96 closed 5 months ago

positron96 commented 5 months ago

Fixes #45 Uses info from #17 Also needs patch to PlatformIO python script (it adds FPU compiler flags), see https://github.com/h2zero/platform-n-able/pull/1

I was able to compile blink and basic BLE example (BLE-server-test).

Here are some comparisons with other cores (neither work without modifications):

blink: n-able:

RAM:   [==        ]  20.3% (used 4988 bytes from 24576 bytes)
Flash: [=         ]   9.1% (used 17896 bytes from 196608 bytes)

zephyr (probably contains BLE stack, as numbers are not much different from below):

RAM:   [======    ]  60.1% (used 14778 bytes from 24576 bytes)
Flash: [===       ]  31.1% (used 61228 bytes from 196608 bytes)

official PlatformIO RF52 core (no RTOS gives you these numbers, yes):

RAM:   [          ]   0.6% (used 140 bytes from 24576 bytes)
Flash: [          ]   1.1% (used 2156 bytes from 196608 bytes)

basic BLE example The examples are different for each core, BLE beacon in zephyr, BLE-controlled LED in RF52, BLE-server-test for n-able. Though I don't expect much different resources requirements.

n-able:

RAM:   [========  ]  77.3% (used 19004 bytes from 24576 bytes)
Flash: [======    ]  62.6% (used 123080 bytes from 196608 bytes)

zephyr:

RAM:   [======    ]  63.6% (used 15628 bytes from 24576 bytes)
Flash: [===       ]  33.2% (used 65308 bytes from 196608 bytes)

RF52 (need to add softdevice size, 114kb flash + 8kb RAM):

RAM:   [          ]   4.4% (used 1076 bytes from 24576 bytes)
Flash: [=         ]   8.2% (used 16120 bytes from 196608 bytes)

I'd be fine with n-able using 62% of flash (there is still plenty left), but I am concerned that it uses 77% or RAM, leaving like 5Kb for all my code. Is there anything I can tweak to reduce RAM usage?

h2zero commented 5 months ago

Great work so far, there are some tweaks that need to be made to the linker file to reduce the ram use as they all have been modified for use here.

h2zero commented 5 months ago

@positron96 I've pushed a few changes to the config and startup scripts, please test them and let me know how it works out.

positron96 commented 5 months ago

@positron96 I've pushed a few changes to the config and startup scripts, please test them and let me know how it works out.

Thanks! With new changes, the same BLE-server is this:

RAM:   [=======   ]  66.5% (used 16348 bytes from 24576 bytes)

I'll test on the MCU later.

h2zero commented 5 months ago

@positron96 I changed the linker script so there is some defined space for data storage and added the board as a generic. Could you have a look at the board config and let me know if anything is incorrect?

positron96 commented 5 months ago

I don't have Arduino IDE, only PlatformIO, I think it doesn't use boards file. It looks good, except maximum upload size should be 196608

positron96 commented 5 months ago

I thought that since in terms of RAM nRF52810 is closer to nrf51 than to nRF52832, it's better to take some settings from that definition. So I set MYNEWT_VAL_MSYS_1_BLOCK_SIZE to 88 (instead of 292) to save a Kb or two. Could you tell me what MSYS refers to actually?

h2zero commented 5 months ago

The max upload needs to be adjusted lower because the bond storage and user data storage each need 2 pages of flash.

Yes the nRF51 settings are memory optimal, you'll need to adjust the settings for your application, like main task stack size, disabling ble roles etc.

The msys is the internal memory system used by NimBLE, mainly for long reads and writes and scan results.

h2zero commented 5 months ago

We should add a board to the platform as well

positron96 commented 5 months ago

We should add a board to the platform as well

Done in https://github.com/h2zero/platform-n-able/pull/1

h2zero commented 5 months ago

LGTM, let me know when you are done testing/ready for this to be merged please.

positron96 commented 5 months ago

Well, I've been using it for a week and it's working well for me.

h2zero commented 5 months ago

Awesome, thanks!