ambiot / ambd_arduino

AmebaD Arduino third-party package SDK
MIT License
81 stars 51 forks source link

Make use of DCT API? #195

Closed vshymanskyy closed 3 months ago

vshymanskyy commented 11 months ago

I need to store some settings in the form of key-value pairs in the NVM (Flash). Overall, I'm trying to get support for Ameba devices for my Preferences library.

One option I found is to use DCT:

// initial DCT
ret = dct_init(DCT_BEGIN_ADDR, MODULE_NUM, VARIABLE_NAME_SIZE, VARIABLE_VALUE_SIZE, 1, 0);
// register module
ret = dct_register_module(example_dct_module);
// open module
ret = dct_open_module(&dct_handle, example_dct_module);

However, looks like the DCT library is not linked, I'm getting:

undefined reference to `dct_init(unsigned long, unsigned short, unsigned short, unsigned short, unsigned char, unsigned char)'
collect2: error: ld returned 1 exit status

Another option is to use some kind of a File system (I see FATFS, but can it be used on the system flash?).

Also, to store any data in the flash, I need to define a dedicated region / partition in the flash memory. What's the best practice to do that?

@xidameng please advise

vshymanskyy commented 11 months ago

I overlooked the "C" linkage. It builds successfully like this:

extern "C" {
  #include <dct.h>
}

I also had to add "-I{ameba.sdkpath}/component/common/file_system/dct" to the compiler.ameba.c.include in platform.txt. It would be great if it was included by default.

Didn't test It yet. I need to define a dedicated region / partition in the flash memory.

vshymanskyy commented 11 months ago

So yeah, DCT actually works as a back-end for the Preferences library:

Preferences_Test/Preferences_Test.ino:142:test_bytes:PASS
Preferences_Test/Preferences_Test.ino:144:test_zero_bytes:PASS
Preferences_Test/Preferences_Test.ino:146:test_utf8_key:PASS
Preferences_Test/Preferences_Test.ino:147:test_utf8_value:PASS
Preferences_Test/Preferences_Test.ino:148:test_remove_key:PASS
Preferences_Test/Preferences_Test.ino:149:test_clear_namespace:PASS
vshymanskyy commented 11 months ago

So, there are 2 questions left:

S10143806H commented 11 months ago

@vshymanskyy ,

The dct function is default wrapped in lib_dct.a under /variants/common_libs/, therefore, to compile dct successfully, you may add in "-I{ameba.sdkpath}/component/common/file_system/dct" in platform.txt

For the DCT configuration, please refer to our standard sdk example located at ambd_sdk\component\common\example\dct. (https://github.com/ambiot/ambd_sdk/tree/dev/component/common/example/dct)

Please do let us know if there are any other things that we could assist you with. And is there any chance that you could pull request this feature upon compilation is done? By the way, xidameng has already left the team.

Thank you for your support.

vshymanskyy commented 11 months ago

The Device Configuration Table support was added and pushed to GitHub. @S10143806H would you consider this:

  1. Adding the required include path to the platform.txt
  2. Adding the Preferneces library to your library package by default? https://github.com/vshymanskyy/Preferences
vshymanskyy commented 11 months ago

@S10143806H could you please review these portions of code:

https://github.com/vshymanskyy/Preferences/blob/main/src/Preferences_impl_dct.h#L12-L29

https://github.com/vshymanskyy/Preferences/blob/main/src/Preferences_impl_dct.h#L41-L55

github-actions[bot] commented 10 months ago

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

vshymanskyy commented 10 months ago

@M-ichae-l @xidameng let me know if this is something you would consider

M-ichae-l commented 10 months ago

@vshymanskyy Thanks for bring it out. As we have discovered, there is no example for DCT demo at arduino level Arduino_package/hardware/libraries

But there is a lib_dct.a at compilations process. So as you have provided the Preference. Why not just do the Pull Request, as a submodule of the SDK?

S10143806H commented 10 months ago

The Device Configuration Table support was added and pushed to GitHub. @S10143806H would you consider this:

  1. Adding the required include path to the platform.txt
  2. Adding the Preferneces library to your library package by default? https://github.com/vshymanskyy/Preferences

Hi @vshymanskyy , Sorry for the late reply.

  1. As answered previously, the line including lib_dct.a have exited in platform.txt: https://github.com/ambiot/ambd_arduino/blob/8e9512a7ac1372b6cc123127da36324f8d0002a2/Arduino_package/hardware/platform.txt#L83C1-L83C1

  2. Yes, you could go ahead with Pull Request your examples into our SDK upon verification. I have tested your examples but both of them seems could not compile successfully in AmebaD Arduino environment. image image

Therefore, maybe could you please clarify what are things that I could do to help you with your Pull Request contribution. And we could proceed to review your codes. Thank you.

vshymanskyy commented 10 months ago
vshymanskyy commented 10 months ago

Updated one of the examples so it doesn't rely on Print::printf(): https://github.com/vshymanskyy/Preferences/blob/main/examples/StartCounter/StartCounter.ino

github-actions[bot] commented 9 months ago

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

github-actions[bot] commented 9 months ago

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

github-actions[bot] commented 8 months ago

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

vshymanskyy commented 8 months ago

will get to it soon

github-actions[bot] commented 8 months ago

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

github-actions[bot] commented 7 months ago

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

vshymanskyy commented 7 months ago

still not there;) sorry!

M-ichae-l commented 7 months ago

@vshymanskyy Thanks for the patient, I have create a submodule of your repo main branch. #5a4b8b79ede9ec2502da29b34cd89e65749bfad6 You may want to review the update. If any update or debug I will help to merge. However, Please note that there is no early release version for current SDK with your submodule. Once your review is one, I will help to create a early release version SDK.

github-actions[bot] commented 6 months ago

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

vshymanskyy commented 6 months ago

I'm alive!

M-ichae-l commented 6 months ago

@vshymanskyy
Could you review about the submodule system for the example you have ported?

github-actions[bot] commented 6 months ago

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

vshymanskyy commented 6 months ago

@M-ichae-l please elaborate, Didn't get your question

github-actions[bot] commented 5 months ago

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

vshymanskyy commented 5 months ago

@M-ichae-l ?

M-ichae-l commented 5 months ago

@vshymanskyy Can you review the submodule here https://github.com/ambiot/ambd_arduino/tree/dev/Arduino_package/hardware/libraries 2024-1-23_16-1-31

If there is no further issue, we will add your repo into the SDK by submodule.

github-actions[bot] commented 4 months ago

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

vshymanskyy commented 4 months ago

ok, i should be able to verify it during the weekend. sorry for a delay, the project that used it was put on hold, so i need to setup the environment again. this holds back any progress

vshymanskyy commented 3 months ago

Looks like everything is correct. Closing the ticket. Thanks for all your help and support!