sub usage {
print <<EOF;
-usage: spi_flash16bit_slaves.pl <--endpoint|e=0xYYYY> <--chain|c=N> [--register=number] [--data=number]
-
-examples: spi_flash16bit_slaves.pl -e 0x1212 -c 0 -x time # reads the compile time of 0x1212, chain 0
- spi_flash16bit_slaves.pl -e 0x1212 -c 0 -x pwm --channel=1 # reads the threshold setting of channel 1
- spi_flash16bit_slaves.pl -e=0x1212 -c=0 -x=inputenable --data=0xa55a # disables some channels
- spi_flash16bit_slaves.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert -d 0xff # sets the dischargedelayinvert bits
- spi_flash16bit_slaves.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert # reads the dischargedelayinvert register
- spi_flash16bit_slaves.pl -e 0x1212 -c 0 --enablecfgflash=1 # enables the access to the config-flash
- spi_flash16bit_slaves.pl --endpoint=0x1212 --chain=0 --dumpcfgflash > flash_dump.txt
+usage: spi_slave.pl <--endpoint|e=0xYYYY> <--chain|c=N> [--register=number] [--data=number]
+
+examples: spi_slave.pl -e 0x1212 -c 0 -x time # reads the compile time of 0x1212, chain 0
+ spi_slave.pl -e 0x1212 -c 0 -x pwm --channel=1 # reads the threshold setting of channel 1
+ spi_slave.pl -e=0x1212 -c=0 -x=inputenable --data=0xa55a # disables some channels
+ spi_slave.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert -d 0xff # sets the dischargedelayinvert bits
+ spi_slave.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert # reads the dischargedelayinvert register
+ spi_slave.pl -e 0x1212 -c 0 --enablecfgflash=1 # enables the access to the config-flash
+ spi_slave.pl --endpoint=0x1212 --chain=0 --dumpcfgflash > flash_dump.txt
Some of the commands can also be used directly, i.e. '-rr=0x12' instead of '-x=rr -register=0x12'
usage();
}
+if (defined $enablecfgflash and (defined $erasecfgflash or defined $dumpcfgflash or defined $writecfgflash or defined $verifycfgflash)) {
+ die("for security reasons is not allowed to enable cfg flash and to use it in one single command");
+}
+
$endpoint = &conv_input_string_to_number($endpoint, "endpoint", "hex");
$chain = &conv_input_string_to_number($chain, "chain");
$register = &conv_input_string_to_number($register, "register") if (defined $register);
###############################################################################
+sub checkcfgflash {
+ my $b = sendcmd(0x5C<<$REGNR | $READ);
+ foreach my $e (sort keys %$b) {
+ printf(" %x ",$b->{$e}&0xfff);
+ if (($b->{$e}&0xfff) ne 0x101) {
+ die "config flash not enabled";
+ }
+ }
+}
+
sub enableccfgflash {
+ sendcmd(0x51<<$REGNR | $WRITE | 0x8);
+ sendcmd(0x50<<$REGNR | $WRITE | 0x0);
+ sendcmd(0x5C<<$REGNR | $WRITE | 0x103);
+ sendcmd(0x5C<<$REGNR | $WRITE | 0x105);
sendcmd(0x5C<<$REGNR | $WRITE | 0x101);
}
sub enableuserflash {
+ sendcmd(0x51<<$REGNR | $WRITE | 0x8);
+ sendcmd(0x50<<$REGNR | $WRITE | 0x0);
sendcmd(0x5C<<$REGNR | $WRITE | 0x100);
}
###############################################################################
if ($execute eq "dumpcfgflash" | defined $dumpcfgflash) {
- enableccfgflash();
+ #enableccfgflash();
+ checkcfgflash();
my $b = sendcmd(0xFF<<$REGNR | $READ);
my $version = $b->{$endpoint};
my $max = 0x23ff;
}
sub erasecfgflash {
- enableccfgflash();
+ #enableccfgflash();
+ checkcfgflash();
while (flash_is_busy()) {
printf(" busy - try again\n");
usleep(300000);
}
if ($execute eq "writecfgflash" | defined $writecfgflash) {
+ checkcfgflash();
if (!defined($filename)) {$filename=$writecfgflash;}
if (!defined $filename) {
die "for the command writecfgflash an option or --filename is missing.\n";
}
if ($execute eq "verifycfgflash" | defined $verifycfgflash) {
+ checkcfgflash();
printf("Verify with file: %s \n", $filename);
if (!defined($filename)) {$filename=$verifycfgflash;}
if (!defined $filename) {