Skip to content

Commit

Permalink
Merge pull request #258 from brilliantlabsAR/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
siliconwitch authored Aug 25, 2023
2 parents 64c0327 + e5ff8b6 commit 3238934
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 121 deletions.
9 changes: 1 addition & 8 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
"includePath": [
".",
"build",
"build/genhdr",
"driver",
"micropython",
"micropython/extmod/**",
"micropython/lib/cmsis/inc",
"micropython/lib/libm_dbl",
"micropython/lib/libm",
"micropython/lib/re1.5",
"micropython/py",
"micropython/shared/**",
"micropython/shared/readline",
"modules",
"modules/libvgrs/src",
"monocle-core",
"nrfx",
"nrfx/drivers",
Expand Down
40 changes: 34 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"presentation": {
"echo": false,
"reveal": "always",
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
Expand All @@ -24,7 +24,7 @@
},
},
{
"label": "Build & flash",
"label": "Build & Flash Chip",
"type": "shell",
"command": "make -j`getconf _NPROCESSORS_ONLN` flash",
"problemMatcher": [
Expand All @@ -43,6 +43,34 @@
"isDefault": false
},
},
{
"label": "Erase & Unlock Chip",
"type": "shell",
"command": "make recover",
"problemMatcher": [],
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
},
{
"label": "Clean",
"type": "shell",
"command": "make clean",
"problemMatcher": [],
"presentation": {
"echo": false,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
},
{
"label": "Release",
"type": "shell",
Expand All @@ -64,18 +92,18 @@
},
},
{
"label": "Clean",
"label": "RTT Debug Console",
"type": "shell",
"command": "make clean",
"command": "JLinkRTTClient",
"problemMatcher": [],
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"panel": "dedicated",
"showReuseMessage": false,
"clear": true
},
}
},
]
}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@ build/application.elf: $(OBJ)
$(Q)$(SIZE) $@

flash: build/application.hex
nrfjprog --program softdevice/*.hex --chiperase -f nrf52 --verify
nrfjprog --program $< -f nrf52 --verify
nrfjprog -q --program softdevice/*.hex --chiperase
nrfjprog -q --program build/application.hex
nrfjprog --reset -f nrf52

recover:
nrfjprog --recover

release: clean build/application.hex
nrfutil settings generate --family NRF52 --application build/application.hex --application-version 0 --bootloader-version 0 --bl-settings-version 2 build/settings.hex
mergehex -m build/settings.hex build/application.hex softdevice/s132_nrf52_7.3.0_softdevice.hex bootloader/build/nrf52832_xxaa_s132.hex -o build/monocle-micropython-$(BUILD_VERSION).hex
Expand Down
65 changes: 40 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,68 @@
# MicroPython for Monocle

A custom deployment of MicroPython designed specifically for Monocle. Read the [docs](https://docs.brilliant.xyz).
A custom deployment of MicroPython designed specifically for Monocle. Check out the user docs [here](https://docs.brilliant.xyz).

## Flash you Monocle


1. Download the latest `.hex` file from the [releases page](https://github.com/brilliantlabsAR/monocle-micropython/releases).

1. Ensure you have the [nRF Command Line Tools](https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools) installed.

1. Connect your debugger as described [here](https://docs.brilliant.xyz/monocle/monocle/#manually-programming).

1. Flash your device using the command:

```sh
nrfjprog --program *.hex --chiperase -f nrf52 --verify --reset
```

---
For those of you who want to modify the standard firmware, keep on reading.

## Getting started with development

1. Ensure you have the [ARM GCC Toolchain](https://developer.arm.com/downloads/-/gnu-rm) installed.

1. Ensure you have the [nRF Command Line Tools](https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools) installed.

1. Clone this repository, submodules and build:
1. Clone this repository along with submodules and build the mpy-cross toolchain:

```sh
# Clone and jump into this repo
git clone https://github.com/brilliantlabsAR/monocle-micropython.git
cd monocle-micropython

# Initialize the submodules
git submodule update --init
git -C micropython submodule update --init lib/micropython-lib

# Build mpy-cross toolchain
make -C micropython/mpy-cross
```

1. You can now close the terminal and open the project in [VSCode](https://code.visualstudio.com).
1. You should now be able to build the project by calling `make` from the `monocle-micropython` folder.

```sh
make
```

There are three build tasks already configured and ready for use. Access them by pressing `Ctrl-Shift-P` (`Cmd-Shift-P` on MacOS) → `Tasks: Run Task`.
1. Before flashing an nRF5340, you may need to unlock the chip first.

```sh
nrfjprog --recover
```

1. Build (`Ctrl-B` / `Cmd-B`)
1. Build & flash
1. You should then be able to flash the device.

```sh
make flash
```

### Debugging

1. Open the project in [VSCode](https://code.visualstudio.com).

There are some build tasks already configured within `.vscode/tasks.json`. Access them by pressing `Ctrl-Shift-P` (`Cmd-Shift-P` on MacOS) → `Tasks: Run Task`.

1. Build
1. Build & Flash Chip
1. Erase & Unlock Chip
1. Clean

1. Connect your debugger as described [here](https://docs.brilliant.xyz/monocle/monocle/#manually-programming).

1. You many need to unlock the device by using the `Erase Chip` task before programming or debugging.

1. To enable IntelliSense, be sure to select the correct compiler from within VSCode. `Ctrl-Shift-P` (`Cmd-Shift-P` on MacOS) → `C/C++: Select IntelliSense Configuration``Use arm-none-eabi-gcc`.

1. Install the [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) extension for VSCode in order to enable debugging.

1. A debugging launch is already configured within `.vscode/launch.json`. Run the `J-Link` launch configuration from the `Run and Debug` panel, or press `F5`. The project will automatically build and flash before launching.

1. To monitor the logs, run the task `RTT Console` and ensure the `J-Link` launch configuration is running.

### Generating final release `.hex` and DFU `.zip` files

1. Download and install [nrfutil](https://www.nordicsemi.com/Products/Development-tools/nRF-Util) including the `nrf5sdk-tools` package:
Expand Down
2 changes: 1 addition & 1 deletion config-tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const camera_config_t camera_config[] = {
{0x4602, 0x02}, // JPEG output width (high byte)
{0x4603, 0x80}, // JPEG output width (low byte)
{0x4604, 0x80}, // JPEG output width (low byte)
{0x3820, 0x47}, // Flip image vertically
{0x3820, 0x40}, // Don't flip the image
{0x3821, 0x27}, // TIMING_TC_REG_21 - enable JPEG, binning, flip image vertically
{0x3002, 0x00}, // SYSTEM_RESET_2 - set everything on
{0x3814, 0x31}, // Timing Y increment
Expand Down
2 changes: 1 addition & 1 deletion micropython
Submodule micropython updated 330 files
2 changes: 2 additions & 0 deletions modules/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "nrf_gpio.h"
#include "nrfx_systick.h"
#include "py/runtime.h"

STATIC mp_obj_t camera_sleep(void)
Expand All @@ -35,6 +36,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(camera_sleep_obj, camera_sleep);
STATIC mp_obj_t camera_wake(void)
{
nrf_gpio_pin_write(CAMERA_SLEEP_PIN, false);
nrfx_systick_delay_ms(5);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(camera_wake_obj, camera_wake);
Expand Down
1 change: 0 additions & 1 deletion modules/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

def capture():
_camera.wake()
time.sleep_ms(1)
fpga.write(0x1003, b"")
while fpga.read(0x1000, 1) == b"2":
time.sleep_us(10)
Expand Down
62 changes: 0 additions & 62 deletions modules/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,73 +103,11 @@ STATIC mp_obj_t fpga_run(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fpga_run_obj, 0, 1, fpga_run);

STATIC mp_obj_t fpga_version(void)
{
uint8_t target_device[8];
uint8_t application_version[13];
uint8_t chip_revision[8];

memset(target_device, 0, sizeof(target_device));
memset(application_version, 0, sizeof(application_version));
memset(chip_revision, 0, sizeof(chip_revision));

uint8_t target_device_address[2] = {(uint8_t)(0x0001 >> 8), (uint8_t)0x0001};
uint8_t application_version_address[2] = {(uint8_t)(0x0002 >> 8), (uint8_t)0x0002};
uint8_t chip_revision_address[2] = {(uint8_t)(0x0003 >> 8), (uint8_t)0x0003};

monocle_spi_write(FPGA, target_device_address, 2, true);
monocle_spi_read(FPGA, target_device, 4, false);

monocle_spi_write(FPGA, application_version_address, 2, true);
monocle_spi_read(FPGA, application_version, 12, false);

monocle_spi_write(FPGA, chip_revision_address, 2, true);
monocle_spi_read(FPGA, chip_revision, 4, false);

// In case the chip is off, or has no image, nothing will be returned
if (target_device[0] == 0xff)
{
strcpy((char *)target_device, "unknown");
}
if (application_version[0] == 0xff)
{
strcpy((char *)application_version, "unknown");
}
if (chip_revision[0] == 0xff)
{
strcpy((char *)chip_revision, "unknown");
}

// In case of legacy revC images, the register will return 'f' characters
if (memcmp(chip_revision, "ffff", 4) == 0)
{
strcpy((char *)chip_revision, "revC");
}

mp_obj_t return_dict = mp_obj_new_dict(0);

mp_obj_dict_store(return_dict,
MP_OBJ_NEW_QSTR(MP_QSTR_target_device),
mp_obj_new_str((char *)target_device, strlen((char *)target_device)));

mp_obj_dict_store(return_dict,
MP_OBJ_NEW_QSTR(MP_QSTR_application_version),
mp_obj_new_str((char *)application_version, strlen((char *)application_version)));

mp_obj_dict_store(return_dict,
MP_OBJ_NEW_QSTR(MP_QSTR_chip_revision),
mp_obj_new_str((char *)chip_revision, strlen((char *)chip_revision)));

return return_dict;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(fpga_version_obj, fpga_version);

STATIC const mp_rom_map_elem_t fpga_module_globals_table[] = {

{MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&fpga_read_obj)},
{MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&fpga_write_obj)},
{MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&fpga_run_obj)},
{MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&fpga_version_obj)},
};
STATIC MP_DEFINE_CONST_DICT(fpga_module_globals, fpga_module_globals_table);

Expand Down
1 change: 1 addition & 0 deletions mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)

#define MICROPY_PY_ASYNCIO (1)
#define MICROPY_PY_IO_IOBASE (1)

#define MICROPY_MODULE_WEAK_LINKS (1)

Expand Down
Loading

0 comments on commit 3238934

Please sign in to comment.