动态储存不足 text section exceeds available space in board-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 635|回复: 2

[未解决] 动态储存不足 text section exceeds available space in board

[复制链接]
发表于 2022-1-16 15:47 | 显示全部楼层 |阅读模式
本帖最后由 cheeks 于 2022-1-16 19:37 编辑

usb调试器
我该如何解决这个问题  XD
Arduino Leonardo

text section exceeds available space in board
项目使用了 31778 字节,占用了 (110%) 程序存储空间。最大为 28672 字节。
全局变量使用了1719字节,(67%)的动态内存,余留841字节局部变量。最大为2560字节。
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
为开发板 Arduino Leonardo 编译时出错。


  1. #include <Keyboard.h>
  2. #include <SPI.h>
  3. #include <SD.h>
  4. #include <Wire.h>
  5. #include <Adafruit_GFX.h>
  6. #include <Adafruit_SSD1306.h>
  7. Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

  8. File myFile;
  9. boolean first = true;
  10. String fileName="payload.txt";
  11. int SD_mode = 0;
  12. Sd2Card card;
  13. SdVolume volume;
  14. SdFile root;


  15. String bufferStr = "";
  16. String last = "";
  17. int defaultDelay = 0;



  18. int key1 = 8;
  19. int key2 = 6;
  20. int key3 = 12 ;
  21. int key4 = 4;
  22. int LedA = 9;
  23. int LedB = 10;
  24. int enablestorage = 7;
  25. int keystatus = 0;
  26. int delaytime = 60;



  27. int SW2 = A5;
  28. int JoystickPush = A4;
  29. int JoystickRight = 5;
  30. int JoystickLeft = 11;
  31. int Buzzer = 13;
  32. const int chipSelect = PIN_SPI_SS;



  33. int modeSelect()
  34. {
  35.   display.println("Payload Select");
  36.   display.println("1.se_mode");
  37.   display.println("2.duck_mode");
  38.   display.println("3.wifi_mode");
  39.   display.display();
  40.   int mode = 2;
  41.   while (!digitalRead(SW2))
  42.   {
  43.     if (digitalRead(JoystickLeft))
  44.     {
  45.       delay(10);
  46.       if (digitalRead(JoystickRight))
  47.       {
  48.        mode = 1;
  49.       }
  50.       else{}
  51.     }
  52.     else if (digitalRead(JoystickRight))
  53.     {
  54.       delay(10);
  55.       if (digitalRead(JoystickRight))
  56.       {
  57.         mode= 3;
  58.       }
  59.       else{}
  60.     }
  61.     else if(digitalRead(JoystickPush))
  62.     {
  63.      delay(10);
  64.       if (digitalRead(JoystickPush))
  65.       {
  66.         mode= 2;
  67.       }
  68.       else{}
  69.     }  
  70.     display.clearDisplay();
  71.     display.println("Payload Select");
  72.     if (mode == 1)
  73.     {
  74.       display.println("1.SE_MODE");
  75.     }
  76.     else
  77.     {
  78.       display.println("1.se_mode");
  79.     }
  80.     if (mode == 2)
  81.     {
  82.       display.println("2.DUCK_MODE");
  83.     }
  84.     else
  85.     {
  86.       display.println("2.duck_mode");
  87.     }
  88.     if (mode == 3)
  89.     {
  90.       display.println("3.WIFI_MODE");
  91.     }
  92.     else
  93.     {
  94.       display.println("3.wifi_mode");
  95.     }
  96.     display.display();
  97.   }
  98.   return mode;
  99. }


  100. void buzzer(int times)
  101. {
  102.   for (int i = 1; i <= times; i++)
  103.   {
  104.     digitalWrite(Buzzer, HIGH);
  105.     delay(100);
  106.     digitalWrite(Buzzer, LOW);
  107.     delay(200);
  108.   }
  109. }
  110. void led(bool led1, bool led2)
  111. {
  112.   digitalWrite(LedA, led1);
  113.   digitalWrite(LedB, led2);
  114. }
  115. void breakpoint()
  116. {
  117.   while(!digitalRead(JoystickPush))
  118.   {
  119.     delay(30);
  120.   }
  121. }

  122. void runPayload(int mode,int Payload_X)
  123. {
  124.     if (mode == 3)
  125.     {
  126.       wifiduck();
  127.     }
  128.     else  if(mode==2)
  129.     {
  130.       const char x[]={Payload_X};
  131.       fileName.replace("payload",x);
  132.       fileName.replace(fileName,".txt");
  133.       rubberducky(fileName);
  134.     }
  135.   {
  136.     switch(Payload_X)
  137.   {
  138.     case 0:
  139.     {
  140.       //payload0
  141.       break;
  142.     }
  143.     case 1:
  144.     {
  145.       //payload1
  146.       break;
  147.     }
  148.     case 2:
  149.     {
  150.       //payload2
  151.       break;
  152.     }
  153.     case 3:
  154.     {
  155.       //payload3
  156.       break;
  157.     }
  158.     case 4:
  159.     {
  160.       //payload4
  161.       break;
  162.     }
  163.     case 5:
  164.     {
  165.       //payload5
  166.       break;
  167.     }
  168.     case 6:
  169.     {
  170.       //payload6
  171.       break;
  172.     }
  173.     case 7:
  174.     {
  175.       //payload7
  176.       break;
  177.     }
  178.     case 8:
  179.     {
  180.       //payload8
  181.       break;
  182.     }
  183.     case 9:
  184.     {
  185.       //payload9
  186.       break;
  187.     }
  188.     case 10:
  189.     {
  190.       //payload10
  191.       break;
  192.     }
  193.     case 11:
  194.     {
  195.       //payload11
  196.       break;
  197.     }
  198.     case 12:
  199.     {
  200.       //payload12
  201.       break;
  202.     }
  203.     case 13:
  204.     {
  205.       //payload13
  206.       break;
  207.     }
  208.     case 14:
  209.     {
  210.       //payload14
  211.       break;
  212.     }
  213.     case 15:
  214.     {
  215.       //payload15
  216.       break;
  217.     }
  218.   }
  219.   }
  220. }



  221. void rubberducky(String duckyScript)
  222. {
  223.   
  224.   if (!SD.begin(PIN_SPI_SS)) {
  225.     return;
  226.   }

  227.   myFile = SD.open(duckyScript);
  228.   if (myFile) {
  229.     Keyboard.begin();

  230.     String line = "";
  231.     while (myFile.available()) {
  232.       char m = myFile.read();
  233.       if (m == '\n') {
  234.         Line(line);
  235.         line = "";
  236.       }
  237.       else if ((int) m != 13)
  238.       {
  239.         line += m;
  240.       }
  241.     }
  242.     Line(line);

  243.     myFile.close();
  244.   } else {

  245.   }

  246.   Keyboard.end();
  247. }

  248. void wifiduck()
  249. {
  250.   Keyboard.begin();
  251.   while (1)
  252.   {
  253.     if(Serial1.available()) {
  254.     bufferStr = Serial1.readStringUntil("END");
  255.   }
  256.   
  257.   if(bufferStr.length() > 0){
  258.    
  259.     bufferStr.replace("\r","\n");
  260.     bufferStr.replace("\n\n","\n");
  261.    
  262.     while(bufferStr.length() > 0){
  263.       int latest_return = bufferStr.indexOf("\n");
  264.       if(latest_return == -1){
  265.         Line(bufferStr);
  266.         bufferStr = "";
  267.       } else{
  268.         Line(bufferStr.substring(0, latest_return));
  269.         last=bufferStr.substring(0, latest_return);
  270.         bufferStr = bufferStr.substring(latest_return + 1);
  271.       }
  272.     }
  273.    
  274.     bufferStr = "";
  275.     Serial1.write(0x99);
  276.   }
  277.   }
  278. }

  279. void Line(String l)
  280. {
  281.   int space_1 = l.indexOf(" ");
  282.   if (space_1 == -1)
  283.   {
  284.     Press(l);
  285.   }
  286.   else if (l.substring(0, space_1) == "STRING")
  287.   {
  288.     Keyboard.print(l.substring(space_1 + 1));
  289.   }
  290.   else if (l.substring(0, space_1) == "DELAY")
  291.   {
  292.     int delaytime = l.substring(space_1 + 1).toInt();
  293.     delay(delaytime);
  294.   }
  295.   else if (l.substring(0, space_1) == "REM") {}
  296.   else
  297.   {
  298.     String remain = l;

  299.     while (remain.length() > 0)
  300.     {
  301.       int latest_space = remain.indexOf(" ");
  302.       if (latest_space == -1)
  303.       {
  304.         Press(remain);
  305.         remain = "";
  306.       }
  307.       else
  308.       {
  309.         Press(remain.substring(0, latest_space));
  310.         remain = remain.substring(latest_space + 1);
  311.       }
  312.       delay(5);
  313.     }
  314.   }

  315.   Keyboard.releaseAll();
  316. }


  317. void Press(String b)
  318. {
  319.   if(b.length() == 1) Keyboard.press(char(b[0]));
  320.   else if (b.equals("ENTER")) Keyboard.press(KEY_RETURN);
  321.   else if (b.equals("CTRL")) Keyboard.press(KEY_LEFT_CTRL);
  322.   else if (b.equals("SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
  323.   else if (b.equals("ALT")) Keyboard.press(KEY_LEFT_ALT);
  324.   else if (b.equals("GUI")) Keyboard.press(KEY_LEFT_GUI);
  325.   else if (b.equals("UP") || b.equals("UPARROW")) Keyboard.press(KEY_UP_ARROW);
  326.   else if (b.equals("DOWN") || b.equals("DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
  327.   else if (b.equals("LEFT") || b.equals("LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
  328.   else if (b.equals("RIGHT") || b.equals("RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
  329.   else if (b.equals("DELETE")) Keyboard.press(KEY_DELETE);
  330.   else if (b.equals("PAGEUP")) Keyboard.press(KEY_PAGE_UP);
  331.   else if (b.equals("PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
  332.   else if (b.equals("HOME")) Keyboard.press(KEY_HOME);
  333.   else if (b.equals("ESC")) Keyboard.press(KEY_ESC);
  334.   else if (b.equals("INSERT")) Keyboard.press(KEY_INSERT);
  335.   else if (b.equals("TAB")) Keyboard.press(KEY_TAB);
  336.   else if (b.equals("END")) Keyboard.press(KEY_END);
  337.   else if (b.equals("CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
  338.   else if (b.equals("F1")) Keyboard.press(KEY_F1);
  339.   else if (b.equals("F2")) Keyboard.press(KEY_F2);
  340.   else if (b.equals("F3")) Keyboard.press(KEY_F3);
  341.   else if (b.equals("F4")) Keyboard.press(KEY_F4);
  342.   else if (b.equals("F5")) Keyboard.press(KEY_F5);
  343.   else if (b.equals("F6")) Keyboard.press(KEY_F6);
  344.   else if (b.equals("F7")) Keyboard.press(KEY_F7);
  345.   else if (b.equals("F8")) Keyboard.press(KEY_F8);
  346.   else if (b.equals("F9")) Keyboard.press(KEY_F9);
  347.   else if (b.equals("F10")) Keyboard.press(KEY_F10);
  348.   else if (b.equals("F11")) Keyboard.press(KEY_F11);
  349.   else if (b.equals("F12")) Keyboard.press(KEY_F12);
  350.   else if (b.equals("SPACE")) Keyboard.press(' ');
  351. }

  352. void setup()
  353. {

  354.   pinMode(key1, INPUT);
  355.   pinMode(key2, INPUT);
  356.   pinMode(key3, INPUT);
  357.   pinMode(key4, INPUT);
  358.   pinMode(LedA, OUTPUT);
  359.   pinMode(LedB, OUTPUT);
  360.   pinMode(enablestorage, OUTPUT);

  361.   pinMode(SW2, INPUT);
  362.   pinMode(JoystickPush, INPUT);
  363.   pinMode(JoystickRight, INPUT);
  364.   pinMode(JoystickLeft, INPUT);
  365.   pinMode(Buzzer, OUTPUT);
  366.   //对外设进行初始化
  367.   digitalWrite(enablestorage, HIGH);
  368.   digitalWrite(LedA, LOW);
  369.   digitalWrite(LedB, LOW);

  370.   Serial1.begin(57200);
  371.   //开启串口
  372.   delay(100);
  373.   display.begin(SSD1306_SWITCHCAPVCC,0x3C);
  374.   display.display();
  375.   delay(1000);
  376.   display.clearDisplay();
  377.   display.display();
  378.   display.setTextColor(WHITE);
  379.   display.setTextSize(1);
  380.   display.setCursor(0,0);
  381.    
  382.   int mode=modeSelect();
  383.   int k1 = digitalRead(key1);
  384.   int k2 = digitalRead(key2);
  385.   int k3 = digitalRead(key3);
  386.   int k4 = digitalRead(key4);
  387.   int payload = k1 * 1 + k2 * 2 + k3 * 4 + k4 * 8;
  388.   runPayload(mode,payload);

  389.    //attachInterrupt(digitalPinToInterrupt(SW2), breakpoint, HIGH);
  390. }

  391. void loop()
  392. {
  393. }
复制代码


发表于 2022-1-17 08:13 | 显示全部楼层
Adafruit_GFX.h + SD 的支持,占用改代码太多了,放不下了
换一个板子吧
发表于 2022-1-16 16:28 | 显示全部楼层
换ESP32-S2
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 16:05 , Processed in 0.071021 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表