[Testers Needed] Mbed OS Port for Teensy 4.0

Ah, I figured out the mystery of the ncache initialization crashing. Turns out that you were right, that section specifically was still being put into the SEMC due to some weird linker script hijinks. I combined it into main RAM so things should work a bit better now. I also incorporated the fix for the boot data issue that you found!

Try updating your mbed-os submodule to my branch here. Note that you might have to un-shallow the mbed-os submodule to checkout that branch, see here for instructions on that. That should at least fix the bootup errors. It might also fix usb, because the USB buffers were in the ncache section, so they might nave not been getting initialized until now.
 
Aha! I was able to reproduce and diagnose a crash when activating BufferedSerial on pins D1 and D0 using my MIMXRT1050 dev kit. It turns out that, for some reason, the original Mbed port didn't define interrupt handlers for UART ports 5 through 8 (these pins use UART6). So when it tried to call the interrupt handler for the UART, the chip crashed instead.

I pushed a new commit that should fix this issue and allow using the UART properly. I also noticed that the pinmap table seemed to be missing the daisy-chain register settings for those pins, so I added them, plus docs I figured out for how that part of the code works.

> tried PwmOut test on D12 -- i get the "mbed dead" blink pattern

I'm pretty sure that D12 (GPIO_B0_01) can't do PWM, which is why it's dying. That pin isn't listed under any FlexPWM module as far as I can tell. Try D22 instead, that one supports PWM and is currently mapped for it (not all of them are yet).
 
Try updating your mbed-os submodule to my branch

Tried it. Not sure if I got everything set up correctly (see below).

Building this time:

Code:
[251/251] Linking CXX executable HelloWorld.elf
-- built: /tmp/mbed-ce-hello-world/build/HelloWorld.bin
-- built: /tmp/mbed-ce-hello-world/build/HelloWorld.hex
| Module                    |         .text |       .data |        .bss |
|---------------------------|---------------|-------------|-------------|
| CMakeFiles/HelloWorld.dir |       50(+50) |       0(+0) |       0(+0) |
| [fill]                    |     169(+169) |       4(+4) |     31(+31) |
| [lib]/c.a                 | 15223(+15223) | 2476(+2476) |     56(+56) |
| [lib]/gcc.a               |     760(+760) |       0(+0) |       0(+0) |
| [lib]/mbed-usb.a          | 10435(+10435) |       0(+0) |       2(+2) |
| [lib]/misc                |     248(+248) |       4(+4) |     28(+28) |
| [lib]/nosys.a             |       32(+32) |       0(+0) |       0(+0) |
| [misc]                    |         0(+0) |       0(+0) |       0(+0) |
| mbed-os/CMakeFiles        | 39797(+39797) |   436(+436) | 8379(+8379) |
| Subtotals                 | 66714(+66714) | 2920(+2920) | 8496(+8496) |
Total Static RAM memory (data + bss): 11416(+11416) bytes
Total Flash memory (text + data): 69634(+69634) bytes

Good news is there is now signs of life on USB. But not successful enumeration. Here's how Linux kernel sees it.

Code:
Feb  8 01:32:54 preston kernel: [680516.642354] usb 4-13.1: new high-speed USB device number 14 using xhci_hcd
Feb  8 01:32:59 preston kernel: [680521.758356] usb 4-13.1: device descriptor read/64, error -110
Feb  8 01:33:15 preston kernel: [680537.370473] usb 4-13.1: device descriptor read/64, error -110
Feb  8 01:33:15 preston kernel: [680537.558482] usb 4-13.1: new high-speed USB device number 15 using xhci_hcd
Feb  8 01:33:20 preston kernel: [680542.746543] usb 4-13.1: device descriptor read/64, error -110
Feb  8 01:33:36 preston kernel: [680558.366632] usb 4-13.1: device descriptor read/64, error -110
Feb  8 01:33:36 preston kernel: [680558.474925] usb 4-13-port1: attempt power cycle
Feb  8 01:33:37 preston kernel: [680559.082643] usb 4-13.1: new high-speed USB device number 16 using xhci_hcd
Feb  8 01:33:42 preston kernel: [680564.174648] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
Feb  8 01:33:47 preston kernel: [680569.546742] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
Feb  8 01:33:47 preston kernel: [680569.754654] usb 4-13.1: device not accepting address 16, error -62
Feb  8 01:33:47 preston kernel: [680569.834664] usb 4-13.1: new high-speed USB device number 17 using xhci_hcd
Feb  8 01:33:52 preston kernel: [680574.922765] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
Feb  8 01:33:58 preston kernel: [680580.298781] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
Feb  8 01:33:58 preston kernel: [680580.506788] usb 4-13.1: device not accepting address 17, error -62
Feb  8 01:33:58 preston kernel: [680580.507051] usb 4-13-port1: unable to enumerate USB device

Here are the commands I ran. (note to future me trying this again tomorrow....)

Code:
cd /tmp
rm -rf mbed-ce-hello-world
git clone https://github.com/mbed-ce/mbed-ce-hello-world.git
cd mbed-ce-hello-world/
git clone git@github.com:mbed-ce/mbed-os.git
cd mbed-os/
git checkout dev/fix-teensy4-issues
cd ..
mkdir build
cd build/
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Develop -DMBED_TARGET=TEENSY_40
ninja
~/teensy/arduino-1.8.19/hardware/tools/teensy_post_compile -file=HelloWorld -path=/tmp/mbed-ce-hello-world/build
# (press pushbutton on Teensy 4.0)

Not elegant, but reality is I have extremely limited time to fiddle and Github has plenty of bandwidth!
 
Here is a USB protocol analyzer capture of the failed USB enumeration

usb1.jpg

And for reference, here is the beginning of a successful enumeration with Teensy programmed by Arduino+Teensyduino

usb2.jpg
 
> tried PwmOut test on D12 -- i get the "mbed dead" blink pattern

I'm pretty sure that D12 (GPIO_B0_01) can't do PWM, which is why it's dying. That pin isn't listed under any FlexPWM module as far as I can tell. Try D22 instead, that one supports PWM and is currently mapped for it (not all of them are yet).
D12 (GPIO_B0_01) is on QTIMER 1 CHN 1 and does PWM with Teensy core, also see T4.0 pin map


i'll do some UART testing shortly ...
 
OK I updated mbed-ce-hello-world -- thanks Paul for the detailed git incantations. I built, loaded, and ran main.cpp. No mbed death flashing. ttyUSB0 showed up
Code:
[1435205.021011] usb 1-3.4: new full-speed USB device number 37 using xhci_hcd
[1435205.129127] usb 1-3.4: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[1435205.129133] usb 1-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[1435205.129137] usb 1-3.4: Product: FT232R USB UART
[1435205.129140] usb 1-3.4: Manufacturer: FTDI
[1435205.129143] usb 1-3.4: SerialNumber: A501JKF2
[1435205.137833] ftdi_sio 1-3.4:1.0: FTDI USB Serial Device converter detected
[1435205.137902] usb 1-3.4: Detected FT232RL
[1435205.139026] usb 1-3.4: FTDI USB Serial Device converter now attached to ttyUSB0
I hooked up FTDI cable to /dev/ttyUSB0 @115000 baud, but I am seeing no tty output?? I added some LED flashing to while-loop and that is working. I confirmed USB0 and FTDI was working with a Teensy sketch printing on Serial1.

PwmOut pwm(D22); didn't crash and scope showed PWM on pin D22 -- though period wasn't what was requested ?
SystemCoreClock 528MHz
 
Last edited:
Update, I used the following for mbed_app.json
Code:
{
    "target_overrides": {
        "*": {
            "platform.stdio-baud-rate": 115200,
            "platform.stdio-buffered-serial": 1,
            "target.console-usb": false,
            "target.console-uart": true
        }
    }
}
re-created build/ and now I have output on ttyUSB0
Code:
Hello world from Mbed CE!
Hello world from Mbed CE!
Hello world from Mbed CE!
Hello world from Mbed CE!
...

yeah, I can get rid of my morse code output. :)
 
Some hardware registers for T4.0 under mbed os 6.
Code:
SystemCoreClock 528000000  11:38:27 Feb  8 2023 ok

ArmPllClk 1056000000  AhbClk 528000000  RtcClk 32768  Usb1PllPfd0Clk 664615368  IpgClk 132000000 SemClk 176000000 
Usb1PllClk 480000000  OscClk 24000000 
XTALOSC24M->LOWPWR_CTRL 0x74f01
XTALOSC24M->OSC_CONFIG0 0x1f033a73
XTALOSC24M->OSC_CONFIG1 0x228002dc
XTALOSC24M->OSC_CONFIG2 0x800102d7
SCB->ICIALLU 0x0
SCB->CCR 0x70200
SCB->CSSELR 0x0
SCB->CCSIDR 0xf01fe019
SCB->DCISW 0x0
SCB->CCR 0x70200
CCM->CBCDR 0xa8300
SNVS->LPCR 0x20
SNVS->LPSRTCMR 0x0
SNVS->LPSRTCLR 0x0
CCM_ANALOG->PLL_ARM 0x80002058
CCM_ANALOG->PFD_480 0xf1a230d
CCM_ANALOG->PFD_528 0x18131818
CCM_ANALOG->MISC0 0x24008080
SysTick->CTRL 0x0
SysTick->LOAD 0x0
CCM->CCGR0 0xc0000fff
CCM->CMEOR 0x7fffffff
   @600MHz
SystemCoreClock 600000000  11:33:17 Feb 25 2023 ok                                                             
ArmPllClk 1200000000  AhbClk 600000000  RtcClk 32768  Usb1PllPfd0Clk 664615368  
IpgClk 150000000 SemClk 200000000 
Usb1PllClk 480000000  OscClk 24000000 
XTALOSC24M->LOWPWR_CTRL 0x74f01
XTALOSC24M->OSC_CONFIG0 0xa0033a73
XTALOSC24M->OSC_CONFIG1 0x2de002dc
XTALOSC24M->OSC_CONFIG2 0x800102d7
SCB->ICIALLU 0x0
SCB->CCR 0x70200
SCB->CSSELR 0x0
SCB->CCSIDR 0xf01fe019
SCB->DCISW 0x0                                                                  
SCB->CCR 0x70200                                                                
CCM->CBCDR 0xa8300                                                              
SNVS->LPCR 0x20                                                                 
SNVS->LPSRTCMR 0x0                                                              
SNVS->LPSRTCLR 0x0                                                              
CCM_ANALOG->PLL_ARM 0x80002064                                                  
CCM_ANALOG->PFD_480 0xf1a230d                                                   
CCM_ANALOG->PFD_528 0x18131818                                                  
CCM_ANALOG->MISC0 0x24008080                                                    
SysTick->CTRL 0x0                                                               
SysTick->LOAD 0x0                                                               
CCM->CCGR0 0xc3000fff                    
CPU:             600000000 Hz                                                   
AHB:             600000000 Hz                                                   
SEMC:            200000000 Hz                                                   
IPG:             150000000 Hz                                                   
PER:             24000000 Hz                                                    
OSC:             24000000 Hz                                                    
RTC:             32768 Hz                                                       
ARMPLL:          1200000000 Hz                                                  
USB1PLL:         480000000 Hz                                                   
USB1PLLPFD0:     664615368 Hz                                                   
USB1PLLPFD1:     246857130 Hz                                                   
USB1PLLPFD2:     332307684 Hz                                                   
USB1PLLPFD3:     576000000 Hz                                                   
USB2PLL:         24000000 Hz                                                    
SYSPLL:          528000000 Hz                                                   
SYSPLLPFD0:      396000000 Hz                                                   
SYSPLLPFD1:      396000000 Hz                                                   
SYSPLLPFD2:      500210514 Hz                                                   
SYSPLLPFD3:      396000000 Hz                                                   
ENETPLL0:        24000000 Hz                                                    
ENETPLL1:        24000000 Hz                                                    
AUDIOPLL:        24000000 Hz                                                    
VIDEOPLL:        24000000 Hz                     
00 02 f7 f0 00 00

and to enable floating point in printf() modified mbed_app.json
Code:
{
    "target_overrides": {
        "*": {
            "platform.stdio-baud-rate": 115200,
            "platform.stdio-buffered-serial": 1,
            "target.console-usb": false,
            "target.console-uart": true,
            "platform.minimal-printf-enable-floating-point": true
        }
    }
}
 
Last edited:
@MultipleMonomials - I have everything setup and successfully built the hello-world sketch. But ran into an error during the Ninja build with the linker script:

Code:
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld:/home/wwatson/mbed/mbed-ce-hello-world/build/mbed-teensy-40.link_script.ld:26: syntax error
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Here is the section withe error:

Code:
SECTIONS
{
  .flash_config :
  {
    . = ALIGN(8);
    __FLASH_BASE = .;
    KEEP(* (.boot_hdr.conf))
    . = ALIGN(8);
  } > m_flash_config
  [COLOR="#FF0000"]ivt_begin= ORIGIN[/COLOR](m_flash_config) + LENGTH(m_flash_config);
  .ivt :
  {

Should be:

Code:
[COLOR="#00FF00"]ivt_begin = ORIGIN[/COLOR](m_flash_config) + LENGTH(m_flash_config);

Needed thew space before the '=' operator. Also with this command line:
Code:
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Develop -DMBED_TARGET=TEENSY_40

The Ninja build command is not automatically being run. I have to run it separately. Is that correct?
Lastly, which branch should I be using. I am using the main branch. Is that correct? I saw another branch "dev/fix-teensy4-issues".

Results of build:
Code:
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: warning: HelloWorld.elf has a LOAD segment with RWX permissions
-- built: /home/wwatson/mbed/mbed-ce-hello-world/build/HelloWorld.bin
-- built: /home/wwatson/mbed/mbed-ce-hello-world/build/HelloWorld.hex
| Module                    |         .text |       .data |        .bss |
|---------------------------|---------------|-------------|-------------|
| CMakeFiles/HelloWorld.dir |       50(+50) |       0(+0) |       0(+0) |
| [fill]                    |     189(+189) |       4(+4) |     37(+37) |
| [lib]/c.a                 | 16429(+16429) | 1708(+1708) |   373(+373) |
| [lib]/gcc.a               |     752(+752) |       0(+0) |       0(+0) |
| [lib]/mbed-usb.a          | 10387(+10387) |       0(+0) |       2(+2) |
| [lib]/misc                |     264(+264) |       4(+4) |     25(+25) |
| [lib]/nosys.a             |       32(+32) |       0(+0) |       0(+0) |
| [misc]                    |         0(+0) |       0(+0) |       0(+0) |
| mbed-os/CMakeFiles        | 40285(+40285) |   436(+436) | 8379(+8379) |
| Subtotals                 | 68388(+68388) | 2152(+2152) | 8816(+8816) |
Total Static RAM memory (data + bss): 10968(+10968) bytes
Total Flash memory (text + data): 70540(+70540) bytes

Uploaded and got the orange LED on and no output to ttyACM0 as expected. No read LED death flashes:)
 
> Needed thew space before the '=' operator.

Oops, pushed a fix! Odd, that worked with whatever version of ld I have...

> The Ninja build command is not automatically being run. I have to run it separately. Is that correct?

Yep! That's intentional, that's how CMake normally works. There is a "cmake --build" command that I think you can use to do it in one go, but I haven't used it.

> Lastly, which branch should I be using.

You want the dev/fix-teensy4-issues branch. I linked that in my post last night.
 
> Needed thew space before the '=' operator.

Oops, pushed a fix! Odd, that worked with whatever version of ld I have...

> The Ninja build command is not automatically being run. I have to run it separately. Is that correct?

Yep! That's intentional, that's how CMake normally works. There is a "cmake --build" command that I think you can use to do it in one go, but I haven't used it.

> Lastly, which branch should I be using.

You want the dev/fix-teensy4-issues branch. I linked that in my post last night.

Thanks - I am new to Mbed and Cmake. I have a lot to learn. My bad:) Should have read all of the posts I guess...
 
Each time I've looked at this over the last couple days, I also had to re-read a bunch of stuff just to figure out the build commands all over again. That's why I put the notes on msg #28. Still not 100% sure I really got it right.
 
Might be a good idea to define the _teensy_model_identifier inside the linker script. Here's how we do it for Arduino builds:

https://github.com/PaulStoffregen/c...6daba3f3b094893c5b3/teensy4/imxrt1062.ld#L100

When Teensy Loader opens your .HEX file, it also looks to find a .ELF file with the same name. If found, and if its code matches the .HEX file data, Teensy Loader then looks for this _teensy_model_identifier symbol inside the .ELF to learn which Teensy model your code is meant to target. If the actual hardware doesn't match _teensy_model_identifier, a warning dialog box is shown.

Without a .ELF file having _teensy_model_identifier, Teensy Loader will just blindly write the .HEX data into whatever Teensy you connect.
 
Each time I've looked at this over the last couple days, I also had to re-read a bunch of stuff just to figure out the build commands all over again. That's why I put the notes on msg #28. Still not 100% sure I really got it right.

Hi Paul - Me too. Based on the installation instructions, readme's and your post #28 I came up with the right sequence start to finish that seems to work. I have @manitou's post #32 working as well. Just tested the updated "mbed_app.json" from post #33 and:
Code:
#include "mbed.h"

int main()
{
    float fnum = 0.0;
    
	while(true) 
	{
		printf("Hello world from Mbed CE!: %f\n",fnum+=0.5);
		ThisThread::sleep_for(1s);
	}

	// main() is expected to loop forever.
	// If main() actually returns the processor will halt
	return 0;
}

Ouputs:
Code:
Hello world from Mbed CE!: 0.500000
Hello world from Mbed CE!: 1.000000
Hello world from Mbed CE!: 1.500000
Hello world from Mbed CE!: 2.000000
Hello world from Mbed CE!: 2.500000
Hello world from Mbed CE!: 3.000000
Hello world from Mbed CE!: 3.500000

I think I will try to put together step by step installation instructions if for anything so I don't forget:)
 
@anybody interested - Here is the first go at documenting the installation and usage procedure for MBED CE on the Teensy T40. May try to set it up on Windows 11 (maybe).

MBED CE OS installation instructions for Ubuntu 22.04 with Teensy T40.

1. Open a Linux terminal. and create a sub-directory. I used 'mkdir mbed' then 'cd mbed'.

2. Go to this Internet page: https://github.com/mbed-ce/mbed-os/wiki/Toolchain-Setup-Guide

3. Drop down to the "On Linux:" section. Skip over step '1.' and start at step '2.'.

4. Install Ninga Build: 'sudo apt-get install ninja-build'

5. Install other needed packages: 'sudo apt-get install libncurses5 libncursesw5'.

6. Next go to this Internet page: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

7. Again, dropdown to this section: 'x86_64 Linux hosted cross toolchains' 'AArch32 bare-metal target (arm-none-eabi)'

8. Download: 'arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi.tar.xz'

9. Extract the package with: 'tar xf arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi.tar.xz' This may take a little time on a slow computer.

10. Move and rename the resulting directory to /usr/local directory: 'sudo mv arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi /usr/local/gcc-arm'

11. Next 'cd ~/' to get to your home directory.

12. With a text editor open (in my case) '.bash' or '.profile'. Basically, we are adding the path to '/usr/local/gcc-arm' to the existing PATH enviroment variable. Add this to the end of the open file: 'export PATH=/usr/local/gcc-arm/bin:$PATH'. Save the file.

13. Reset the PATH variable with 'source ~/.bashrc' then check to make sure it's set with: 'echo $PATH'. You should see: '/usr/local/gcc-arm/bin:...' at the begining fo the print out.

14. Next install a few python dependency's: 'sudo apt-get install python3-pip python3-setuptools python3-wheel'

15. Now to get Mbed CE Hello World project from GitHub for testing. First cd to the directory you created in step 1. Then execute the following: 'git clone --recursive https://github.com/mbed-ce/mbed-ce-hello-world.git' Make sure to use the '--recursive' option as this will bring in the needed mbed-os submodule.

16. This next step switches to mbed-os branch we are using for testing with the Teensy T40. First change to the mbed-os directory: 'cd mbed-ce-hello-world/mbed-os/'. Then do: 'git checkout dev/fix-teensy4-issues'.

17. You should now be in 'mbed-ce-hello-world/mbed-os/'. Execute the following: 'cmake .. -GNinja -DCMAKE_BUILD_TYPE=Develop -DMBED_TARGET=TEENSY_40'. Then execute 'ninja'. This will build the project. Output should be something like:

Code:
-- built: /home/wwatson/mbed/mbed-ce-hello-world/mbed-os/HelloWorld.bin
-- built: /home/wwatson/mbed/mbed-ce-hello-world/mbed-os/HelloWorld.hex
| Module                    |         .text |       .data |        .bss |
|---------------------------|---------------|-------------|-------------|
| CMakeFiles/HelloWorld.dir |       50(+50) |       0(+0) |       0(+0) |
| [fill]                    |     189(+189) |       4(+4) |     37(+37) |
| [lib]/c.a                 | 16429(+16429) | 1708(+1708) |   373(+373) |
| [lib]/gcc.a               |     752(+752) |       0(+0) |       0(+0) |
| [lib]/mbed-usb.a          | 10387(+10387) |       0(+0) |       2(+2) |
| [lib]/misc                |     264(+264) |       4(+4) |     25(+25) |
| [lib]/nosys.a             |       32(+32) |       0(+0) |       0(+0) |
| [misc]                    |         0(+0) |       0(+0) |       0(+0) |
| mbed-os/CMakeFiles        | 40285(+40285) |   436(+436) | 8379(+8379) |
| Subtotals                 | 68388(+68388) | 2152(+2152) | 8816(+8816) |
Total Static RAM memory (data + bss): 10968(+10968) bytes
Total Flash memory (text + data): 70540(+70540) bytes

18. To upload the hex file to the T40 open the Teensy UI and click on 'File'. Select 'Open hex file'. Choose the 'HelloWorld.hex' file which is in 'mbed-ce-hello-world/mbed-os/'. Press the program button on the T40. Make sure the 'Auto' mode is selected. This will upload the file.

At this point not much is visibly happening. To see the output from the program you need to setup serial1 to show output from the program. You will also need a serial to USB adaptor and a terminal program setup to use /dev/ttyUSB0. Also we will need to modify a json file in the 'mbed-ce-hello-world' directory (mbed_app.json) to look like the following:
====================================================================================
Code:
{
    "target_overrides": {
        "*": {
            "platform.stdio-baud-rate": 115200,
            "platform.stdio-buffered-serial": 1,
            "target.console-usb": false,
            "target.console-uart": true,
            "platform.minimal-printf-enable-floating-point": true
        }
    }
}
====================================================================================

And to see the floating point printf working, modify 'main.cpp' like so:

====================================================================================
Code:
#include "mbed.h"

int main()
{
    float fnum = 0.0;
	while(true) 
	{
		printf("Hello world from Mbed CE! : %f\n", fnum+=0.5);
		ThisThread::sleep_for(1s);
	}

	// main() is expected to loop forever.
	// If main() actually returns the processor will halt
	return 0;
}
====================================================================================

Then execute the 'ninja' command and repeat step #18.

I have tried this with Ubuntu 22.04 and Ubuntu 20.04. Unfortunately there are many issues with Ubuntu 20.04 that I have not worked through yet so suggest using version 22.04. I repeated these steps a few times and they have worked every time.

Hopefully this helps others get started with MBED CE and the T40. T41 anyone?

Please feel free to correct any mistakes I may have made...
 
Last edited:
This is an awesome guide!

Want me to give you edit access to the Mbed wiki so you can improve the instructions there?

You can if you would like to. I hope to get more time to gain experience with this. I am on vacation right now so I have some time. But I cannot guarantee that I will be able to work though it in a timely manner:)
 
In cmake how do I change compiler optimization for builds?

Would be nice to increase SystemCoreClock from 528 MHz to 600 MHz.
 
In CMake, optimization is controlled by the CMAKE_BUILD_TYPE variable. There are three types available in Mbed OS:

  • Debug, which builds with no optimizations and enables debug symbols
  • Develop, which enables -Os optimizations and enables debug symbols
  • Release, which enables -Os optimizations and doesn't build debug symbols

The default is Develop, so optimizations are already on if you didn't change it.

It's pretty odd if the board is running at 528MHz. Looking at the code, it appears to be set for 600: https://github.com/mbed-ce/mbed-os/...sso_MCUS/TARGET_MIMXRT1050/fsl_clock_config.c
 
You can if you would like to. I hope to get more time to gain experience with this. I am on vacation right now so I have some time. But I cannot guarantee that I will be able to work though it in a timely manner:)

Thought I would mention, I was able to build it using W11 sort of using your guide. My first attempt using Visual code, the cmake stuff failed.
Started over and used the Command line. stuff and there I saw the instructions on installing all of necessary python extensions.

Have not tried it out yet. Been playing with other stuff.
 
Thought I would mention, I was able to build it using W11 sort of using your guide. My first attempt using Visual code, the cmake stuff failed.
Started over and used the Command line. stuff and there I saw the instructions on installing all of necessary python extensions.

Have not tried it out yet. Been playing with other stuff.

Glad it helped. I have another project that I am trying to get finished as well. I just keep distracting myself:) I have been playing with SerialTransfer and USB host serial. I have one T41 sending and receiving packets through the USB device port to another T41 USB host port.
 
In CMake, optimization is controlled by the CMAKE_BUILD_TYPE variable. There are three types available in Mbed OS:

  • Debug, which builds with no optimizations and enables debug symbols
  • Develop, which enables -Os optimizations and enables debug symbols
  • Release, which enables -Os optimizations and doesn't build debug symbols

The default is Develop, so optimizations are already on if you didn't change it.

It's pretty odd if the board is running at 528MHz. Looking at the code, it appears to be set for 600: https://github.com/mbed-ce/mbed-os/...sso_MCUS/TARGET_MIMXRT1050/fsl_clock_config.c

I would like to run with -O3. It appears that it is running at -Os. -Os appears in CMakeCache.txt
Code:
CMAKE_ASM_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
also CMAKE_BUILD_TYPE:STRING=Develop
I haven't figured out what set() to use in CMakeLists.txt to use -O3??

In a T4.0 mbed benchmark code with default -Os, duration is 6744 us. In the main.cpp using #pragma GCC optimize ("O3") duration is 5756 us. Teensy 4.0 (Arduino IDE Fastest -O3) duration is 5516 us. So that suggests MCU is running at 600 MHz. A better benchmark example, mbed T4 reports 175 Mflops, teensy T4.0 reports 224 Mflops, 147/224 =0.88, and 528/600 = 0.88. Under mbed if you print SystemCoreClock, it reports 528000000.

UPDATE: No I think MBED T4.0 is running at 528 MHz, see post #51
 
Last edited:
Glad it helped. I have another project that I am trying to get finished as well. I just keep distracting myself:) I have been playing with SerialTransfer and USB host serial. I have one T41 sending and receiving packets through the USB device port to another T41 USB host port.

Sorry, I know off topic, probably should take to another thread, but:
Earlier I was playing with Two Teensy 4.x talking to each other using RAWHID, with the version I made that supports 512 byte transfer. But so far not in build... (Although there may be some support in the USBHost that detects that the RX, TX have size 512...
 
Being really honest, I'm not sure I'll be able to make much headway on the USB issue anytime soon. While I have experience with many MIMXRT peripherals and with Ethernet (will try and port the Teensy 4.1 ETH PHY driver soon so we can do networking), I have virtually no experience with USB. There are a few things I can look into (the MIMXRT1052 dev kit passes Mbed's own USB tests, IIRC), but it will definitely be a learning process. Help would be much appreciated! Note that Mbed also has other USB modes such as USBKeyboard (example) and USB mass storage device (FAT32 emulated thumb drive example), it would be interesting to try those out and see if anything happens.

Regarding the benchmark difference, one possible explanation is Mbed's RTOS scheduler. It runs every millisecond and determines if a thread change or anything is needed. You can disable it by changing the target_link_libraries() call in the CMake script to link to "mbed-baremetal" instead of "mbed-os".

If you want to compile main.cpp with -O3, you can do:
Code:
target_compile_options(HelloWorld PRIVATE -O3)
 
Back
Top