PaulStoffregen
Well-known member
Ivan - if you want to integrate the new size info, the source code is here:
https://github.com/PaulStoffregen/teensy_size
https://github.com/PaulStoffregen/teensy_size
Yes.
The size print looks like this:
..which is not as good as the one Teensy has for T4/4.1/MMCode:RAM: [=== ] 26.6% (used 139616 bytes from 524288 bytes) Flash: [ ] 0.9% (used 75736 bytes from 8126464 bytes) Building .pio\build\teensy41\firmware.hex
which looks like this (more or less (I use a slightly modified version))
Code:(FB) Memory Usage on Teensy 4.1: FLASH: code:26884, data:3784, headers:8240 free for files:8087556 RAM1: code:24264, variables:17088 free for local variables:474432 RAM2: variables:12384 free for malloc/new:511904
build_flags = -Wl,--print-memory-usage
Memory region Used Size Region Size %age Used
ITCM: 151036 B 512 KB 28.81%
DTCM: 123584 B 512 KB 23.57%
RAM: 15424 B 512 KB 2.94%
FLASH: 325 KB 7936 KB 4.10%
ERAM: 6432512 B 16 MB 38.34%
Its allready for a long time possible to get more info on the allocated memory during compilation,
just add this to platformio.ini
Memory region Used Size Region Size %age Used
ITCM: 151036 B 512 KB 28.81%
DTCM: 123584 B 512 KB 23.57%
RAM: 15424 B 512 KB 2.94%
FLASH: 325 KB 7936 KB 4.10%
ERAM: 6432512 B 16 MB 38.34%
Checking size .pio/build/teensy41/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [===== ] 52.4% (used 274608 bytes from 524288 bytes)
Flash: [ ] 3.7% (used 299336 bytes from 8126464 bytes)
teensy_size .pio/build/teensy41/firmware.elf
teensy_size: Memory Usage on Teensy 4.1:
teensy_size: FLASH: code:179364, data:144836, headers:8596 free for files:7793668
teensy_size: RAM1: variables:123584, code:151032, padding:12808 free for local variables:236864
teensy_size: RAM2: variables:15424 free for malloc/new:508864
teensy_size: EXTRAM: variables:6432512
Hi @Frank B! The latest upstream version of the Teensy platform now also uses the "teensy_size" tool to report additional info about memory usage. It'd be great if you could retest your project using the following configuration:
[env:teensy41]
platform = https://github.com/platformio/platform-teensy.git
framework = arduino
board = teensy41
Platform Manager: Installing git+https://github.com/platformio/platform-teensy.git
[COLOR=#ff0000]Error: Traceback (most recent call last):
File "c:\users\frank\.platformio\penv\lib\site-packages\platformio\commands\run\processor.py", line 70, in process
p = PlatformFactory.new(self.options["platform"])
File "c:\users\frank\.platformio\penv\lib\site-packages\platformio\platform\factory.py", line 54, in new
raise UnknownPlatform(pkg_or_spec)
platformio.platform.exception.UnknownPlatform: Unknown development platform 'https://github.com/platformio/platform-teensy.git'
[...] etc[/COLOR]
[...]
Linking .pio\build\teensy41\firmware.elf
Checking size .pio\build\teensy41\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [=== ] 26.6% (used 139616 bytes from 524288 bytes)
Flash: [ ] 0.9% (used 75736 bytes from 8126464 bytes)
Building .pio\build\teensy41\firmware.hex
Configuring upload protocol...
[...]
.vsteensy/build/project17.elf
Memory region Used Size Region Size %age Used
ITCM: 173084 B 512 KB 33.01%
DTCM: 63232 B 512 KB 12.06%
RAM: 12416 B 512 KB 2.37%
FLASH: 406 KB 7936 KB 5.12%
ERAM: 0 GB 16 MB 0.00
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o: In function `fnet_mimxrt_serial_init':
C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: multiple definition of `fnet_mimxrt_serial_init'
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o:C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: first defined here
c:/progra~2/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o: In function `fnet_mimxrt_serial_init':
C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: multiple definition of `fnet_mimxrt_serial_putchar'
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o:C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: first defined here
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o: In function `fnet_mimxrt_serial_init':
C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: multiple definition of `fnet_mimxrt_serial_getchar'
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o:C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: first defined here
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o: In function `fnet_mimxrt_serial_init':
C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: multiple definition of `Serials'
.vsteensy/build/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.o:C:\Users\win10\github\project17/lib/FNET/src/port/cpu/mimxrt//fnet_mimxrt_serial.cpp:56: first defined here
collect2.exe: error: ld returned 1 exit status
%
make: *** [makefile:237: .vsteensy/build/project17.elf] Error 1
The terminal process "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:/Users/win10/github/VisualTeensy_v1_0_0_0/make.exe all -j -Otarget" terminated with exit code: 1.
Does this also happen if you use the Arduino IDE?
If it turns out to be a VisualTeensy problem it would be good to file an issue with an example on the VisualTeensy repo.
I've been looking into this NativeEthernet bug. Indeed the crash is happening deep within FNET. It's going to take some serious work to unravel to figure out what the actual cause really is.
Just to be realistic, this is very unlikely to get fixed in 1.54. So many other things are updated & improved, and it's been just over 1 year since 1.53 and Arduino 1.8.15 is now 7 weeks old. We really need to wrap up 1.54 now.
But I definitely will be diving into this problem in the coming weeks. It will get fixed, though a problem this complex isn't the sort of thing that (typically) gets solved quickly.
Here are trimmed copies of the code to reproduce the problem. I sped it up quite a lot, so it usually crashes in less than 1 minute.
#include "NativeEthernet.h"
uint8_t mac[6];
void teensyMAC(uint8_t *mac) {
for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
Serial.printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
//EthernetServer server(443, true); //Uncomment for TLS
EthernetServer server(80);
void setup() {;
// put your setup code here, to run once:
teensyMAC(mac);
Ethernet.begin(mac);
MDNS.begin("Teensy41", 2); //.local Domain name and number of services
// MDNS.setServiceName("Teensy41_Service_Name"); //Uncomment to change service name
// MDNS.addService("_https._tcp", 443); //Uncomment for TLS
MDNS.addService("_http._tcp", 80);
server.begin();
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
Serial.send_now();
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
// client.println("Refresh: 1"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
client.close(); //If "Connection: close" make sure to close after printing and before stop to avoid harsh reset
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
ab -k -c 10 -n 10000 http://teensy41.local/
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\NativeEthernet\src\NativeEthernet.cpp:39:31: error: conflicting declaration 'void** EthernetClass::socket_ptr'
fnet_socket_t* EthernetClass::socket_ptr;
^
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\NativeEthernet\src\NativeEthernet.cpp:23:0:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\NativeEthernet\src\NativeEthernet.h:91:36: note: previous declaration as 'void* volatile* EthernetClass::socket_ptr'
static volatile fnet_socket_t* socket_ptr;
^
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\NativeEthernet\src\NativeEthernet.cpp:39:31: warning: declaration of 'void* volatile* EthernetClass::socket_ptr' outside of class is not definition [-fpermissive]
fnet_socket_t* EthernetClass::socket_ptr;
^
For NativeEthernet I've already made a commit because I've previously tested this fix when I first looked into this, it stops NativeEthernet from actually running out of sockets and completely stopping when FNETs TCP code doesn't behave like you would expect it too.
https://github.com/vjmuzik/NativeEthernet
lib/FNET/src/stack//fnet_tcp.c: In function '_fnet_tcp_initial_seq_number_update':
lib/FNET/src/stack//fnet_tcp.c:450:70: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
_fnet_tcp_initial_seq_number += FNET_TCP_INITIAL_SEQ_NUMBER_STEP + fnet_rand() & 0xFF;
lib/NativeEthernet/src//NativeEthernet.cpp:39:31: error: conflicting declaration 'void** EthernetClass::socket_ptr'
fnet_socket_t* EthernetClass::socket_ptr;
^
In file included from lib/NativeEthernet/src//NativeEthernet.cpp:23:0:
lib/NativeEthernet/src//NativeEthernet.h:91:36: note: previous declaration as 'void* volatile* EthernetClass::socket_ptr'
static volatile fnet_socket_t* socket_ptr;
^
lib/NativeEthernet/src//NativeEthernet.cpp:39:31: warning: declaration of 'void* volatile* EthernetClass::socket_ptr' outside of class is not definition [-fpermissive]
fnet_socket_t* EthernetClass::socket_ptr;
^
make: *** [makefile:213: .vsteensy/build/lib/NativeEthernet/src//NativeEthernet.cpp.o] Error 1
make: *** Waiting for unfinished jobs....