PSoC Creator 4.2 Debugging issue

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MuKh_4408861
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Hi all,
I've created memory section in linker script.

my_ram (rwx):ORIGIN = 0x08020000, LENGTH = 0x02000

    .mysection (NOLOAD):

    {

        KEEP(*(.mysection))

    } > my_ram

And allocated structure to it like this in "main_cm4.c"

volatile bmt_ble_buffer_t bmt_ble_buffer  CY_SECTION(".mysection")={.write_idx=0, .write_len=0, .ble_notify=0, .buffer[0][0]=0 };

I have issue - VectorDataPointer does not take correct address.
As you can see below, buffer address within structure is 0x0802009. This is as supposed to be and shows correct in Watch.

However, after running 1 more step in debug, VectorDataPointer gets random value - 0x09F9C229 - you can see it in Watch1 window below.
Why address cannot be assigned to pointer?
Pointer value is definitely wrong, because program get exception later when this pointer get used.

bmt_ble_buffer initialized fully prior getting this function.

What I'm doing wrong?

PS. If I change bmt_ble_buffer to static or remove memory allocation, then all fine,
but I cannot use it that way. I need this structure in other files and processes too.

pastedImage_0.png

0 Likes
1 Solution

Hi Rakshith,

I've noticed some intermittent behaviour. Same I was seeing in my project but did not have a clue.
After this and that tries it was defined following.

A)  Removing Init function affects only after USB reconnect. If you do not reconnect USB it behave like nothing was changed even if you recompile. Address is still good. If you do reconnect USB, then it shows wrong address.
B)  Adding Init function affects immediately. No need to reconnect USB. It fixes address.

My init function is below.

void Init_bmt_ble_buffer()

{

    bmt_ble_buffer.write_idx = 0;

    bmt_ble_buffer.write_len = 0;

    for(uint32_t index=0; index<10; index++)

    {

         bmt_ble_buffer.buffer[0][index] = 0xff;

         bmt_ble_buffer.buffer[1][index] = 0xff;       

    }

}

I do not think M0 linker changes affect behaviour.
I was having init function in my project, but without these 2 lines below.

    bmt_ble_buffer.write_idx = 0;

    bmt_ble_buffer.write_len = 0;

Conclusion is - this style initialization below does not work in case of memory sections.

volatile bmt_ble_buffer_t bmt_ble_buffer  CY_SECTION(".mysection")={.write_idx=0, .write_len=0, .ble_notify=0, .buffer[0][0]=0 };//

Hopefully I won't get this bug anymore. Thanks for your advice.

View solution in original post

4 Replies
lock attach
Attachments are accessible only for community members.
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi MuKh_4408861​,

I tried the same thing at my end and I am unable to reproduce the error.

The pointer value in the Watch Window -

pastedImage_0.png

The buffer address -

pastedImage_1.png

I have also attached the project for your reference. Please let me know if I am missing something.

Can you please try the same project and let me know if it works for you too?

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

Hi Rakshith,

Thanks for your effort.
Yes indeed  it works correct if executed in main.

However, I was able to reproduce error in your project by simply calling this function from main.

void bmt_sample_sensors(void)

{

    pntr = &bmt_ble_buffer.buffer[bmt_ble_buffer.write_idx][bmt_ble_buffer.write_len];

}

Very strange. Any ideas?

0 Likes
lock attach
Attachments are accessible only for community members.

Hi MuKh_4408861​,

I tried the following things -

1. Created a new function and assigned the address to the pointer. It worked for me.

2. Later I realized I was passing the index as [0][0] instead of [bmt_ble_buffer.write_idx][bmt_ble_buffer.write_len]. When I changed it, I was able to observe the issue. The variables were not getting initialized properly.

So, I added the custom section in the M0+ linker file as well and after that, the values were initialized as expected. The address value is also passed properly as shown -

pastedImage_0.png

I have attached the project for your reference. Please try it out at your end and let me know if it works for you.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B

Hi Rakshith,

I've noticed some intermittent behaviour. Same I was seeing in my project but did not have a clue.
After this and that tries it was defined following.

A)  Removing Init function affects only after USB reconnect. If you do not reconnect USB it behave like nothing was changed even if you recompile. Address is still good. If you do reconnect USB, then it shows wrong address.
B)  Adding Init function affects immediately. No need to reconnect USB. It fixes address.

My init function is below.

void Init_bmt_ble_buffer()

{

    bmt_ble_buffer.write_idx = 0;

    bmt_ble_buffer.write_len = 0;

    for(uint32_t index=0; index<10; index++)

    {

         bmt_ble_buffer.buffer[0][index] = 0xff;

         bmt_ble_buffer.buffer[1][index] = 0xff;       

    }

}

I do not think M0 linker changes affect behaviour.
I was having init function in my project, but without these 2 lines below.

    bmt_ble_buffer.write_idx = 0;

    bmt_ble_buffer.write_len = 0;

Conclusion is - this style initialization below does not work in case of memory sections.

volatile bmt_ble_buffer_t bmt_ble_buffer  CY_SECTION(".mysection")={.write_idx=0, .write_len=0, .ble_notify=0, .buffer[0][0]=0 };//

Hopefully I won't get this bug anymore. Thanks for your advice.