Skip to content

Commit

Permalink
Merge branch 'master' into dev-tdoa2
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Nov 29, 2017
2 parents 7b2cbc0 + 814720f commit 491952b
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 12 deletions.
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Contributing
============

👍🎉 Thanks a lot for considering contributing 🎉👍

We welcome and encourage contribution. There is many way to contribute: you can
write bug report, contribute code or documentation.
You can also go to the [bitcraze forum](https://forum.bitcraze.io) and help others.

## Reporting issues

When reporting issues the more information you can supply the better.

- **Information about the environment:**
- What version of the firmware are you running
- **How to reproduce the issue:** Step-by-step guide on how the issue can be reproduced (or at least how you reproduce it).
Include everything you think might be useful, the more information the better.

## Improvements request and proposal

We and the community are continuously working to improve the firmware.
Feel free to make an issue to request a new functionality.

## Contributing code/Pull-Request

We welcome code contribution, this can be done by starting a pull-request.

If the change is big, typically if the change span to more than one file, consider starting an issue first to discuss the improvement.
This will makes it much easier to make the change fit well into the firmware.

There is some basic requirement for us to merge a pull request:
- Describe the change
- Refer to any issues it effects
- Separate one pull request per functionality: if you start writing "and" in the feature description consider if it could be separated in two pull requests.
- The pull request must pass the automated test (see test section bellow)

In your code:
- 2 spaces indentation
- Make sure the coding style of your code follows the style of the file.

### Run test

In order to run the tests you can run:
```
./tools/build/build
```
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
OPENOCD ?= openocd
OPENOCD_INTERFACE ?= interface/stlink-v2.cfg
REV ?= B
REV ?= B
PYTHON2 ?= python2
# CFLAGS += -fdiagnostics-color=auto
# CFLAGS += -fdiagnostics-color=auto
# CFLAGS += -DUSE_FTDI_UART

BOOTLOAD ?= 0
BOOTLOAD ?= 0

ifeq ($(strip $(REV)),A)
$(error Rev.A not supported anymore)
Expand Down Expand Up @@ -74,12 +74,13 @@ CC=$(PREFIX)gcc
LD=$(PREFIX)gcc
AS=$(PREFIX)as
OBJCOPY=$(PREFIX)objcopy
SIZE=$(PREFIX)size

all: check_submodules bin/lps-node-firmware.elf bin/lps-node-firmware.dfu

bin/lps-node-firmware.elf: $(OBJS)
$(LD) -o $@ $^ $(LDFLAGS)
arm-none-eabi-size $@
$(SIZE) $@
@echo BOOTLOADER Support: $(BOOTLOAD)

clean:
Expand All @@ -96,7 +97,11 @@ openocd:
$(OPENOCD) -d2 -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET) -c init -c targets

dfu:
dfu-util -d 0483:df11 -a 0 -D bin/lps-node-firmware.dfu -R
dfu-util -d 0483:df11 -a 0 -D bin/lps-node-firmware.dfu -s :leave

reset_and_dfu:
tools/make/reset-to-dfu.py
dfu-util -d 0483:df11 -a 0 -D bin/lps-node-firmware.dfu -s :leave

# Generic rules
%.bin: %.elf
Expand Down
24 changes: 24 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void changeMode(unsigned int newMode);
static void printModeList();
static void printMode();
static void help();
static void bootload(void);

static void main_task(void *pvParameters) {
int i;
Expand Down Expand Up @@ -242,6 +243,8 @@ static void handleSerialInput(char ch) {
printf("System halted, reset to continue\r\n");
while(true){}
break;
case 'u':
bootload();
default:
configChanged = false;
break;
Expand Down Expand Up @@ -358,6 +361,7 @@ static void help() {
printf("s - sniffer mode\r\n");
printf("m - List and change mode\r\n");
printf("d - reset configuration\r\n");
printf("u - enter BSL (DFU mode)\r\n");
printf("h - This help\r\n");
printf("---- For machine only\r\n");
printf("b - Switch to binary mode (sniffer only)\r\n");
Expand Down Expand Up @@ -385,6 +389,26 @@ int main() {
return 0;
}

// Enter bootloader from software: Taken from micropython machine_bootloader function
static void bootload(void) {
printf("Entering DFU Mode\r\n");
HAL_Delay(500);

HAL_RCC_DeInit();
HAL_DeInit();

__HAL_REMAPMEMORY_SYSTEMFLASH();

// arm-none-eabi-gcc 4.9.0 does not correctly inline this
// // // MSP function, so we write it out explicitly here.
//__set_MSP(*((uint32_t*) 0x00000000));
__ASM volatile ("movs r3, #0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");

((void (*)(void)) *((uint32_t*) 0x00000004))();

while (1);
}

// Freertos required callbacks
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
Expand Down
24 changes: 24 additions & 0 deletions tools/make/reset-to-dfu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

import serial
import sys
import serial.tools.list_ports
import time

ports = serial.tools.list_ports.comports()
nodes = list(filter(lambda p: p.description == "Loco Positioning Node", ports))

if len(nodes) > 0:
print("Resetting node to DFU ...")
try:
ser = serial.Serial(nodes[0].device)
ser.write(b'u')
ser.close()
time.sleep(2)
except serial.SerialException:
print("Error: Cannot open node serial port!")
sys.exit(1)
sys.exit(0)
else:
print("Cannot find node, already in DFU mode?")
sys.exit(0)
33 changes: 26 additions & 7 deletions tools/sniffer/sniffer_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@
import struct
import serial
import binascii
import yaml

if len(sys.argv) != 2:
print("usage: {} <sniffer serial port>".format(sys.argv[0]))
if len(sys.argv) < 2:
print("usage: {} <sniffer serial port> [format]".format(sys.argv[0]))
print(" Possible format: human (default), csv, yaml")
sys.exit(1)

ser = serial.Serial('/dev/ttyACM0')
ser = serial.Serial(sys.argv[1], 9600)

outputFormat = 'human'
if len(sys.argv) > 2:
outputFormat = sys.argv[2].strip()

# Switch to binary mode
ser.write(b'b')

while True:
c = ser.read(1)

if c == b'\xbc':
ts = ser.read(5)
ts += b'\0\0\0'
Expand All @@ -32,8 +37,22 @@
data = ser.read(length)
l2 = struct.unpack('<H', ser.read(2))[0]
if length == l2:
print("@{:010x} from {} to {}: {}".format(ts, addrFrom, addrTo,
binascii.hexlify(data)
.decode('utf8')))
if outputFormat == 'human':
print("@{:010x} from {} to {}: {}".format(ts, addrFrom, addrTo,
binascii.hexlify(data)
.decode('utf8')))
elif outputFormat == 'csv':
print("0x{:010x}, {}, {}, {}".format(ts, addrFrom, addrTo,
binascii.hexlify(data)
.decode('utf8')))
elif outputFormat == 'yaml':
print("---")
print(yaml.dump({'ts': ts, 'from': addrFrom,
'to': addrTo, 'data': data},
Dumper=yaml.CDumper))
else:
sys.stderr.write("Error: Uknown output format: {}\n".format(
outputFormat))

else:
print("Out of sync!")

0 comments on commit 491952b

Please sign in to comment.