Arduino Ameba SDK - How to compile?

Hello everyone,

Board: BW16
Platform: Arduino
Application: I plan to use the BW16 as a slave module for providing WiFi capabilities to another device, to do so I need a serial interface for the other device to control the BW16.
Issues: The BW16 outputs debug information for both serial ports. According to what I’ve read in the forum disabling this debug output is not possible from a high level, but after checking the Arduino SDK source code it seems to be possible in low level.
I’ve tried to edit the SDK and compile again in Arduino but the adjustments are not reflected in the uploaded binaries, so it seems that my changes are not being compiled and instead it is using a static binary..
Question: Is it possible to modify the Arduino SDK an compile a new version? How can achieve this?

Thanks!

Hi @nic_ea

Can you share what adjustments you are making?

I suggest using the Arduino-CLI tool and using the Verbose flag to see what Arduino is doing during the compilation process.

Hi @sourceparts

I’m changing line 151 of diag.h file in directory C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\system\component\soc\realtek\amebad\swlib\string, check below. I’m changing the initial words for the debug messages which are “RTL8721D[Driver]:

...
#define DBG_ERR_MSG_ON(x)       (ConfigDebug[LEVEL_ERROR] |= BIT(x))
#define DBG_WARN_MSG_ON(x)      (ConfigDebug[LEVEL_WARN] |= BIT(x))
#define DBG_INFO_MSG_ON(x)      (ConfigDebug[LEVEL_INFO] |= BIT(x))

#define DBG_ERR_MSG_OFF(x)      (ConfigDebug[LEVEL_ERROR] &= ~BIT(x))
#define DBG_WARN_MSG_OFF(x)     (ConfigDebug[LEVEL_WARN] &= ~BIT(x))
#define DBG_INFO_MSG_OFF(x)     (ConfigDebug[LEVEL_INFO] &= ~BIT(x))
//#define DRIVER_PREFIX	"RTL8721D[Driver]: "
#define DRIVER_PREFIX	"EEEEEEEE[Driver]: "

#ifdef CONFIG_DEBUG_LOG
#define DBG_8195A(...)     do {\
    if (unlikely(ConfigDebug[LEVEL_ERROR] & BIT(MODULE_MISC))) \
        DiagPrintf("\r" __VA_ARGS__);\
}while(0)
...

If I redefined the DRIVER_PREFIX macro in the main.c file (where the setup and loop are called) I get warnings during the compilation process in the Arduino console so it seems that the compiler is aware of the changes. The compilation output can be found here, since it is too large to be copied here.

After the code is compiled, I erase the BW16’s flash and then load the program. After that, the debug messages still start with “RTL8721D[Driver]:” so the change had no effect.

Hey @nic_ea

Thanks for using arduino-cli like I suggested. This is an ideal way to dig into the Arduino SDK modifications as opposed to the IDE which is not designed for this line of work.

Here are the relevant errors regarding your change in main.c on lines 26 to 38.

C:\Users\Colbits\Downloads\MQTT_TLS\MQTT_TLS.ino:4:0: warning: “DRIVER_PREFIX” redefined
#define DRIVER_PREFIX "defined in main.c "

In file included from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\system/component/soc/realtek/amebad/fwlib/include/rtl8721d.h:22:0,
from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\system/component/soc/realtek/amebad/fwlib/include/ameba_soc.h:13,
from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\system/component/soc/realtek/amebad/cmsis/cmsis.h:35,
from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\system/component/common/mbed/targets/hal/rtl8721d/PinNames.h:5,
from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\variants\rtl8720dn_bw16/variant.h:29,
from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\variants\rtl8720dn_bw16/pins_arduino.h:20,
from C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\cores\ambd/Arduino.h:135,
from C:\Users\Colbits\AppData\Local\Temp\arduino\sketches\0C2BE697C86EF580C250C25BDAD82F8F\sketch\MQTT_TLS.ino.cpp:1:
C:\Users\Colbits\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\system/component/soc/realtek/amebad/swlib/string/diag.h:151:0: note: this is the location of the previous definition
#define DRIVER_PREFIX "EEEEEEEE[Driver]: "

Why don’t you remove that for now? Let’s focus on the diag.h file.

It’s important to remember that when doing any sort of embedded development with microcontrollers that you should often do a clean build.

Check this out:

-clean                        Optional, cleanup the build folder and do not use any cached build.

Maybe give that a shot and let me know?
By the way, I’m not associated with Realtek in anyway. I’m just trying to help.

Sincerely,
Jose@Source.Parts

1 Like

Forgot to mention, for compilation output text, you can use a Paste Bin like:
https://paste.debian.net/

This sets an expiration date on the text so that it is deleted after a certain time period.
It’s more secure than a Google Drive link.

1 Like

Hi @sourceparts,
Thanks for your suggestions! I’ll try them and get back.

Hello again,
I tried compiling using the CLI with the clean option enabled but no success. No redefined macros in main.c (MQTT_TLS.ino).
I used this command:
arduino-cli compile --fqbn realtek:AmebaD:Ai-Thinker_BW16 --clean --verbose MQTT_TLS.ino
This is the output (sorry, it is too large that isn’t allowed in Pastebin).

Still, the uploaded binaries (using CLI) are the same and no changes are effective. I guess that what @xidameng says here is related.

Got it. I’ll take a deeper look and see what I advice I can provide on my end within the next 24 hours.

Hi @nic_ea
I’m still looking into it. I got quite busy with other work.
I had a quick thought however that may be a quick fix to get you going.

Can you try using the #undef directive in the main Sketch the line before where you were redefining it? Try undefining then define it again.