Ameba-AIoT / ameba-arduino-d

AmebaD Arduino third-party package SDK
MIT License
86 stars 53 forks source link

sscanf does not work when Arduino_STD_PRINTF is enabled #172

Closed vladkozlov69 closed 1 year ago

vladkozlov69 commented 1 year ago

The following fragment of code works correctly when Arduino_STD_PRINTF is disabled:

String mqttServer = "192.168.0.110";
uint8_t ipAddress[4];
mqttServer.trim();
sscanf(mqttServer.c_str(), "%u.%u.%u.%u", &ipAddress[0], &ipAddress[1], &ipAddress[2], &ipAddress[3]);    

When I enable Arduino_STR_PRINTF, all bytes in ipAddress are 0x00 after sscanf. It it a known limitation or a bug?

PS: I've tried to use different format string and data type.

String mqttServer = "192.168.0.110";
int ipAddress[4];
mqttServer.trim();
sscanf(mqttServer.c_str(), "%d.%d.%d.%d", &ipAddress[0], &ipAddress[1], &ipAddress[2], &ipAddress[3]);    

Result is still the same. When enabling Arduino_STD_PRINTF, ipAddress array is filled with zeros.

vladkozlov69 commented 1 year ago

After some experiments I found that if I remove _strtol_r symbol from variants/rtl8720dn_bw16/linker_scripts/gcc/rom_symbol_ns.txt then it works as expected.

M-ichae-l commented 1 year ago

@vladkozlov69 Thanks for the solution. We will review and merge into SDK.

vladkozlov69 commented 1 year ago

@M-ichae-l I afraid we'll need two different linker scripts for Arduino_STD_PRINTF ON and OFF, otherwise it could lead to linker issues. There could be different offsets at least...

M-ichae-l commented 1 year ago

@vladkozlov69 Ok, I think currently this is a work around. Our team will run though and try to give a solution by using one linker script only. Thanks again!

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 7 days since being marked as stale.