STM32 Microcontroller with GDB: debugging doesn't work when I change flash structure












0















I want to debug my application for the STM32F107 microcontroller using JLinkGDBServer and the arm-none-eabi-gdb client. I am using the startup assembly file and the linker script provided by default by ST for the STM32F107 microcontroller.



Everything works fine if I don't modify the linker script: on one terminal window, I run arm-none-eabi-gdb, and in another terminal I run the GDB server as JLinkGDBServer -select USB -device STM32F107RC -if SWD -speed auto. Then on the GDB client I connect to the server on port 2331, load my elf file, monitor semihosting enable, monitor reset, and finally continue. The program starts at the Reset_Handler (I see its address writen into the PC Register) and runs perfecty, and I even see my std out on a new terminal window running telnet on port 2333.



The problem runs when I modify the LD linker script in order to have custom addresses. The default FLASH part starts at 0x08000000, but I want to reserve that space for a bootloader and some other data, and store my program at 0x08004000. After this change in the linker script, I follow the same steps as before for debugging, but it doesn't work. My application seems to start at some random address, not at the Reset_Handler. However, according to the output of the GDB server, the address of Reset_Handler is correctly written into the PC register.



What am I missing?










share|improve this question



























    0















    I want to debug my application for the STM32F107 microcontroller using JLinkGDBServer and the arm-none-eabi-gdb client. I am using the startup assembly file and the linker script provided by default by ST for the STM32F107 microcontroller.



    Everything works fine if I don't modify the linker script: on one terminal window, I run arm-none-eabi-gdb, and in another terminal I run the GDB server as JLinkGDBServer -select USB -device STM32F107RC -if SWD -speed auto. Then on the GDB client I connect to the server on port 2331, load my elf file, monitor semihosting enable, monitor reset, and finally continue. The program starts at the Reset_Handler (I see its address writen into the PC Register) and runs perfecty, and I even see my std out on a new terminal window running telnet on port 2333.



    The problem runs when I modify the LD linker script in order to have custom addresses. The default FLASH part starts at 0x08000000, but I want to reserve that space for a bootloader and some other data, and store my program at 0x08004000. After this change in the linker script, I follow the same steps as before for debugging, but it doesn't work. My application seems to start at some random address, not at the Reset_Handler. However, according to the output of the GDB server, the address of Reset_Handler is correctly written into the PC register.



    What am I missing?










    share|improve this question

























      0












      0








      0








      I want to debug my application for the STM32F107 microcontroller using JLinkGDBServer and the arm-none-eabi-gdb client. I am using the startup assembly file and the linker script provided by default by ST for the STM32F107 microcontroller.



      Everything works fine if I don't modify the linker script: on one terminal window, I run arm-none-eabi-gdb, and in another terminal I run the GDB server as JLinkGDBServer -select USB -device STM32F107RC -if SWD -speed auto. Then on the GDB client I connect to the server on port 2331, load my elf file, monitor semihosting enable, monitor reset, and finally continue. The program starts at the Reset_Handler (I see its address writen into the PC Register) and runs perfecty, and I even see my std out on a new terminal window running telnet on port 2333.



      The problem runs when I modify the LD linker script in order to have custom addresses. The default FLASH part starts at 0x08000000, but I want to reserve that space for a bootloader and some other data, and store my program at 0x08004000. After this change in the linker script, I follow the same steps as before for debugging, but it doesn't work. My application seems to start at some random address, not at the Reset_Handler. However, according to the output of the GDB server, the address of Reset_Handler is correctly written into the PC register.



      What am I missing?










      share|improve this question














      I want to debug my application for the STM32F107 microcontroller using JLinkGDBServer and the arm-none-eabi-gdb client. I am using the startup assembly file and the linker script provided by default by ST for the STM32F107 microcontroller.



      Everything works fine if I don't modify the linker script: on one terminal window, I run arm-none-eabi-gdb, and in another terminal I run the GDB server as JLinkGDBServer -select USB -device STM32F107RC -if SWD -speed auto. Then on the GDB client I connect to the server on port 2331, load my elf file, monitor semihosting enable, monitor reset, and finally continue. The program starts at the Reset_Handler (I see its address writen into the PC Register) and runs perfecty, and I even see my std out on a new terminal window running telnet on port 2333.



      The problem runs when I modify the LD linker script in order to have custom addresses. The default FLASH part starts at 0x08000000, but I want to reserve that space for a bootloader and some other data, and store my program at 0x08004000. After this change in the linker script, I follow the same steps as before for debugging, but it doesn't work. My application seems to start at some random address, not at the Reset_Handler. However, according to the output of the GDB server, the address of Reset_Handler is correctly written into the PC register.



      What am I missing?







      arm gdb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 8 at 16:36









      Dani S.Dani S.

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The problem was the location of the ISR vectors. I needed to write the ISR vectors offset to the VTOR register. Also, performing a monitor reset from GDB won't perform an actual reset, because it will load the SP register with the value found in the beginning of the flash memory, which is not where my vectors are anymore. However the PC register does seem to be loaded correctly. To summarize, in my startup code I added 2 things: 1) I set the VTOR register. 2) I initialized the SP register to the beginning of the stack. After that, it works fine.






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403590%2fstm32-microcontroller-with-gdb-debugging-doesnt-work-when-i-change-flash-struc%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The problem was the location of the ISR vectors. I needed to write the ISR vectors offset to the VTOR register. Also, performing a monitor reset from GDB won't perform an actual reset, because it will load the SP register with the value found in the beginning of the flash memory, which is not where my vectors are anymore. However the PC register does seem to be loaded correctly. To summarize, in my startup code I added 2 things: 1) I set the VTOR register. 2) I initialized the SP register to the beginning of the stack. After that, it works fine.






            share|improve this answer




























              0














              The problem was the location of the ISR vectors. I needed to write the ISR vectors offset to the VTOR register. Also, performing a monitor reset from GDB won't perform an actual reset, because it will load the SP register with the value found in the beginning of the flash memory, which is not where my vectors are anymore. However the PC register does seem to be loaded correctly. To summarize, in my startup code I added 2 things: 1) I set the VTOR register. 2) I initialized the SP register to the beginning of the stack. After that, it works fine.






              share|improve this answer


























                0












                0








                0







                The problem was the location of the ISR vectors. I needed to write the ISR vectors offset to the VTOR register. Also, performing a monitor reset from GDB won't perform an actual reset, because it will load the SP register with the value found in the beginning of the flash memory, which is not where my vectors are anymore. However the PC register does seem to be loaded correctly. To summarize, in my startup code I added 2 things: 1) I set the VTOR register. 2) I initialized the SP register to the beginning of the stack. After that, it works fine.






                share|improve this answer













                The problem was the location of the ISR vectors. I needed to write the ISR vectors offset to the VTOR register. Also, performing a monitor reset from GDB won't perform an actual reset, because it will load the SP register with the value found in the beginning of the flash memory, which is not where my vectors are anymore. However the PC register does seem to be loaded correctly. To summarize, in my startup code I added 2 things: 1) I set the VTOR register. 2) I initialized the SP register to the beginning of the stack. After that, it works fine.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 8:34









                Dani S.Dani S.

                11




                11






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403590%2fstm32-microcontroller-with-gdb-debugging-doesnt-work-when-i-change-flash-struc%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                     ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕