Skip to content

Commit

Permalink
added discription to current settings in README-STACK.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wowa committed Jun 1, 2018
1 parent ade3b03 commit 6952b3f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 25 deletions.
70 changes: 68 additions & 2 deletions README-STACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ which can be used to modify the stack and the heap from outside this function.
One option to do so, is to extend the file [toolchain.cmake](yotta_targets/calliope-mini-classic-gcc/CMake/toolchain.cmake). Add `-D__STACK_SIZE=2632 -D__HEAP_SIZE=1464` at the end of `add_definitions("...`
and the stack will have the size of 2632 Bytes and the heap will have the size of 1464 Bytes.

### 1.2: Adding defines.json
### 1.2: Adding defines.json
The alternative option is to add a [defines.json](defines.json) file to the same directory, where [module.json](module.json) is located.
Therein macro definitions can be added for the application. In this case the file would look like this:
```[bash]
Expand All @@ -25,7 +25,73 @@ Therein macro definitions can be added for the application. In this case the fil
The advantage of this option is, that you do not have to modify any dependencies, but can add extra definitions to the application.
The disadvantage is, that these definitions will apply to all application code, which can lead multiple definitions.

**NOTE: The size of Stack + Heap has to be 4096 Bytes or less**
**NOTE: The size of Stack + Heap has to fit into the RAM**

#### 1.2.1 How much space for Heap and Stack is in the RAM

To find out how much space is in the RAM, you have to read the [calliope-demo.elf](build/calliope-mini-classic-gcc/source/calliope-demo)
file. Therefore enter the following command in the terminal:
```[bash]
$ readelf -S calliope-demo
```
The output will look like this:
```[bash]
There are 22 section headers, starting at offset 0x326b10:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 00018000 008000 016494 00 AX 0 0 8
[ 2] .ARM.exidx ARM_EXIDX 0002e494 01e494 000008 00 AL 1 0 4
[ 3] .data PROGBITS 20002000 022000 0000fc 00 WA 0 0 4
[ 4] .bss NOBITS 20002100 022100 000a20 00 WA 0 0 8
[ 5] .heap PROGBITS 20002b20 022100 000acc 00 0 0 8
[ 6] .stack_dummy PROGBITS 20002b20 022bd0 000a00 00 0 0 8
[ 7] .ARM.attributes ARM_ATTRIBUTES 00000000 0235d0 000028 00 0 0 1
[ 8] .comment PROGBITS 00000000 0235f8 00007e 01 MS 0 0 1
[ 9] .debug_info PROGBITS 00000000 023676 220d76 00 0 0 1
[10] .debug_abbrev PROGBITS 00000000 2443ec 028b2e 00 0 0 1
[11] .debug_loc PROGBITS 00000000 26cf1a 02800e 00 0 0 1
[12] .debug_aranges PROGBITS 00000000 294f28 003268 00 0 0 8
[13] .debug_ranges PROGBITS 00000000 298190 006958 00 0 0 1
[14] .debug_line PROGBITS 00000000 29eae8 035e48 00 0 0 1
[15] .debug_str PROGBITS 00000000 2d4930 02f121 01 MS 0 0 1
[16] .debug_frame PROGBITS 00000000 303a54 009790 00 0 0 4
[17] .stab PROGBITS 00000000 30d1e4 00003c 0c 18 0 4
[18] .stabstr STRTAB 00000000 30d220 000076 00 0 0 1
[19] .symtab SYMTAB 00000000 30d298 00dac0 10 20 2352 4
[20] .strtab STRTAB 00000000 31ad58 00bcde 00 0 0 1
[21] .shstrtab STRTAB 00000000 326a36 0000d8 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
```
The important number here is at `[ 5] .heap PROGBITS 20002b20`,
which is the hexadecimal address = **0x2002b20** where the **Heap starts**. Since the **Stack ends** at the address **0x20004000**,
the space in beetween can be used for Heap and Stack and defined in [defines.json](defines.json) and [config.json](config.json)

**Important for config.json:**
The following settings have to be set:


```[bash]
{
...
"debug": 0,
"heap_debug": 0,
"reuse_sd": 0,
"heap_allocator": 0,
"stack_size": 2560,
}
}
```
where `stack_size` has to be the same as `__STACK_SIZE`




# !!!DEPRECATED!!!

## 2: MicroBit custom heap configuration
Since the [microbit-dal](yotta_modules/microbit-dal)
Expand Down
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"event_service": 0,
"device_info_service": 1
},
"gatt_table_size": "0x300",
"gatt_table_size": "0x600",
"debug": 0,
"heap_debug": 0,
"reuse_sd": 0,
Expand All @@ -30,7 +30,7 @@
"display_scroll_stride": -1,
"display_print_speed": 400,
"panic_on_heap_full": 0,
"stack_size": 2672,
"stack_size": 2560,
"sram_base": "0x20000008",
"sram_end": "0x20004000",
"sd_limit": "0x20002000"
Expand Down
4 changes: 2 additions & 2 deletions defines.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"__STACK_SIZE": 2672,
"__HEAP_SIZE": 2672
"__STACK_SIZE": 2560,
"__HEAP_SIZE": 2764
}
16 changes: 6 additions & 10 deletions source/BluetoothServiceNotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ static const uint8_t BluetoothServiceNotifyUUID[] = {
0xa0,0x62,
0xfa,0x19,0x22,0xdf,0xa9,0xa8
};
extern const uint8_t BluetoothServiceProgramUUID[];

BluetoothServiceNotify::BluetoothServiceNotify(Interpreter &_interpreter) :
interpreter(_interpreter),
Expand All @@ -26,7 +25,7 @@ BluetoothServiceNotify::BluetoothServiceNotify(Interpreter &_interpreter) :
),
characteristicsBuffer()
{
characteristic.requireSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK);//MICROBIT_BLE_SECURITY_LEVEL);
characteristic.requireSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK);
characteristic.setReadAuthorizationCallback(this, &BluetoothServiceNotify::onDataRead);

GattCharacteristic *characteristics[] = {
Expand All @@ -47,27 +46,24 @@ BluetoothServiceNotify::BluetoothServiceNotify(Interpreter &_interpreter) :
ManagedString namePrefix("BBC micro:bit [");
#endif
ManagedString namePostfix("]");

// this->deviceName = microbit_friendly_name();
ManagedString BLEName = namePrefix + microbit_friendly_name() + namePostfix;


// // Update the advertised name of this micro:bit to include the device name
// Update the advertised name of this micro:bit to include the device name
ble.clearAdvertisingPayload();

ble.accumulateAdvertisingPayload(
GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *) BLEName.toCharArray(),
BLEName.length());

ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, BluetoothServiceNotifyUUID,
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
BluetoothServiceNotifyUUID,
16);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, BluetoothServiceProgramUUID,
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
BluetoothServiceProgramUUID,
16);

ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.setAdvertisingInterval(200);

ble.setAdvertisingTimeout(0);
ble.startAdvertising();

Expand Down
9 changes: 0 additions & 9 deletions source/BluetoothServiceProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@

extern MicroBit uBit;

//static const uint8_t BluetoothServiceProgramUUID[] = {
// 0xff,0x66,0xdd,0xee,
// 0x25,0x1d,
// 0x47,0x0a,
// 0xa0,0x62,
// 0xfa,0x19,0x22,0xdf,0xa9,0xa8
//};


BluetoothServiceProgram::BluetoothServiceProgram(Interpreter &_interpreter) :
interpreter(_interpreter),
ble(*uBit.ble),
Expand Down

0 comments on commit 6952b3f

Please sign in to comment.