Giter VIP home page Giter VIP logo

pslab-firmware's Introduction

PSLab Firmware

This repository contains firmware for the Pocket Science Lab (PSLab) open hardware platform. Hardware version 5 and 6 are supported.

Build Status Gitter Mailing List Twitter Follow

Pocket Science Lab

The PSLab provides an array of test and measurement instruments for doing science and engineering experiments. Its built-in instruments include an oscilloscope, a waveform generator, a frequency counter, programmable voltage and current sources, and a logic analyzer. The PSLab also has UART, I2C, and SPI buses, via which external devices can be connected and controlled.

The PSLab is a fully open device, and FOSSASIA provides a complete hardware and software stack under open source licenses:

Buy

Get in touch

Dependencies

The following tools are required to build the firmware:

  • xc16 compiler
  • cmake

Building

This project is built with CMake. After cloning this repository, you must first initialize and update the toolchain submodule:

git submodule init
git submodule update

This will populate the external/cmake-microchip directory, after which the firmware can be built:

mkdir build
cd build
cmake ..
make

This will create a build artifact in the build directory: pslab-firmware.hex.

Flashing

The firmware can be flashed over USB or by using a programmer such as the PICkit3.

Over USB

Firmware can be flashed over USB if the device already has the bootloader installed.

Flashing the firmware requires the pslab-python library. See pslab-python for installation instructions.

Follow these steps to flash new firmware:

  1. If using PSLab v5, see Entering bootloader mode on PSLab v5

  2. Press and hold the 'BOOT' button

  3. Press the 'RESET' button

    1. The 'Status' LED should start blinking, indicating that the device is in bootloader mode

    2. Release the 'BOOT' button

  4. Run pslab flash --port <portname> firmware.hex

  5. After flashing is complete, reset or power cycle the device

Using a programmer

Warning If your device contains a bootloader, flashing just the firmware HEX with a programmer will OVERWRITE the bootloader. If for some reason you are unable to flash over USB, it is a better idea to first create a combined HEX file containing both the bootloader and the firmware and flash that, rather than flashing the pure firmare HEX. See the bootloader repository for instructions on how to create a combined HEX.

Flashing with a programmer requires the mdb.sh script, which is distributed as part of Microchip's MPLAB-X software suite. On Linux, the default installation path for mdb.sh is /opt/microchip/mplabx/<version>/mplab_platform/bin/mdb.sh. This script is used to run the file flash.mdbscript, located in the repository root. Before following the below steps, you may need to modify flash.mdbscript depending on which programmer you are using and the location of the firmware HEX.

  1. Disconnect the device from any power source
  2. Connect the programmer to the device's ICSP header
  3. Power on the device via USB
  4. Run mdb.sh flash.mdbscript
  5. Disconnect the programmer

Entering bootloader mode on PSLab v5

The PSLab v5 lacks the BOOT button which is used to enter bootloader mode on the v6. The pin which is connected to the BOOT button on the v6 is present, however. It is therefore possible to enter bootloader mode on the v5 by following these steps.

Note The PSLab v5 does not come with the bootloader preinstalled. These steps will have no effect unless you have already installed the bootloader as described here.

  1. With the USB port to the top left of the board, the 5:th pin on the MCU's left side is the BOOT pin, counting from the top. Immediately below it (6:th from the top) is a conveniently located GND pin: How to enter bootloader on PSLab v5

  2. Bridge these pins by touching both simultaneously with a small piece of metal, such as the tip of a jump wire or a paper clip.

  3. Reset or power cycle the device. The v5 lacks a RESET button, but you can soft-reset it through pslab-python:

    import pslab
    pslab.ScienceLab().reset()
  4. The BOOT and GND pins must be bridged when the reset / power cycle happens. If you did it right the SYSTEM LED will start blinking, indicating that the PSLab is in bootloader mode.

Repository structure

📦pslab-firmware
 ┣ 📂src                        # PSLab firmware source code
 ┃ ┣ 📂bus                      # Communication specific source files
 ┃ ┃ ┣ 📜 ...
 ┃ ┃ ┗ 📜i2c.c
 ┃ ┣ 📂helpers                  # Supplementary functions
 ┃ ┃ ┣ 📜 ...
 ┃ ┃ ┗ 📜version.c
 ┃ ┣ 📂instruments              # Instrument specific source files
 ┃ ┃ ┣ 📜 ...
 ┃ ┃ ┗ 📜multimeter.c
 ┃ ┣ 📂registers                # PIC specific register entry files
 ┃ ┃ ┣ 📂comparators
 ┃ ┃ ┃ ┣ 📜 ...
 ┃ ┃ ┃ ┗ 📜ic1.c
 ┃ ┃ ┣ 📂 ...                   # includes converters, memory, system
 ┃ ┃ ┣ 📂timers
 ┃ ┃ ┃ ┣ 📜 ...
 ┃ ┃ ┃ ┗ 📜tmr1.c
 ┃ ┣ 📂sdcard                   # SD Card specific file handling source files
 ┃ ┣ 📜 ...
 ┃ ┣ 📜main.c                   # Entry point to PSLab Core
 ┃ ┣ 📜commands.c               # Entry point to function implementations
 ┣ 📂external
 ┃ ┣ 📂cmake-microchip          # Toolchain submodule
 ┣ 📜CMakeLists.txt
 ┣ 📜flash.mdbscript
 ┣ 📜LICENSE
 ┗ 📜README.md

pslab-firmware's People

Contributors

bessman avatar cloudypadmal avatar hrushi20 avatar

Watchers

 avatar

pslab-firmware's Issues

Split off SD-card driver to separate module

The SD-card driver contains two parts:

The SD-card driver contains basically zero code written by us (PSLab developers). A few lines of glue, no more. As such, I would prefer to not have it in the main codebase at all, but instead version control it in a separate repo, build it into a library, and pull it in during build with CMake.

Stand-alone mode phase 1

Implement stand-alone mode as a branch-less sequence of serial commands, read from the SD-card. Responses are written back to the SD-card.

Depends on the new serial protocol. Use protobuf wire format.

Bluetooth

Add support for bluetooth communication via HC-05/06.

ESP-01 Wifi

Add support for wifi communication via ESP-01.

Heap-based memory management

Instead of allocating a fixed buffer of the stack for measured data, we could switch to a heap-based memory model.

Pros:

  • Maintainability
  • Performance?

Cons:

  • Requires libc (Microchip's libc is proprietary...)

Refactor codebase

The pslab-firmware codebase contains a lot of machine-generated code (generated by MPLAB Code Configurator), which contains a lot of duplicate code spread over several files. There are also lots of cross-dependencies between drivers.

As a result, the code is difficult to read and understand, and a change to one part of the code often necessitates further changes in other parts. This makes the code largely unmaintainable.

Due to the aforementioned cross-dependencies, it is difficult to split this issue into multiple issues. Refactoring the ADC driver, for example, will also require refactoring the multimeter, the oscilloscope, and the DMA drivers. Refactoring the DMA driver, in turn, requires refactoring the IC, CN, logic analyzer, waveform generator drivers, and so and and so forth. There is no obvious best place to start.

It may even be easier to start from scratch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.