15
15
16
16
By default, no locking is performed. User have to manually enable the flags that
17
17
turn on the locking. Furthermore, user have to send a SPACE character on serial
18
- console when prompted to do any locking.
19
- Default settings use ATSHA204 on pin 7.
18
+ console when prompted to do any locking. On boards that does not provide UART
19
+ input it is possible to configure the sketch to skip this confirmation.
20
+ Default settings use ATSHA204 on pin 17 (A3).
20
21
*/
21
22
#include < sha204_library.h>
22
23
#include < sha204_lib_return_codes.h>
23
24
24
25
// The pin the ATSHA204 is connected on
25
- #define ATSHA204_PIN 7
26
+ #define ATSHA204_PIN 17 // A3
26
27
27
28
// Uncomment this to enable locking the configuration zone.
28
29
// *** BE AWARE THAT THIS PREVENTS ANY FUTURE CONFIGURATION CHANGE TO THE CHIP ***
44
45
// Uncomment this to skip key generation and use 'user_key_data' as key instead.
45
46
// #define USER_KEY_DATA
46
47
48
+ // Uncomment this for boards that lack UART
49
+ // IMPORTANT: No confirmation will be required for locking any zones with this
50
+ // configuration!
51
+ // Also, key generation is not permitted in this mode as there is no way of
52
+ // presenting the generated key.
53
+ // #define SKIP_UART_CONFIRMATION
54
+
55
+ #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY_DATA)
56
+ #error You have to define USER_KEY_DATA for boards that does not have UART
57
+ #endif
58
+
47
59
#ifdef USER_KEY_DATA
48
- const uint8_t user_key_data[32 ] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
49
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
50
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
51
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
60
+ const uint8_t user_key_data[32 ] = {
61
+ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
62
+ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
63
+ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
64
+ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
65
+ };
52
66
#endif
53
67
54
68
const int sha204Pin = ATSHA204_PIN;
@@ -727,6 +741,7 @@ void setup()
727
741
728
742
#ifdef LOCK_CONFIGURATION
729
743
// Purge serial input buffer
744
+ #ifndef SKIP_UART_CONFIRMATION
730
745
while (Serial.available ())
731
746
{
732
747
Serial.read ();
@@ -735,6 +750,7 @@ void setup()
735
750
736
751
while (Serial.available () == 0 );
737
752
if (Serial.read () == ' ' )
753
+ #endif // not SKIP_UART_CONFIRMATION
738
754
{
739
755
Serial.println (F (" Locking configuration..." ));
740
756
@@ -773,10 +789,12 @@ void setup()
773
789
}
774
790
}
775
791
}
792
+ #ifndef SKIP_UART_CONFIRMATION
776
793
else
777
794
{
778
795
Serial.println (F (" Unexpected answer. Skipping lock." ));
779
796
}
797
+ #endif // not SKIP_UART_CONFIRMATION
780
798
#else // LOCK_CONFIGURATION
781
799
Serial.println (F (" Dry-run. Configuration not locked. Define LOCK_CONFIGURATION to lock for real." ));
782
800
#endif
@@ -793,7 +811,7 @@ void setup()
793
811
#else
794
812
#ifdef USER_KEY_DATA
795
813
memcpy (key, user_key_data, 32 );
796
- Serial.print (F (" Using this user supplied key: " ));
814
+ Serial.println (F (" Using this user supplied key:" ));
797
815
#else
798
816
// Retrieve random value to use as key
799
817
ret_code = sha204.sha204m_random (tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
@@ -817,11 +835,14 @@ void setup()
817
835
#endif
818
836
for (int i=0 ; i<32 ; i++)
819
837
{
838
+ Serial.print (" 0x" );
820
839
if (key[i] < 0x10 )
821
840
{
822
841
Serial.print (' 0' ); // Because Serial.print does not 0-pad HEX
823
842
}
824
843
Serial.print (key[i], HEX);
844
+ if (i < 31 ) Serial.print (' ,' );
845
+ if (!((i+1 ) % 8 )) Serial.println ();
825
846
}
826
847
Serial.println ();
827
848
@@ -842,13 +863,15 @@ void setup()
842
863
if (lockValue != 0x00 )
843
864
{
844
865
#ifdef LOCK_DATA
866
+ #ifndef SKIP_UART_CONFIRMATION
845
867
while (Serial.available ())
846
868
{
847
869
Serial.read ();
848
870
}
849
871
Serial.println (F (" Send SPACE character to lock data..." ));
850
872
while (Serial.available () == 0 );
851
873
if (Serial.read () == ' ' )
874
+ #endif // not SKIP_UART_CONFIRMATION
852
875
{
853
876
// Correct sequence, resync chip
854
877
ret_code = sha204.sha204c_resync (SHA204_RSP_SIZE_MAX, rx_buffer);
@@ -907,10 +930,12 @@ void setup()
907
930
}
908
931
}
909
932
}
933
+ #ifndef SKIP_UART_CONFIRMATION
910
934
else
911
935
{
912
936
Serial.println (F (" Unexpected answer. Skipping lock." ));
913
937
}
938
+ #endif // not SKIP_UART_CONFIRMATION
914
939
#else // LOCK_DATA
915
940
Serial.println (F (" Dry-run. Data not locked. Define LOCK_DATA to lock for real." ));
916
941
#endif
0 commit comments