tstana / cubes-fw

Firmware running on the CUBES SmartFusion2 Cortex-M3 core
2 stars 1 forks source link

Firmware for the CUBesat x-ray Explorer using Scintillators (CUBES)

Introduction

The code on this repository runs on the Cortex-M3 core embedded on the SmartFusion2 FPGA.

Getting Started

  1. Download and install SoftConsole
    • NOTE: Latest version to support Cortex-M3 development is 2021.1
    • Download from Microchip website
  2. Clone this repository/unzip the archive downloaded via GitHub
  3. Import this project from the repo/unzipped archive into SoftConsole
  4. Program firmware to RAM or to NVM.

Code Summary

Most of the code is under main.c, in the while (1) loop:

MSP callbacks functions and main I2C ISR are also present at the bottom of main.c.

Other folders under cubes-fw contain various APIs for handling devices on the CUBES board.

Folder Structure

Regenerating the firmware folder

Regenerating the msp folder

Programming

Programming Port

CUBES should be programmed using a FlashPro5 programmer from Microchip. The standard 10-pin JTAG connector supplied with the FlashPro5 should be adapted to the 1.27-mm pitch programming port on the CUBES board using a 2.54-to-1.27-mm adapter:

One such adapter can be found in AlbaNova, in the "PoGO lab" on the bottom floor of the building. The adaptor should be located in the plastic box labeled "CUBES".

Board ID

Each CUBES board has its own ID, labeled on the top side of CUBES boards, corresponding to the -Z face of the satellite. The number on this label corresponds to the second character in the BOARD_ID macro, defined via a -D compiler flag (see programming sections below):

Debug: Program to CUBES RAM

  1. Open the Properties window for the cubes-fw project by either right-clicking the project in SoftConsole and pressing Properties in the pop-up menu, or selecting the project in SoftConsole and hitting Alt+Enter on your keyboard.

  2. Navigate to C/C++ Build > Settings > GNU ARM Cross C Linker > General and double-click the script file:

    linker-script-file-nav.png
  3. Ensure the esram linker script is used for programming:

    esram-linker-script.png
  4. Still in the Properties window, C/C++ Build > Settings, navigate to GNU ARM Cross C Compiler > Preprocessor.

  5. Change the BOARD_ID macro for the board you are programming as outlined in the Board ID section above (note the escape characters before each double quote):

    • BOARD_ID = \"C3\" or
    • BOARD_ID = \"C4\"

      board-id-macro.png

  6. Change the MSP_EXP_ADDR macro for the board according to the i2c.h config file under the obcsw GitLab repository, nominally:

    • MSP_EXP_ADDR = 0x35 for CUBES-1
    • MSP_EXP_ADDR = 0x36 for CUBES-2

    msp-exp-addr-macro.png

  7. Press the Apply and Close button in the Properties dialog.

  8. Connect the FlashPro5 programmer to the CUBES PCB of interest.

  9. Press the Debug (bug) button on the SoftConsole interface.

  10. The code should now be programmed to CUBES volatile memory; HK can be read out from CUBES and checked if it "makes sense".

Production: Program to CUBES NVM

  1. Open the Properties window for the cubes-fw project by either right-clicking the project in SoftConsole and pressing Properties in the pop-up menu, or selecting the project in SoftConsole and hitting Alt+Enter on your keyboard.

  2. Navigate to C/C++ Build > Settings > GNU ARM Cross C Linker > General and double-click the linker script file:

    linker-script-file-nav.png
  3. To ensure the code is programmed to non-volatile memory, change esram to envm at the very end of the text line in the dialog that appears:

    envm-linker-script.png
  4. Still in the Properties window, C/C++ Build > Settings, navigate to GNU ARM Cross C Compiler > Preprocessor.

  5. Change the BOARD_ID macro for the board you are programming as outlined in the Board ID section above (note the escape characters before each double quote):

    board-id-macro.png

  6. Change the MSP_EXP_ADDR macro for the board according to the i2c.h config file under the obcsw GitLab repository, nominally:

    • MSP_EXP_ADDR = 0x35 for CUBES-1
    • MSP_EXP_ADDR = 0x36 for CUBES-2

    msp-exp-addr-macro.png

  7. Click the Debug (yes -- Debug!) button in the SoftConsole main window to program the board. The Console window should display information about it programming to NVM. Programming should also take longer than in the case of RAM.

  8. End the debug session from SoftConsole's Debug perspective.

  9. Move the FlashPro5 programmer from the board you just programmed to the next one you want to program.

  10. Repeat steps 4-7.

    • NOTE: Remember that the BOARD_ID and MSP_EXP_ADDR macros need to be different.
  11. Reset the CUBES stackup by power-cycling the 5V_CUBES power rail.

  12. Perform a REQ_HK MSP command from each of the two CUBES boards and ensure the readouts "make sense".

IMPORTANT: