From e8b586cc02f5fa67a0b60e66f95cc4edb2584870 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 17 Apr 2014 14:54:14 +0700 Subject: [PATCH] add script files, fix build error with device --- demos/board_test.pl | 234 ++++++++++++++++++++++++++++++++++++++++++ demos/build_all.pl | 154 +++++++++++++++++++++++++++ demos/build_report.pl | 64 ++++++++++++ tinyusb/host/hcd.h | 2 + 4 files changed, 454 insertions(+) create mode 100644 demos/board_test.pl create mode 100644 demos/build_all.pl create mode 100644 demos/build_report.pl diff --git a/demos/board_test.pl b/demos/board_test.pl new file mode 100644 index 00000000..d27005ef --- /dev/null +++ b/demos/board_test.pl @@ -0,0 +1,234 @@ +#!/usr/bin/perl + +use List::MoreUtils 'any'; +use List::MoreUtils 'first_value'; +use File::Spec; +use File::Find; +use File::Path; +use File::Glob; +use File::stat; +use Cwd; +use Cwd 'abs_path'; + +$" = "\n"; # change list separator + +$KEIL_PATH = 'C:/Keil/UV4'; #'/C/Keil/UV4'; +$IAR_PATH = glob ('C:/Program*/IAR*/Embedded*/common/bin'); + +$XPRESSO_PATH = glob ('C:/nxp/LPCXpresso_7*/lpcxpresso'); +$XPRESSO_BIN_PATH = "$XPRESSO_PATH/bin"; +$XPRESSO_PATH = "$XPRESSO_PATH;$XPRESSO_PATH/bin;$XPRESSO_PATH/tools/bin;$XPRESSO_PATH/msys/bin"; + +$ENV{'PATH'} .= ';' . $KEIL_PATH . ';' . $IAR_PATH . ';' . $XPRESSO_PATH; +$ENV{'PATH'} .= ';' . "C:/Keil/ARM/BIN"; +#print $ENV{'PATH'}; die; + +$repo_path = abs_path(cwd . "/.."); + +$device_dir = "device/"; +$host_dir = "host/"; + +##### Command line arguments ### +$board = $ARGV[0]; + +$is_keil = (any { /keil/ or /all/ } @ARGV); +$is_iar = (any { /iar/ or /all/ } @ARGV); +$is_xpresso = (any { /xpresso/ or /all/ } @ARGV); +$is_download_only = (any { /download_only/ } @ARGV); + +if ( any { /device_/ or /host_/ } @ARGV) +{ + my $build_project; + $device_dir .= defined ($build_project = first_value { /device_/ } @ARGV) ? $build_project : "nowhere_path" ; + $host_dir .= defined ($build_project = first_value { /host_/ } @ARGV) ? $build_project : "nowhere_path"; +}else +{ #default is all + $device_dir .= "*"; + $host_dir .= "*"; +} + +#print "$device_dir $host_dir"; die; + +my $log_file = "board_$board.txt"; +unlink $log_file; + +################## KEIL ##################### +if ($is_keil) +{ + @KEIL_PROJECT_LIST = (<$device_dir*/*.uvproj>, <$host_dir*/*.uvproj>); + + foreach (@KEIL_PROJECT_LIST) + { + /([^\/]+).uvproj/; + print_title("Keil $1"); + + my $temp_log = "temp_log.txt"; + my $build_cmd = "Uv4 -b $_ -t$board -j0 -o ../../$temp_log"; + + if ( $is_download_only || cmd_execute($build_cmd) < 2 ) + { + append_file($log_file, $temp_log); + + my $flash_cmd = "Uv4 -f $_ -t$board -j0 -o ../../$temp_log"; + append_file($log_file, $temp_log) if flash_to_board($flash_cmd); + } + } +} + +################## IAR ##################### +if ($is_iar) +{ + @IAR_PROJECT_LIST = (<$device_dir*/*.ewp>, <$host_dir*/*.ewp>); + + foreach (@IAR_PROJECT_LIST) + { + /(.+\/)([^\/]+).ewp/; + print_title("IAR $2"); + + my $build_cmd = "IarBuild $_ -build $board -log warnings >> $log_file"; + if ( $is_download_only || cmd_execute($build_cmd) == 0) + { + my $flash_cmd = "cd $1 & " . iar_flash_cmd($_); + flash_to_board($flash_cmd); + } + } +} + +################## LPCXPRESSO ##################### +if ($is_xpresso) +{ + (my $repo_path_other_dash = $repo_path) =~ s/\//\\/g; + my $workspace_dir = "C:/Users/hathach/Dropbox/tinyusb/workspace7"; #projects must be opened in the workspace to be built + + my %flash_tool = + ( # board => (tool, chip_name) + 'Board_EA4357' => ['crt_emu_lpc18_43_nxp' , 'LPC4357' ], + 'Board_NGX4330' => ['crt_emu_lpc18_43_nxp' , 'LPC4330' ], + 'Board_LPCXpresso1769' => ['crt_emu_cm3_nxp' , 'LPC1769' ], + 'Board_LPCXpresso1347' => ['crt_emu_lpc11_13_nxp' , 'LPC1347' ], + 'Board_rf1ghznode' => ['crt_emu_lpc11_13_nxp' , 'LPC11U37/401'], + ); + + die "board is not supported" unless $flash_tool{$board}; + + print "all projects in $workspace_dir must be opened and set to the correct MCU of the boards. Enter to continue:\n"; + #; + + @XPRESSO_PROJECT_LIST = (<$device_dir*/.cproject>, <$host_dir*/.cproject>); + + foreach (@XPRESSO_PROJECT_LIST) + { + /([^\/]+)\/.cproject/; + print_title("XPRESSO $1"); + + my $build_cmd = "lpcxpressoc -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -cleanBuild $1/$board -data $workspace_dir >> $log_file"; + + if ( $is_download_only || cmd_execute($build_cmd) == 0) + { + /(.+\/(.+))\/.cproject/; + my $flash_cmd = "$flash_tool{$board}[0] -p$flash_tool{$board}[1] -s2000 -flash-load-exec=$1/$board/$2.axf"; + + $flash_cmd .= " -flash-driver=$XPRESSO_BIN_PATH/Flash/LPC18_43_SPIFI_4MB_64KB.cfx" if $board eq 'Board_NGX4330'; + + #print $flash_cmd; die; + flash_to_board($flash_cmd); + } + } + +=pod + open (my $fout, ">$log_file") or die; + + foreach (@log_content) + { + unless (/Invoking: MCU C Compiler/ or /arm-none-eabi-gcc -D/ or /Finished building:/ or /^ $/) + { + s/Building file:.+?([^\/]+\.[ch])/\1/; + s/$repo_path//; + s/$repo_path_other_dash//; + print $fout $_; + } + } +=cut +} + +################## HELPER ##################### +sub cmd_execute +{ + print "executing: $_[0] ..."; + $result = system($_[0]); + print "$result done\n"; + return $result; +} + +sub flash_to_board +{ + my $flash_cmd = $_[0]; + + print "Do you want to flash y/n: "; + chomp ($ask = ); + #$ask = "y"; + cmd_execute($flash_cmd) if ( $ask eq "y" ); + + return ( $ask eq "y" ); +} + +sub print_title +{ + print "---------------------------------------------------------------------\n"; + print "$_[0] for $board\n"; + print "---------------------------------------------------------------------\n"; +} + +sub append_file +{ + my $log_file = $_[0]; + my $temp_log = $_[1]; + + open(my $log_handle, ">>$log_file") or die "cannot open $log_file"; + open(my $temp_handle, $temp_log) or die "cannot open $temp_log"; + + print $log_handle (@temp_content = <$temp_handle>); + + close($temp_handle); + close($log_handle); +} + +sub iar_flash_cmd +{ + $_[0] =~ /^(.+)\/(.+).ewp/; + my $debug_file = "$board/Exe/$2.out"; + + my $arm_path = abs_path "$IAR_PATH/../../arm"; + my $bin_path = "$arm_path/bin"; + my $debugger_path = "$arm_path/config/debugger/NXP"; + + my %mcu_para_hash = + ( # board => family (for macro), architecture, fpu, name + 'Board_EA4357' => ['LPC18xx_LPC43xx', 'Cortex-M4', 'VFPv4', 'LPC4357_M4' ], + 'Board_NGX4330' => ['LPC18xx_LPC43xx', 'Cortex-M4', 'VFPv4', 'LPC4330_M4' ], + 'Board_LPCXpresso1769' => ['LPC175x_LPC176x', 'Cortex-M3', 'None' , 'LPC1769' ], + 'Board_LPCXpresso1347' => ['lpc1315' , 'Cortex-M3', 'None' , 'LPC1347' ], + 'Board_rf1ghznode' => ['' , 'Cortex-M0', 'None' , 'LPC11U37FBD48_401'], + ); + + my @mcu_para = @{$mcu_para_hash{$board}}; + die "Board is not supported" unless @mcu_para; + + my $cmd = "cspybat \"$bin_path/armproc.dll\" \"$bin_path/armjlink.dll\" \"$debug_file\" --download_only --plugin \"$bin_path/armbat.dll\""; + + $cmd .= " --macro \"$debugger_path/Trace_$mcu_para[0].dmac\"" if $mcu_para[0]; + + $repo_mcu_iar = "$repo_path/mcu/lpc43xx/iar"; + $cmd .= " --macro \"$repo_mcu_iar/lpc18xx_43xx_debug.mac\" --flash_loader \"$repo_mcu_iar/FlashLPC18xx_43xx_SPIFI.board\"" if $board eq 'Board_NGX4330'; + + $cmd .= " --backend -B \"--endian=little\" \"--cpu=$mcu_para[1]\" \"--fpu=$mcu_para[2]\" \"-p\" \"$debugger_path/$mcu_para[3].ddf\" \"--semihosting\" \"--device=$mcu_para[3]\""; + + #SWD interface --> need change if use lpc43xx_m0 + $cmd .= " \"--drv_communication=USB0\" \"--jlink_speed=auto\" \"--jlink_initial_speed=1000\" \"--jlink_reset_strategy=0,0\" \"--jlink_interface=SWD\" \"--drv_catch_exceptions=0x000\" --drv_swo_clock_setup=72000000,0,2000000\""; + + $cmd .= " \"--jlink_script_file=$debugger_path/LPC4350_DebugCortexM4.JLinkScript\"" if $mcu_para[3] =~ /LPC43.._M4/; + + $cmd =~ s/\//\\/g; + #print $cmd; die; + return $cmd; +} \ No newline at end of file diff --git a/demos/build_all.pl b/demos/build_all.pl new file mode 100644 index 00000000..08b184d4 --- /dev/null +++ b/demos/build_all.pl @@ -0,0 +1,154 @@ +#!/usr/bin/perl + +################## HOW TO USE THIS FILE ##################### +# iar keil xpresso to build with those toolchain +# clean or build for action +############################################################# +use List::MoreUtils 'any'; +use File::Spec; +use File::Find; +use File::Path; +use File::Glob; +use File::stat; +use File::Basename; +use Cwd; +use Cwd 'abs_path'; + +#use Time::Piece; +#use Time::Seconds; + +$" = "\n"; # change list separator + +$KEIL_PATH = 'C:/Keil/UV4'; #'/C/Keil/UV4'; +$IAR_PATH = glob ('C:/Program*/IAR*/Embedded*/common/bin'); +$XPRESSO_PATH = glob ('C:/nxp/LPCXpresso_7*/lpcxpresso'); +$XPRESSO_PATH = "$XPRESSO_PATH;$XPRESSO_PATH/bin;$XPRESSO_PATH/tools/bin;$XPRESSO_PATH/msys/bin"; + +$ENV{'PATH'} = $KEIL_PATH . ';' . $IAR_PATH . ';' . $XPRESSO_PATH . ';' . $ENV{'PATH'}; +#print $ENV{'PATH'}; die; + +$repo_path = abs_path(cwd . "/.."); +#print $repo_path; die; + +$device_dir = "device/device"; +$host_dir = "host/host"; + +$is_build = any { /build/ } @ARGV; +$is_clean = any { /clean/ } @ARGV; +$is_build = 1 if !$is_clean; # default is build + +$is_keil = (any { /keil/ } @ARGV) || (any { /all/ } @ARGV); +$is_iar = (any { /iar/ } @ARGV) || (any { /all/ } @ARGV); +$is_xpresso = (any { /xpresso/ } @ARGV) || (any { /all/ } @ARGV); + +################## KEIL ##################### +if ($is_keil) +{ + @KEIL_PROJECT_LIST = (<$device_dir*/*.uvproj>, <$host_dir*/*.uvproj>); + + foreach (@KEIL_PROJECT_LIST) + { + /([^\/]+).uvproj/; + my $log_file = "build_all_keil_" . $1 . ".txt"; + my $build_cmd = "Uv4 -b $_ -z -j0 -o ../../$log_file"; + + cmd_execute($build_cmd); + } +} + +################## IAR ##################### +if ($is_iar) +{ + @IAR_PROJECT_LIST = (<$device_dir*/*.ewp>, <$host_dir*/*.ewp>); + + foreach (@IAR_PROJECT_LIST) + { + my $proj_dir = dirname $_; + + /([^\/]+).ewp/; + my $proj_name = $1; + my $log_file = "build_all_iar_" . $proj_name . ".txt"; + unlink $log_file; #delete log_file if existed + + #open project file to get configure name + my $file_content = file_to_var($_); + + #get configure by pattern and build + while ($file_content =~ /^\s*\s*$^\s*(.+)<\/name>\s*$/gm) + { + my $build_cmd = "IarBuild $_ -build $1 -log warnings >> $log_file"; + cmd_execute($build_cmd); + + my $out_file = "$proj_dir/$1/Exe/$proj_name.out"; + system("size $out_file >> $log_file"); + } + } +} + +################## LPCXPRESSO ##################### +($repo_path_other_dash = $repo_path) =~ s/\//\\/g; +if ($is_xpresso) +{ + $workspace_dir = "C:/Users/hathach/Dropbox/tinyusb/workspace7"; #projects must be opened in the workspace to be built + @XPRESSO_PROJECT_LIST = (<$device_dir*/.cproject>, <$host_dir*/.cproject>); + + foreach (@XPRESSO_PROJECT_LIST) + { + /([^\/]+)\/.cproject/; + my $log_file = "build_all_xpresso_" . $1 . ".txt"; + my $build_cmd = "lpcxpressoc -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -build $1 -data $workspace_dir > $log_file"; + + cmd_execute($build_cmd); + + #open log file to clean up output + open (my $fin, $log_file) or die; + my @log_content = <$fin>; + close($fin); + + open (my $fout, ">$log_file") or die; + + foreach (@log_content) + { + unless (/Invoking: MCU C Compiler/ or /arm-none-eabi-gcc -D/ or /Finished building:/ or /^ $/) + { + s/Building file:.+?([^\/]+\.[ch])/\1/; + s/$repo_path//; + s/$repo_path_other_dash//; + print $fout $_; + } + } + } +} + +### call report builder ### +system("perl build_report.pl"); + +################## HELPER ##################### +sub cmd_execute +{ + print "executing: $_[0]\n..."; + system($_[0]); + print "done\n"; +} + +sub file_to_var +{ #open project file to get configure name + my $file_content; + open(my $fin, $_[0]) or die "Can't open $_[0] to read\n"; + { + local $/; + $file_content = <$fin>; + close($fin); + } + + return $file_content; +} + +sub var_to_file +{ # file name, content + open(my $fout, ">$_[0]") or die "Can't open $_[0] to write\n"; + { + print $fout $_[1]; + close($fout); + } +} diff --git a/demos/build_report.pl b/demos/build_report.pl new file mode 100644 index 00000000..3aba44c6 --- /dev/null +++ b/demos/build_report.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +use Scalar::Util qw(looks_like_number); + +$" = "\n"; # change list separator + +$keil_size = "Program Size:.+"; + +%report_patterns = +( #toolchain, pattern-list + 'keil' => ['Build target \'(.+)\'', '(\d+ Error.+\d+ Warning)', $keil_size . 'Code=(\d+)', $keil_size . 'RO-data=(\d+)', $keil_size . 'RW-data=(\d+)', $keil_size . 'ZI-data=(\d+)'], + 'iar' => ['Building configuration.+ (.+)', 'Total number of (.+)', '((\s+\d+){4})\s+[0-9a-f]+'], + 'xpresso' => ['Build of configuration (\S+) ', '(Finished) building target', '((\s+\d+){4})\s+[0-9a-f]+'] +); + +@report_file_list = ; +#print "@report_file_list"; die; + +open $freport, ">build_report.txt" or die "cannot open build_reprot.txt"; + +foreach (@report_file_list) +{ + /build_all_([^_]+)_/; + build_report($_, $1); +} + +sub build_report +{ + my $report_file = $_[0]; + my $toolchain = $_[1]; + + my @pattern = @{$report_patterns{$toolchain}}; + + open $report_handle, $report_file or die "cannot open $report_file"; + + $report_file =~ /build_all_(.+).txt/; + + print $freport "--------------------------------------------------------------------\n"; + printf $freport "%-25s", $1; + printf $freport "%13s", "" if $toolchain eq 'iar'; + print $freport " text data bss dec" if $toolchain eq 'xpresso' or $toolchain eq 'iar'; + print $freport " Code RO RW ZI" if $toolchain eq 'keil'; + print $freport "\n--------------------------------------------------------------------"; + + while( my $line = <$report_handle> ) + { + local $/ = "\r\n"; + chomp $line; + + foreach (@pattern) + { + if ($line =~ /$_/) + { + my $fmat = ($_ eq $pattern[0]) ? "\n%-25s" : "%s "; + $fmat = "%6s " if $toolchain eq 'keil' and looks_like_number($1); + printf $freport $fmat, $1; + } + } + } + + close $report_handle; + + print $freport "\n\n"; +} \ No newline at end of file diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index a7b5210e..604b89f7 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -49,6 +49,7 @@ #include "common/common.h" +#if MODE_HOST_SUPPORTED // Max number of endpoints per device enum { HCD_MAX_ENDPOINT = TUSB_CFG_HOST_HUB + TUSB_CFG_HOST_HID_KEYBOARD + TUSB_CFG_HOST_HID_MOUSE + TUSB_CFG_HOST_HID_GENERIC + @@ -56,6 +57,7 @@ enum { HCD_MAX_XFER = HCD_MAX_ENDPOINT*2, }; +#endif //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF