Advertisement
jlhonora

Batch programming for msp430 under linux

Feb 21st, 2012
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Script for batch programming of several devices.
  4. # Specifically written for msp430 devices, but if
  5. # you want to program another device just modify
  6. # the program() function
  7. #
  8. # Usage:
  9. # ./patch_program.sh binary_file.ihex
  10. #
  11. # Jose Luis Honorato, 2012
  12.  
  13.  
  14. # Checks if the device in a specific port was correctly programmed
  15. # Arguments:
  16. #   1. Dump file name
  17. #   2. Port name
  18. function check_output() {
  19.  
  20.     local port_name=$2
  21.     local dump_file_name=$1
  22.  
  23.         echo -n "Device at port $port_name "
  24.     # The string "Traceback" is present whenever an exception
  25.     # occurred during the programming. It could be replaced
  26.     # with any other string
  27.     if grep -q "Traceback" $dump_file_name; then
  28.         echo "failed!"
  29.     else
  30.         echo "OK"
  31.     fi
  32. }
  33.  
  34. # Programs a
  35. # Arguments:
  36. #   1. Port name
  37. #   2. Port number
  38. #   3. binary file name
  39. function program() {
  40.    
  41.     local port_name=$1
  42.     local port_number=$2
  43.     local bin_file_name=$3
  44.  
  45.     # Ready to program, put the output into a file. We cannot add the & symbol
  46.     # to this line because we need to wait for the programming to be finished
  47.     # in order to analyze the dump file.
  48.     echo -e "Programming port $port_name"
  49.     export dump_file=$(echo $"dump$port_number.txt")
  50.     # Programs and writes the output to the file
  51.     (./goodfet.bsl -c $port_name -r -e -I -p -S 38400 $bin_file_name) &> $dump_file
  52.    
  53.     # Check if it was correctly programmed
  54.     (check_output $dump_file $port_name) | tee -a script_status.txt
  55.     exit   
  56. }
  57.  
  58. function check_input_parameters() {
  59.     case "$#" in
  60.  
  61.     0)  # If no arguments are passed a default file name is used
  62.         echo "No arguments passed, assuming default binary: $default_bin_file_name"
  63.         bin_file_name=$default_bin_file_name
  64.         ;;
  65.     *)  # If there is more than one argument then discard them
  66.         if [ "$#" -gt "1" ]; then
  67.             echo "Too many arguments ($#), using only the first one"
  68.         fi
  69.         bin_file_name=$1
  70.         # Get binary file extension and name
  71.         local bin_file_extension=$(echo $bin_file_name | cut -d . -f 2)
  72.         local bin_file_basename=$(basename $bin_file_name ".$bin_file_extension")
  73.    
  74.         # If it is not ihex then transform it
  75.         if [ $bin_file_extension != "ihex" ]; then
  76.             local old_bin_file_name=$bin_file_name
  77.             bin_file_name="$bin_file_basename.ihex"
  78.             echo "Transforming $old_bin_file_name to $bin_file_name"
  79.             msp430-objcopy --output-target=ihex $old_bin_file_name $bin_file_name
  80.         fi
  81.         ;;
  82.     esac
  83. }
  84.  
  85. # Main function for batch programming
  86. function main_task() {
  87.     echo -e "\nStarting batch programming"
  88.     default_bin_file_name="bin.ihex"
  89.     bin_bile_name=$default_bin_file_name
  90.     check_input_parameters $@
  91.    
  92.     # Remove dumps from previous batches
  93.     rm ./dump*.txt
  94.     rm ./script_status.txt 
  95.  
  96.     # Find all available serial ports: ttyUSB (Linux) and tty.usb (Mac OS)
  97.     available_ports=$(find /dev -regextype posix-egrep -iregex "/dev/t.*(ty(USB.|\.usb\w+))")
  98.     echo "Found the following ports:"
  99.     echo $available_ports
  100.  
  101.     # For each found port program the device
  102.     export port_number=0
  103.     for current_port in $(echo $available_ports)
  104.     do
  105.         program $current_port $port_number $bin_file_name &
  106.         export port_number=$(($port_number + 1))
  107.     done
  108.  
  109.     # We are done here because the programming happens in parallel
  110.     echo -e "\nRun cat script_status.txt a bit later to see the results\n"
  111.     exit
  112. }
  113.  
  114.  
  115. main_task $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement