Skip to content

Instantly share code, notes, and snippets.

@carlfriess
Created November 15, 2024 11:00
Show Gist options
  • Save carlfriess/2fcebacbe5c13772396216c72eaf6cc0 to your computer and use it in GitHub Desktop.
Save carlfriess/2fcebacbe5c13772396216c72eaf6cc0 to your computer and use it in GitHub Desktop.
Flash multiple MCUs using MSPFlasher
#!/bin/bash
# Check if a file argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <hex-file>"
exit 1
fi
FILE_PATH=$1
# Check if the file exists
if [ ! -f "$FILE_PATH" ]; then
echo "Error: File '$FILE_PATH' not found!"
exit 1
fi
# Variables to track success and failure counts
SUCCESS_COUNT=0
FAILURE_COUNT=0
TOTAL_SUCCESS_TIME=0
while true; do
echo "Press Enter to continue (or Ctrl+C to quit)..."
read -r
# Record start time
START_TIME=$(date +%s.%N)
# Execute the command
DYLD_FALLBACK_LIBRARY_PATH=~/ti/MSPFlasher_1.3.20 ~/ti/MSPFlasher_1.3.20/MSP430Flasher -w "$FILE_PATH" -v -g -z "[VCC]"
# Capture the exit status of the command
EXIT_STATUS=$?
# Record end time
END_TIME=$(date +%s.%N)
EXECUTION_TIME=$(echo "$END_TIME - $START_TIME" | bc)
if [ $EXIT_STATUS -eq 0 ]; then
((SUCCESS_COUNT++))
TOTAL_SUCCESS_TIME=$(echo "$TOTAL_SUCCESS_TIME + $EXECUTION_TIME" | bc)
else
((FAILURE_COUNT++))
fi
# Calculate average time for successful executions
if [ $SUCCESS_COUNT -ne 0 ]; then
AVERAGE_SUCCESS_TIME=$(echo "scale=2; $TOTAL_SUCCESS_TIME / $SUCCESS_COUNT" | bc)
else
AVERAGE_SUCCESS_TIME=0
fi
# Print statistics
echo
if [ $EXIT_STATUS -eq 0 ]; then
echo "Execution time: ${EXECUTION_TIME}s (avg ${AVERAGE_SUCCESS_TIME}s)"
fi
echo "Success count: $SUCCESS_COUNT"
if [ $FAILURE_COUNT -ne 0 ]; then
echo "Failure count: $FAILURE_COUNT"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment