sparkfun / mbed-os-ambiq-apollo3

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
18 stars 14 forks source link

Print() and (Un)BufferedSerial do not work on Artemis Thing Plus when compiled with ARMC 6.15 #50

Open idea--list opened 3 years ago

idea--list commented 3 years ago

Description of defect

Created a ticket over here about the issue described in the title. Can anyone please update the board specific code so that those important functions work again? That is something beyond my limits.

Problem is 2-fold:

Target(s) affected by this defect ?

Artemis Thing Plus (probably all the Apollo3 based boards)

Toolchain(s) (name and version) displaying this defect ?

ARMC 6.15 (currently i use GCC_ARM which is not affected, but compiles ultra slow the first time)

What version of Mbed-os are you using (tag or sha) ?

Mbed OS 6.8 and up (did not try earlier releases, but i do not expect any releases to compile with ARMC 6.15)

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

Mbed Studio V1.4 and V1.4.1

How is this defect reproduced ?

Try to run any code containing those command/APIs

Wenn0101 commented 3 years ago

I'll take a look and see what i can find!

idea--list commented 3 years ago

@Wenn0101 Mbed Studio V1.4.2 has been released recently and comes with ARMC6.16. Paired up with Mbed OS 6.15 it seems as if the issue would have been fixed.

Can you please try&confirm my finding?

Wenn0101 commented 3 years ago

I am actually still seeing this on v1.4.3 and ARMC6.16, can you send me your example project?

idea--list commented 3 years ago

My project inside which i noticed the issue originally consists of several thousand lines, so i can not post it here, however i use this logic for outputting text inside the project and also this simplified example was failing back in June. Just tried this example (have Mbed Studio V1.4.3 installed on a Win10x64 machine) and now it works again as expected (also inside my original project, that is why i think the issue might have been addressed in recent Mbed OS releases)

#include "mbed.h"
#include <cstdio>
#include <cstring>

#define SERIALBAUD 115200

DigitalOut led(LED_BLUE);
UnbufferedSerial pc(USBTX, USBRX, SERIALBAUD);
char myBuffer[20] = {0};

int main() {

  strcpy(myBuffer, "Hello World!\r\n");

    pc.write(myBuffer, sizeof(myBuffer));

  while (1) {
    led = !led;
    strcpy(myBuffer, "Wishing you ");
    pc.write(&myBuffer, sizeof(myBuffer));
    ThisThread::sleep_for(1000ms);

    led = !led;
    strcpy(myBuffer, "a nice day!\r\n");
    pc.write(&myBuffer, sizeof(myBuffer));
    ThisThread::sleep_for(1000ms);
  }
  return 0;
}

Compiles&runs on my Artemis Thing Plus as expected both with ARMC6.16 and with GCC_ARM 10.3-2021.07 (since OS 6.15 they bumped the GCC version). Did not try to override Mbed's default minimal printf behaviour with any relevant instructions in mbed_app.json.

The only minor glitch i am still facing with the above code: After resetting the board a strange ⸮ character gets printed before the first actual character (same with ARMC and GCC).



While with the code below (probably because of a different minor flaw somewhere in the ported target code as i can not reproduce this on my MAX32630 board) there is no strange character in front of the first actual character, instead an unexpected square glyph gets printed at the end of the first line when compiled with ARMC, and square⸮, when compiled with GCC (different result with ARMC and GCC in this case). However if you uncomment the commented lines you get no strange glyphs anymore, which should be the case even without using std::string.

#include "mbed.h"
#include <cstdint>
#include <cstdio>
#include <string>

// main() runs in its own thread in the OS
struct astruct {
    char name[3];
    //std::string text;
    uint8_t ID;
};

int main()
{
    astruct struct1;
    strcpy(struct1.name, "ABC");
    //struct1.text = "xyZ";
    struct1.ID = 1;

    //printf("name: %s\ntext: %s\nID: %d\n", struct1.name, struct1.text.c_str(), struct1.ID);
    printf("name: %s\nID: %d\n", struct1.name, struct1.ID);

    while (true) {

    }
    return 0;
}

Hope this makes sense or helps to figure out the current situation with these.