4 Replies Latest reply on May 4, 2020 4:25 PM by MuKh_4408861

    PSoC Creator 4.2 Debugging issue

    MuKh_4408861

      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.

        • 1. Re: PSoC Creator 4.2 Debugging issue
          RakshithM_16

          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 -

           

          The buffer address -

           

           

          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

          • 2. Re: PSoC Creator 4.2 Debugging issue
            MuKh_4408861

            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?

            • 3. Re: PSoC Creator 4.2 Debugging issue
              RakshithM_16

              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 -

               

               

              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

              1 of 1 people found this helpful
              • 4. Re: PSoC Creator 4.2 Debugging issue
                MuKh_4408861

                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.

                1 of 1 people found this helpful