polymech - fw latest | web ui

This commit is contained in:
2026-04-18 10:31:24 +02:00
parent a105c5ee85
commit ab2ff368a6
2972 changed files with 441416 additions and 372 deletions
@@ -0,0 +1,18 @@
#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else // __ARM__
extern char *__brkval;
#endif // __arm__
int freeMemory() {
char top;
#ifdef __arm__
return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
return &top - __brkval;
#else // __arm__
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif // __arm__
}
@@ -0,0 +1,10 @@
// memoryFree header
// From http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720/15
// ...written by user "mem".
#ifndef MEMORY_FREE_H
#define MEMORY_FREE_H
int freeMemory();
#endif
@@ -0,0 +1,69 @@
# Arduino library for Measuring and use less Free RAM
This Library was written for the Arduino to both measure available RAM and use less RAM
Did you know that that the Arduinos built in serial.print() of a constant char array
<pre>Serial.Print(“Hello”);</pre>
actually allocates the “Hello” into a unique space of RAM, not just Flash. Hence every such occurrence of serial print of a constant string uses more and more RAM. Until you are out. And there is only 2K of RAM on the ATmega328. This is likely why you dont see many examples with a lot of debug prints.
That said there is hope, use the "F()" funciton. Now natively supported in the IDE > 1.0.0. Same concept applies.
Previously, I have both been suggested and found several work-a-rounds all similar in forcing the char array to be read directly from memory at print time. This can be done using some not as obvious AVR Libc commands provided with avr/pgmspace.h. Where teh pgmStrToRAM library provides a simplified library to do such.
Additionally the companion library MemoryFree is very useful in determining how much RAM is being used or left. Don't wonder or guess. I find it good practice to always dump it during setup to see the global static usage. Just in case.
## Installation
* Download the Library https://github.com/mpflaga/Arduino-MemoryFree.git
* It will contain the following to be placed into corresponding library directories:
<pre>.\pgmStrToRAM\MemoryFree.cpp
.\pgmStrToRAM\MemoryFree.h
.\pgmStrToRAM\pgmStrToRAM.cpp
.\pgmStrToRAM\pgmStrToRAM.h
.\pgmStrToRAM\examples\BareMinimum\BareMinimum.ino</pre>
* Place the pgmStrToRAM directory folder and contents into your arduino library folder,
if the libraries folder does not exist - create it first!
* Restart the IDE
## Example Usage
BareMinimum.ino is a example of usage that both demonstrates how to print out the current available memory at the time the freeMemory() is executed along with how to using getPSTR("hello") to put the "hello" into Flash without using any static RAM.
include the desired library(s) at the beginning of sketch
<pre>#include &lt;MemoryFree.h&gt;
#include &lt;pgmStrToRAM.h&gt;</pre>
then at the desired location
<pre> Serial.println(getPSTR("Old way to force String to Flash"));
Serial.println(F("New way to force String to Flash"));
Serial.println(F("Free RAM = "));</pre>
Please note that the memory is dynamic and always changing. Where Static Global Variables and Members&nbsp; create a base minimum of usage that can typically be read at setup(). When functions and routines dive deeper into the stack more memory will be dynamically consumed and released. So there needs to be a margin from completely running out.
## Back Ground
Based on my tests I see that Serial.Print of actual variables e.g.
Serial.Print( (int8_t) value, DEC);
Does not increase RAM usage for each occurrence.
However it would appear that overloaded object member of an char array (e.i. const string) creates a unique location in static RAM and definitely does not share it. As one might think or expect.
A more indepth look at avr-libc and its features can be found at http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
## Alternatives
It is worth noting that there are many other sources of equivalent methods. Although note widely known. One such alternative is "SdFATlib" found at http://code.google.com/p/sdfatlib/ library file called SdFatUtil.h
<pre>#include&lt;SdFat.h&gt; // required
#include &lt;SdFatUtil.h&gt;
PgmPrint("Free RAM: ");
Serial.println(FreeRam());</pre>
## Gratitude
Special Thanks to GreyGnome, William Greiman and others for providing the example this is based off.
@@ -0,0 +1,17 @@
#include <MemoryFree.h>;
#include <pgmStrToRAM.h>; // not needed for new way. but good to have for reference.
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(getPSTR("Old way to force String to Flash")); // forced to be compiled into and read
Serial.println(F("New way to force String to Flash")); // forced to be compiled into and read
Serial.println(F("Free RAM = ")); //F function does the same and is now a built in library, in IDE > 1.0.0
Serial.println(freeMemory(), DEC); // print how much RAM is available.
// print how much RAM is available.
}
void loop() {
// put your main code here, to run repeatedly:
}
@@ -0,0 +1,166 @@
#######################################
# Syntax Coloring Map For Arduino_PortentaBreakout
#######################################
# Class (KEYWORD1)
#######################################
BreakoutCarrierClass KEYWORD1
Breakout KEYWORD1
breakoutPin KEYWORD1
I2C_0 KEYWORD1
I2C_1 KEYWORD1
I2C_2 KEYWORD1
UART0 KEYWORD1
UART1 KEYWORD1
UART2 KEYWORD1
UART3 KEYWORD1
SPI_0 KEYWORD1
RTClock KEYWORD1
Timestamp KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
pinMode KEYWORD2
digitalWrite KEYWORD2
digitalRead KEYWORD2
setFromUnixTimestamp KEYWORD2
getUnixTimestamp KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
SPI0_CS LITERAL1
SPI0_CK LITERAL1
SPI0_MISO LITERAL1
SPI0_MOSI LITERAL1
SPI1_CS LITERAL1
SPI1_CK LITERAL1
SPI1_MISO LITERAL1
SPI1_MOSI LITERAL1
UART2_TX LITERAL1
UART2_RX LITERAL1
UART2_RTS LITERAL1
UART2_CTS LITERAL1
UART3_TX LITERAL1
UART3_RX LITERAL1
UART3_RTS LITERAL1
UART3_CTS LITERAL1
PCIE_TXN LITERAL1
PCIE_TXP LITERAL1
PCIE_RXN LITERAL1
PCIE_RXP LITERAL1
PCIE_CKN LITERAL1
PCIE_CKP LITERAL1
I2S_SDO LITERAL1
I2S_SDI LITERAL1
I2S_WS LITERAL1
I2S_CK LITERAL1
SAI_D1 LITERAL1
SAI_D0 LITERAL1
SAI_FS LITERAL1
SAI_SCK LITERAL1
CAMERA_D0P LITERAL1
CAMERA_D0N LITERAL1
CAMERA_D1P LITERAL1
CAMERA_D1N LITERAL1
CAMERA_D2P LITERAL1
CAMERA_D2N LITERAL1
CAMERA_D3P LITERAL1
CAMERA_D3N LITERAL1
CAMERA_CKP LITERAL1
CAMERA_CKN LITERAL1
CAMERA_HS LITERAL1
PDM_D1 LITERAL1
PDM_D0 LITERAL1
PDM_CK LITERAL1
SPDIF_RX LITERAL1
SPDIF_TX LITERAL1
USBHS_ID LITERAL1
USBHS_DN LITERAL1
USBHS_DP LITERAL1
USBFS_ID LITERAL1
USBFS_DN LITERAL1
USBFS_DP LITERAL1
SD_WP LITERAL1
SD_CD LITERAL1
SD_D0 LITERAL1
SD_D3 LITERAL1
SD_CMD LITERAL1
SD_D2 LITERAL1
SD_CLK LITERAL1
SD_D1 LITERAL1
SD_VSD LITERAL1
ETHERNET_DP LITERAL1
ETHERNET_DN LITERAL1
ETHERNET_CN LITERAL1
ETHERNET_CP LITERAL1
ETHERNET_BN LITERAL1
ETHERNET_BP LITERAL1
ETHERNET_AN LITERAL1
ETHERNET_AP LITERAL1
ETHERNET_L2 LITERAL1
ETHERNET_L1 LITERAL1
UART0_TX LITERAL1
UART0_RX LITERAL1
UART0_RTS LITERAL1
UART0_CTS LITERAL1
UART1_TX LITERAL1
UART1_RX LITERAL1
UART1_RTS LITERAL1
UART1_CTS LITERAL1
DISPLAY_D3P LITERAL1
DISPLAY_D3N LITERAL1
DISPLAY_D2P LITERAL1
DISPLAY_D2N LITERAL1
DISPLAY_D1P LITERAL1
DISPLAY_D1N LITERAL1
DISPLAY_D0P LITERAL1
DISPLAY_D0N LITERAL1
DISPLAY_CLKP LITERAL1
DISPLAY_CLKN LITERAL1
CAN0_TX LITERAL1
CAN0_RX LITERAL1
CAN1_TX LITERAL1
CAN1_RX LITERAL1
I2C_SDA_1 LITERAL1
I2C_SCL_1 LITERAL1
I2C_SDA_0 LITERAL1
I2C_SCL_0 LITERAL1
I2C_SDA_2 LITERAL1
I2C_SCL_2 LITERAL1
GPIO_0 LITERAL1
GPIO_1 LITERAL1
GPIO_2 LITERAL1
GPIO_3 LITERAL1
GPIO_4 LITERAL1
GPIO_5 LITERAL1
GPIO_6 LITERAL1
ANALOG_REFN LITERAL1
ANALOG_REFP LITERAL1
ANALOG_A7 LITERAL1
ANALOG_A6 LITERAL1
ANALOG_A5 LITERAL1
ANALOG_A4 LITERAL1
ANALOG_A3 LITERAL1
ANALOG_A2 LITERAL1
ANALOG_A1 LITERAL1
ANALOG_A0 LITERAL1
PWM9 LITERAL1
PWM8 LITERAL1
PWM7 LITERAL1
PWM6 LITERAL1
PWM5 LITERAL1
PWM4 LITERAL1
PWM3 LITERAL1
PWM2 LITERAL1
PWM1 LITERAL1
PWM0 LITERAL1
TRST LITERAL1
TRACEDATA_0 LITERAL1
TRACEDATA_1 LITERAL1
TRACEDATA_CLK LITERAL1
USB_FLAG LITERAL1
USB_EN LITERAL1
@@ -0,0 +1,11 @@
name=Arduino_MemoryFree
version=1.0.1
author=Arduino
maintainer=Arduino <info@arduino.cc>
sentence=Arduino Library for Arduino Portenta Breakout Carrier
paragraph=
category=Other
url=https://github.com/arduino-libraries/Arduino_PortentaBreakout
architectures=mbed,mbed_portenta
includes=Arduino_PortentaBreakout.h
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2012 Michael P. Flaga
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,11 @@
#include <avr/pgmspace.h>
#include <stdlib.h>
#include <string.h>
char *to_print;
char *pgmStrToRAM(PROGMEM const char *theString) {
free(to_print);
to_print=(char *) malloc(strlen_P(theString) + 1);
strcpy_P(to_print, theString);
return (to_print);
}
@@ -0,0 +1,5 @@
#include <avr/pgmspace.h>
#define getPSTR(s) pgmStrToRAM(PSTR(s))
char *pgmStrToRAM(PROGMEM const char *theString);