RTL8720DN OTA Update

Hi everyone, thanks for checking out this forum post!

I’m currently trying to fix the OTA update for the rtl8720dn chip. I’m using the update_ota_cloud(char* char*) function (inside update.h of the sdk) to update the OTA bank. Everything seems to work, the ftp server also sees an incoming socket.

The problem I’m facing is related to the hostname. The sdk (AmebaD 3.0.7) doesn’t provide the feature to set the hostname and password of the ftp. I’m also not able to set the hostname to anonymous. Is there a way to edit the hostname, or is it possible to see update.cpp to create a lib on my own?

Thanks in advance!
Tim

2 Likes

Hi @TBeeren Tim, please help confirm on which platform are you compiling for firmware?

Arduino or standard SDK?

Hi @xidameng ,

I’m currently compiling on Arduino.

Hi Tim,

Arduino platform uses pre-built binaries as static libraries used during linking stage, thus all source code are already compiled and not to be changed. There is however, no OTA example with 3.0.7 package nor update.cpp in this package. You may refer to the OTA related source code in our open source standard SDK located on the official github account, you may find the github link on the top right of this forum homepage, and should you desire, you may write your own update.cpp and contribute to the forum so that everyboday can benefit from your work :slight_smile:

Hi Simon,

Thanks once again for your comment, and for the tip! I’ll check out the open source sdk.
Just to be sure, is this the source which is used?

And ofcourse, I’ll share my work to be able to contribute to the community :slight_smile:

1 Like

Hi Tim, thats right :+1:

Also, after grasp the source code u found, you may like to take a look at Ameba RTL8195’s arduino OTA example and Arduino OTA API as follows, though RTL8720 is vastly different from RTL8195 but this example and cpp file should still be useful to you

https://github.com/ambiot/amb1_arduino/blob/8d7e1efa4db63f79ae3a05f2fa3d59e0a7f5d269/Arduino_package/hardware/libraries/OTA/OTA.cpp

1 Like

Hi Simon,

Thanks for the references! I’ve got it working under the Arduino compiler. It’s pretty easy to compile the official sources from the sdk as library in the arduino project.

At the moment i’m stuck at the point of compiling the project into a binary or hex file (for ota). Could there be some export lines missing in the platform.txt (\realtek\hardware\AmebaD\3.0.7\platform.txt)? And if so, could you provide me the correct information to be able to compile the code into a binary which could be used for OTA updates.

Thanks again!

Kind regards,
Tim

1 Like

Hi @TBeeren ,

I need more information about the issue you are facing.

Do you mean that you have compiled the OTA source code into library (.a) but could not link it into your arduino sketch code to output a usable firmware?

If my understanding is correct, then you should take a look of the platform.txt at

and add your static library (.a) into this line and to the same path as the rest of the .a libraries, then gcc will automatically search for the source code inside your .a and link it to your arduino sketch during linking stage and output the firmware at the end

1 Like

Hey Simon,

I think this is not the case. Let me be more specific. The arduino IDE provides a feature to compile the sketch directly to a binary (.bin or .ino.hex if i remember correct). It’s under the ‘sketch’ tab in the arduino IDE. When I try to compile the code for the rtl8720dn (with or without the OTA lib addition, doesn’t matter in this case), it compiles fine. But in the sketch folder or temp arduino_build folder, it’s not showing the binary / firmware which could be used for the OTA.

Maybe I’m thinking completely wrong, but worth a shot.

Thanks!

Hi Tim, this is not it…

You must have noticed that Arduino sketch (.ino) is actually a CPP file thus need to be compiled using a CPP compiler.

In order to use a source code written in C under Arduino IDE (in this case for RTL8720DN, the compiler is g++, a free compiler for C++ source code), there are 2 methods,

  1. Convert the original C source code into a CPP file and place it into the sketch folder as a library.
    This way the CPP will be compiled into object code and add to a temporary archive file (.a) for linking later

  2. Compile the C source code from the SDK where you found it into a object code and archive it into an archive file (.a) and put it into the folder I mentioned in my last reply and also add the name to line 70 of the platform.txt

Note: Tools needed for all above procedures are alrady provided in the arduino package inside the toolchain folder, this will spare you the time needed to find and download the correct toolchain

Hope this has answered your question.

1 Like

Hi Simon,

That did indeed answered my question. Thanks once again!

1 Like

Hi Tim,

There are some detailes missing here and there that couldn’t be covered due to the length of the post, but if you choose one of the methods and give it a try, it ain’t that difficult.

If anything, you can always post in this forum for techincal support

1 Like

Hi Simon,

Sorry if I’m bothering you with all the questions :sweat_smile:! With your steps I was able to compile a working binary based for updates etc.

Currently the OTA runs, but breaks everytime on step 3 (as described in rtl8721d_ota.c). At this step it parse firmware file headers and gets the desired OTA headers (func: get_ota_target_header()). It keeps breaking in this part:

if (strncmp("OTA", (const char *)pTempAddr, 3) == 0)
{
    index = 0;
}
else
{
    goto error;
}

What am I missing or doing wrong in this flow? Does the server has to specify some extra headers? Or is this a mistake in the code? To be more specific, I’ve changed nothing in the function as written in the sdk.

1 Like

Hi Tim,

May I know how you add rtl8721d_ota.c to your project? and if possible, would you mind sharing a bit more info of your project setup so I know where to look for a start

1 Like

Hi Simon,

Currently I’ve a CPP project which compiles through Arduino. Since the arduino package did not include the full implementation of an ota, I’ve used rtl8721d_ota.c in my code as library. I’m sadly not able to share my code, but I can be more specific on this part to give you an idea. It’s basicly just added as library (extern c) to my cpp project. Since all dependancies of the arduino package and official sdk are the same, it works on copy pasting the source to your own project as lib.

When including it in my environment/ system, it works. All function calls are running without errors or linking errors. But the point is related to the OTA Headers. While parsing in the above code snippet, the code seems to break.

The problem could be on server side, where the expected OTA headers are not send while fetching from the rtl8720dn. But it could also be something on the rtl8721dn_ota.c side.

Hope this gives some context. If not, don’t hesitate to reach out.
Thanks for your time! Really appreciate it.

Kind regards,
Tim

Clever

Now this will have to go back to code and OTA requirement described in the documentation, luckily I found what you need in the official website, simply register there and you can donwload this doc for free

https://www.amebaiot.com/?s2member_file_download=AN0400_Ameba-D_Application_Note_v13.pdf

1 Like

Hi Simon,

Thanks a lot! This is exactly what I was looking for since I missed documentation on some parts of the chip. I’ll have a look into it.

Hi Simon,

Completely forgot to come back to this topic. Everything seems to work now. The OTA works, and the bank will be switched after updating. The only question left is, how do I select the bank to flash my ‘test’ code to with Arduino. When the OTA is completed, the bank is switched. But my software keeps being flashed (mannualy, not OTA) on the first bank. I’ve checked the documentation, but did not found a solution for this.

Thanks once again.

Tim

1 Like

Hi Tim,

Glad it works! :smiley: rmbr to share with the community if you don’t mind~ so everyone can benefit from your work!

I don’t quite understand your question… what do you mean by “bank to flash” , are u refering to the OTA address on Flash?

Hi Simon,

Thanks! When i fixed this last thing I’d love to end this post with a full explanation of how get it working. It’s not that hard, and the code is almost identical to the code from the sdk. I’ll ask If I’m allowed to share my work (physical) on here, but If I’m not allowed to, I’ll describe the proces from begin to end.

Hopefully the image below explains a bit more of the problem.