Function __NOP(); not available in Mbed Studio

Good evening,
I just migrated to Mbed Studio from Mbed Online, I have a part of my code that uses “__NOP();” but the compiler crashes because it does not recognize the function! How to find this function or what to replace it with?

Here is the code:

void WS2812::WriteDataOut(int dataLed[])
    {
        const int nBit8 = 8,
                  nBytePerLed = 3,
                  nBit = nLed * (nBytePerLed * nBit8);
        
        int data[nBit+1];
        int buff[nBit8];
        
        for(int x = 0; x < nLed; x ++)
            {
                int_to_binary(dataLed[x * nBytePerLed], buff, nBit8);
                for(int bit = 0; bit < 8; bit ++){data[bit + (x * (nBit8 * nBytePerLed))] = buff[bit];}        
                        
                int_to_binary(dataLed[(x * nBytePerLed)+1], buff, nBit8);
                for(int bit = 0; bit < 8; bit ++){data[bit + (x * (nBit8 * nBytePerLed)) + nBit8] = buff[bit];}
                
                int_to_binary(dataLed[(x * nBytePerLed)+2], buff, nBit8);
                for(int bit = 0; bit < 8; bit ++){data[bit + (x * (nBit8 * nBytePerLed)) + (2 * nBit8)] = buff[bit];}
            }
            
    __disable_irq();
    
    for (int i = 0; i < (nLed * (nBytePerLed * nBit8)); i++) 
        {
            int j = 0;
            if (data[i])
                {
                    Data = 1;
                    for (; j < 5; j++) {__nop();}
                    Data = 0;
                    for (; j < 0; j++) {__nop();}
                } 
            else 
                {
                    Data = 1;
                    for (; j < 0; j++) {__nop();}
                    Data = 0;
                    for (; j < 5; j++) {__nop();}
            }
        }
    
    __enable_irq();

    }

Thanks in advance for your help,
Sincerely Antoine

Hello,

__nop() is from old AC5 and its explanation - ARM Compiler toolchain Compiler Reference Version 5.03
and according to this Arm Compiler Migration and Compatibility Guide Version 6.16 you just need to include arm_acle.h.

#include "arm_acle.h"

BR, Jan

Hello Johnny,

Thank you very much for your answer, I will test this.

At the same time, I also use the “Serial” library under OS-5 but it doesn’t exist anymore under OS-6… I need “Putc, Getc etc…”

How can I find “Serial” under Mbed OS-6?

Thank you in advance for your valuable answer

Hello,

Already edited post.

Serial API was splited to BufferedSerial (no interrupts) and UnbufferedSerial (interrupts are possible), but these APIs do not contain printf, getc, putc functions and so on. There are only read and write methods.

So you have two options. you can change all objects of Serial to one of variants above (we use UnbufferedSerial for now) and all getc/putc to read/write.

Change from

    Serial pc(...);
    // getc
    int c = serial.getc();
    // putc
    serial.putc(c);

change to

   UnbufferedSerial serial(USBTX,USBRX);
    // getc
    char c;
    serial.read(&c, sizeof(buf));
    // putc
    serialPort.write(&c, sizeof(c));

Or you can import this library SerialStream - Bringing MBed serial ports back like it’s 1999…… | Mbed into your project or library. Then just replace your Serial object with code like below and the rest could be same.

UnbufferedSerial serial(...);
SerialStream<UnbufferedSerial> pc(serial);

Simple example with putc/getc under MbedOS 6.16 via SerialStream library.

#include "mbed.h"
#include "SerialStream.h"

UnbufferedSerial serial(...);
SerialStream<UnbufferedSerial> pc(serial);

int main()
{
    printf("SerialStream test\n");
    while (true) {
        pc.putc(pc.getc());
    }
}

BR, Jan

1 Like

Johnny,

Thank you very much for your answer, I have tested with UnbufferedSerial but I get this message:

[Error] mbed-midi_Adapter.hpp@29,24: no member named 'getc' in 'mbed::UnbufferedSerial'
[Error] mbed-midi_Adapter.hpp@34,17: no member named 'putc' in 'mbed::UnbufferedSerial'
[ERROR] In file included from .\MIDI\mbed-midi_Adapter\mbed-midi_Adapter.cpp:1:

I then tested with BufferedSerial but I get this:

[Error] mbed-midi_Adapter.hpp@29,24: no member named 'getc' in 'mbed::UnbufferedSerial'
[Error] mbed-midi_Adapter.hpp@34,17: no member named 'putc' in 'mbed::UnbufferedSerial'
[ERROR] In file included from .\MIDI\mbed-midi_Adapter\mbed-midi_Adapter.cpp:1:

Thank you in advance for your valuable answer

Sorry my answer was not much clear probably. I did edit my previous post.
If it will be still not clear, then share a link of library what you use and I will try to explain better in practice.

BR, Jan

1 Like

Johnny,

Thank you very much for your analysis and example.

For the moment I solved the problem by compiling under MBED OS-5.15.7 which still uses “Serial”.
But I will test your solution in order to migrate to Mbed OS 6

Thanks a lot

Johnny,

I come back to you concerning the compilation, I found that I must add the file “mbed_app.json” as in the example “mbed-os-example-blinky-baremetal-5” in order not to use RTOS and thus not to exceed the RAM and or Flash memory.
Here is the file:

{
    "requires": ["bare-metal"],
    "target_overrides": {
      "*": {
        "target.c_lib": "small",
        "target.printf_lib": "minimal-printf",
        "platform.minimal-printf-enable-floating-point": false
      }
    }
}

For the needs of my project I use a Bootloader on the USB port of the KL25Z and I must therefore shift the flash memory start of the program so that it starts.

I have created a second post for this that describes my problem:
https://forums.mbed.com/t/how-to-shift-the-flash-memory-on-kl25z/17892
Thank you in advance for your help, I can’t find a solution to this problem.

Sincerely, Antoine

Hi,

I found the solution, the function__nop(); is replaced by: __asm(“nop”);

Thank you all for your help