Hi Will, hi Chris,

thanks for your hints. I thought it would be less risky only to reduce the 
counts and not the size of the buffers.

I tweaked a bit with the values of MSYS_1 and found this is working for my 
current app:
    MSYS_1_BLOCK_COUNT: 10  # was 12
    MSYS_1_BLOCK_SIZE: 180 # was 292

If I make BLOCK_SIZE smaller, taskstat and some other stats will still work, 
but mpstat not:
It’s no longer Error 2, but:
Error: NMP timeout; op=0 group=0 id=3 seq=66 peer=bledefs.BleDev{AddrType:0, 
Addr:bledefs.BleAddr{Bytes:[6]uint8{0xc, 0xa, 0xa, 0xa, 0xa, 0xa}}}

If MSYS_1_BLOCK_COUNT < 10, mpstat also no longer works.

All stat requests work with this 10x180 setting, except "stat att“.
But that doesn’t matter for me.

@Will regarding the stats, logging, …
I’m a freelancer since 30 years and had a look at mbed, riot, zephyr and mynewt 
- Mynewt impressed me most.
I hope it will follow the footsteps of other great apache projects, like http 
webserver, tomcat, Felix, ant, maven, wicket, cordova... 


BTW:
every now and then I get this timeout error:

newtmgr -c ble0c stat ble_gattc
Error: Timeout waiting for host <-> controller sync

I’m using a microbit running the blehci, connected via adafruit FT232H with 
rts/cts.

As an alternative, I tried to use the blehostd on a Raspberry Pi zero W with 
these settings:

syscfg.vals:
    OS_MAIN_TASK_PRIO: 1

    # Disable logging.  Writing lots of log output to the UART seems to cause
    # the uart poller task to starve the system in some environemnts.
    LOG_LEVEL: 255

    # We're running in sim; it's OK to over-allocate.
    MSYS_1_BLOCK_COUNT: 1000
    BLE_ACL_BUF_COUNT: 1000
    BLE_HCI_EVT_HI_BUF_COUNT: 1000
    BLE_HCI_EVT_LO_BUF_COUNT: 1000
    BLE_HCI_ACL_OUT_COUNT: 1000
    BLE_MAX_CONNECTIONS: 64

    # More stability; less correctness.  This is a long-running process.
    MCU_NATIVE_USE_SIGNALS: 0
    BLE_SOCK_USE_LINUX_BLUE: 1
    BLE_SOCK_USE_TCP: 0
    BLE_SOCK_LINUX_DEV: 0

But it didn’t work:
pi@pizero:~/dev/mynewt/core-fork/apps/blehostd $ newtmgr -c ble0c echo ok
Error: blehostd did not connect to socket; controller not attached?

newtmgr conn show ble0c
Connection profiles: 
  ble0c: type=ble, 
connstring='own_addr_type=random,peer_addr_type=public,peer_addr=0C:0A:0A:0A:0A:0A,bhd_path=blehostd.elf,ctlr_path=notused'

I tried with hci0 up or down, bluez stopped or running

Another bluetooth-tool is working fine on this raspi:
pi@pizero:~/dev/go/src/github.com/paypal/gatt $ ./discoverer 
2017/06/16 19:46:29 dev: hci0 up
2017/06/16 19:46:29 dev: hci0 reset
2017/06/16 19:46:29 dev: hci0 down
2017/06/16 19:46:29 dev: hci0 opened
State: PoweredOn
scanning...

Peripheral ID:0C:0A:0A:0A:0A:0A, NAME:(master-bleprph)
  Local Name        = master-bleprph
…

Any hints, what typically goes wrong with this configuration?

Regards
Alfred



> Am 16.06.2017 um 21:08 schrieb will sanfilippo <wi...@runtime.io>:
> 
> Alfred:
> 
> Another thing with the nimble stack. The mbuf block size of 292, which Chris 
> shows reduced to 200, is much larger than it needs to be. I am not sure what 
> the smallest size actually is, but you can set it to 100 bytes and it should 
> work. This can get you more buffers and/or reduce your memory usage quite a 
> bit. The amount of buffers you actually need is quite application dependent 
> and generally requires some experimentation unfortunately.
> 
> And thanks for the kind words regarding the stats, logging and image update 
> functionality. We appreciate it!
> 
>> On Jun 16, 2017, at 10:39 AM, Christopher Collins <ch...@runtime.io> wrote:
>> 
>> Hi Alfred,
>> 
>> On Fri, Jun 16, 2017 at 07:02:47PM +0200, Alfred Schilken wrote:
>>> Hello all, I’m experimenting with mynewt for several weeks now and I’m 
>>> especially impressed by the statistics, logging and image update 
>>> functionality.
>>> I’m having problems with getting all the statistics using newtmgr via BLE.
>>> 
>>> I  took bleprph as base, added ADC and enabled several stats, logs and so 
>>> on.
>>> To reduce flash size I had to switch off debug and reduce the logging.
>>> 
>>> When I started the program I got an Assert-reboot-loop.
>>> The target board is a bbc microbit.
>>> 
>>> This seems to be cause of the error:
>>> ble_att_svr_entry_mem = malloc(
>>>   OS_MEMPOOL_BYTES(ble_hs_max_attrs, sizeof (struct ble_att_svr_entry)));
>>> if (ble_att_svr_entry_mem == NULL) {
>>>   rc = BLE_HS_ENOMEM;
>>>   goto err;
>>> }
>> 
>> Fitting BLE and newtmgr into 16kB requires some creativity :).  There
>> are certainly some memory and mbuf optimizations that could be made, we
>> just need to go through the exercise of scouring the code.
>> 
>>> I tweaked these four config values to fix the crash-loop.
>>> BLE_ACL_BUF_COUNT: 4    # was 4
>>> BLE_ACL_BUF_SIZE: 128  # was 255
>>> MSYS_1_BLOCK_COUNT: 4  # was 12
>>> MSYS_1_BLOCK_SIZE: 292 # was 292
>>> 
>>> The program boots now, I can see and connect to the BLE services and all 
>>> this is fine.
>>> 
>>> If I use newtmgr via ble transport to read the statistics, some of them are 
>>> responding, others return just Error: 2.
>>> mpstat and taskstat also don’t work.
>>> But „image list“ is working, I could even upload a new image.
>>> 
>>> 
>>> My question is:
>>> What are the best config settings to reduce ram usage, so that an app runs 
>>> in 16 kb with least impact on functionality? 
>> 
>> I was able to get mpstats working on a 16kB device with the following
>> mbuf settings:
>> 
>>   MSYS_1_BLOCK_COUNT: 11
>>   MSYS_1_BLOCK_SIZE: 200
>> 
>>> Some hints to reduce flash size would also be appreciated :-) 
>> 
>> You might want to look into the split image functionality:
>> https://mynewt.apache.org/latest/os/modules/split/split.  This allows
>> you dedicate more flash space to your application code.  I don't think
>> this will help with your immediates issues, however, since BLE and
>> newtmgr would both need to go into the loader image.
>> 
>> Chris
> 

Reply via email to