diff --git a/README.md b/README.md index 5ccfc30..ba55511 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,17 @@ This is a collection of target code that can be used with the [PicoEMP](https://github.com/newaetech/chipshouter-picoemp) tool. This is test code that can be used with target boards. -Adafruit M0 - Code for that board. +# Adafruit M0 - Code for that board. + +# RP2040 - Raspberry Pi Pico Target Glitch + +Add the following board repos to your Arduino IDE: +https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json +https://electroniccats.github.io/Arduino_Boards_Index/package_electroniccats_index.json +https://raw.githubusercontent.com/sparkfun/Arduino_Boards/main/IDE_Board_Manager/package_sparkfun_index.json +https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json +http://adafruit.github.io/arduino-board-index/package_adafruit_index.json +https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json ## License @@ -10,3 +20,6 @@ This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Inter [cc-by-sa]: http://creativecommons.org/licenses/by-sa/3.0/ [cc-by-sa-image]: https://licensebuttons.net/l/by-sa/3.0/88x31.png [cc-by-sa-shield]: https://img.shields.io/badge/License-CC%20BY--SA%203.0-lightgrey.svg + + + diff --git a/RP2040-Glitch/RP2040-Glitch.ino b/RP2040-Glitch/RP2040-Glitch.ino new file mode 100644 index 0000000..f92c8fc --- /dev/null +++ b/RP2040-Glitch/RP2040-Glitch.ino @@ -0,0 +1,99 @@ + +int Reset = D2; +int GREEN_LED = D0; +int RED_LED = D1; + +void setup() { + // put your setup code here, to run once: + digitalWrite(Reset, HIGH); + delay(200); + pinMode(Reset, OUTPUT); + Serial.begin(115200); // open the serial port at 115200 + Serial.print("Serial port setup\n"); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + pinMode(GREEN_LED, OUTPUT); + pinMode(RED_LED, OUTPUT); + digitalWrite(GREEN_LED, HIGH); + delay(1000); + digitalWrite(LED_BUILTIN, LOW); + digitalWrite(GREEN_LED, LOW); + digitalWrite(RED_LED, HIGH); +} + +void loop() +{ +#define RUN_CNT 1000 +#define OUTER_LOOP_CNT 1000 +#define INNER_LOOP_CNT 1000 + +//Serial.print("Booting into for loop...\n"); +//Serial.print("Booting into for loop...\n"); +//Serial.print("Booting into for loop...\n"); +//Serial.print("Booting into for loop...\n"); +Serial.print("Booting into for loop...\n"); + + digitalWrite(LED_BUILTIN, LOW); + volatile uint32_t i, j; + volatile uint32_t cnt; + uint32_t blink_status = 1; + uint32_t b = 0; + uint32_t run_cnt = 0; + uint32_t glitch_cnt = 0; + //Serial.print("\nCONNECTED 115200\n"); + //Serial.print("W. O. P. R. Login: \n"); + for (run_cnt = 0; run_cnt < RUN_CNT; run_cnt++) { + //Serial.print("starting loop..."); + //Serial.println(run_cnt); + //run led on + //Serial.print("\nCONNECTED 115200\n"); + //Serial.print("W. O. P. R. Login: \n"); + /*digitalWrite(13, HIGH); + delay(500); + digitalWrite(13, LOW); + delay(500); + digitalWrite(13, HIGH); + delay(500); + digitalWrite(13, LOW); + delay(500); + blink_status ^= 1;*/ + cnt = 0; + for ( i = 0; i < OUTER_LOOP_CNT; i++) { + for ( j = 0; j < INNER_LOOP_CNT; j++) { + cnt++; + } + } + + //Serial.print("Looking for a glitch...\n"); + //look for glitch + /*Serial.print("Outer Loop CNT: "); + Serial.println(i); + Serial.print("Inner Loop CNT: "); + Serial.println(j); + Serial.print("Total Loop Count: "); + Serial.println(cnt);*/ + if (i != OUTER_LOOP_CNT || j != INNER_LOOP_CNT || + cnt != (OUTER_LOOP_CNT * INNER_LOOP_CNT) ) { + /*Serial.print("GEETINGS PROFESSOR FALKEN.\n"); + Serial.print("\n"); + Serial.print("HOW ARE YOU FEELING TODAY?\n");*/ + Serial.print("Glitched!\n"); + digitalWrite(RED_LED, LOW); + //if glitched, reset the run count and blink the fault LED + for( b = 0 ; b < 16; b++) + { + digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(GREEN_LED, HIGH); + delay(300); + digitalWrite(LED_BUILTIN, LOW); + digitalWrite(GREEN_LED, LOW); + delay(300); + } + run_cnt = 0; + digitalWrite(Reset, LOW); + digitalWrite(RED_LED, HIGH); + delay(100); + digitalWrite(Reset, HIGH); + } + } +}