The code on this repository runs on the Cortex-M3 core embedded on the SmartFusion2 FPGA.
- Download and install SoftConsole
- NOTE: Latest version to support Cortex-M3 development is 2021.1
- Download from Microchip website
- Clone this repository/unzip the archive downloaded via GitHub
- Import this project from the repo/unzipped archive into SoftConsole
- Program firmware to RAM or to NVM.
Most of the code is under main.c, in the while (1) loop:
REQ_HKdata is prepared once a second; the second counting is handled byTimer1_IRQHandler;REQ_PAYLOADdata is prepared once the DAQ has finished; note that this is a lenghty process (several hundreds of microseconds), especially if histogram binning is performed;- Prepping data for and acting upon data from MSP commands are then handled
in the next
if/else ifstatements:if (has_send)for MSP send commands (from CUBES to OBC);else if (has_rcvd)for MSP receive commands (by CUBES from OBC);else if (has_syscommand)for MSP system commands (for CUBES from OBC).
MSP callbacks functions and main I2C ISR are also present at the bottom of
main.c.
- MSP send (CUBES to OBC)
msp_expsend_startis where the MSP send buffer is assigned to the data to be sent; thehas_sendvariable is also assigned, which informs the main loop to update with new send data based on MSP command;- MSP frames are then sent via
msp_expsend_data(msp_expsend_completeonly clears theREQ_PAYLOADbuffer so it doesn't contain stale data in case of a newREQ_PAYLOADbeing issued);
- MSP receive (CUBES from OBC)
msp_exprecv_startclears the MSP receive buffer for new data;msp_exprecv_databuffers in data retrieved in MSP framesmsp_exprecv_completeinforms the main loop the data is ready to be processed
- The whole process for sending MSP frames starts in
I2C1_SlaveWriteHandler, which essentially (1) waits for an MSP frame from the OBC,msp_recv_callback; and (2) sends a reply MSP frame to the OBC,msp_send_callback. - NOTE: To better understand the way MSP functions, right-click any of the MSP callbacks,
(e.g.,
msp_expsend_startormsp_exprecv_data), then click Open Call Hierarchy.
Other folders under cubes-fw contain various APIs for handling devices
on the CUBES board.
cubes-fwfirmware // Code generated from Liberohk_adc // API to handle the ADS1015 ADChvps // API to handle the C11204-02 HVPS modulemem // API to handle CUBES memory accessesmsp // MSP API functions, generated using the Python script supplied with MSPutils // Various utilitary APIs, e.g., to handle the on-board LED
- See firmware/README.md.
- Externally from the
cubes-fwrepository, obtain the MSP repository from GitLab:git clone https://gitlab.com/kth-mist/msp msp-repo
- Copy/move the file
cubes-fw/msp/msp_configuration.hto somewhere you know; this file will need to replace whatever gets generated by the MSPconf.pyscript! - Delete all contents inside the
cubes-fw/msp/folder; - Use
msp-repo/conf.pyto generate a new set of MSP files; - Copy these files from
msp-repo/target/tocubes-fw/msp/. - Copy back the
msp_configuration.hfile you saved earlier over that generated by theconf.pyscript.
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".
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):
-
BOARD_ID=C<number-on-label>(Cstands for CUBES,<number-on-label>corresponds to board number,1through5) -
Board IDs:
BOARD_ID=\"C3\"for CUBES-1 on MISTBOARD_ID=\"C4\"for CUBES-2 on MIST
- Note: The
\"characters are necessary to avoid compile errors.
-
Open the Properties window for the
cubes-fwproject 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. -
Navigate to C/C++ Build > Settings > GNU ARM Cross C Linker > General and double-click the script file:
-
Ensure the
esramlinker script is used for programming: -
Still in the Properties window, C/C++ Build > Settings, navigate to GNU ARM Cross C Compiler > Preprocessor.
-
Change the
BOARD_IDmacro for the board you are programming as outlined in the Board ID section above (note the escape characters before each double quote): -
Change the
MSP_EXP_ADDRmacro for the board according to thei2c.hconfig file under theobcswGitLab repository, nominally:MSP_EXP_ADDR=0x35for CUBES-1MSP_EXP_ADDR=0x36for CUBES-2
-
Press the Apply and Close button in the Properties dialog.
-
Connect the FlashPro5 programmer to the CUBES PCB of interest.
-
Press the Debug button -- the one that looks like a bug -- on the SoftConsole interface.
-
If a window opens up prompting to select a launch configuration, select the
cubes-fw_Debug.launchfile and click OK. -
The code should now be programmed to CUBES volatile memory; HK can be read out from CUBES and checked if it "makes sense".
-
Open the Properties window for the
cubes-fwproject 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. -
Navigate to C/C++ Build > Settings > GNU ARM Cross C Linker > General and double-click the linker script file:
-
To ensure the code is programmed to non-volatile memory, change
esramtoenvmat the very end of the text line in the dialog that appears: -
Still in the Properties window, C/C++ Build > Settings, navigate to GNU ARM Cross C Compiler > Preprocessor.
-
Change the
BOARD_IDmacro for the board you are programming as outlined in the Board ID section above (note the escape characters before each double quote): -
Change the
MSP_EXP_ADDRmacro for the board according to thei2c.hconfig file under theobcswGitLab repository, nominally:MSP_EXP_ADDR=0x35for CUBES-1MSP_EXP_ADDR=0x36for CUBES-2
-
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.
-
End the debug session from SoftConsole's Debug perspective.
-
Move the FlashPro5 programmer from the board you just programmed to the next one you want to program.
-
Repeat steps 4-7.
- NOTE: Remember that the
BOARD_IDandMSP_EXP_ADDRmacros need to be different.
- NOTE: Remember that the
-
Reset the CUBES stackup by power-cycling the
5V_CUBESpower rail. -
Perform a
REQ_HKMSP command from each of the two CUBES boards and ensure the readouts "make sense".
IMPORTANT:
-
Revert the
.cprojectfile back to its original contents, to ensure you are not unnecessarily programming to NVM next time:git restore .cproject