#14 Startup Code Part-2: Replacing the vector-table, embedded software build process

Поделиться
HTML-код
  • Опубликовано: 1 авг 2024
  • The objective of this lesson is to replace the default vector table from the IAR library with your own.
    To achieve this, you first need to understand the embedded software build process. You will look inside the object files (ELF format) to see what "relocatable code" really means. You will also see how the linker resolves the cross-module references and how the rules are different for objects included directly and object libraries.
    Finally, you will start writing your own startup code with your own vector table. At the end of the lesson, you see that your vector table is used instead of the default one.
    In the next lesson, you will see how to properly initialize your vector table with the stack pointer and addresses of the interrupt handlers.
    ------
    Resources:
    Companion web page for this video course:
    www.state-machine.com/quickstart
    GitHub repository for projects for this video course:
    github.com/QuantumLeaps/moder...
    Links used in this lesson:
    Article "Library order in static linking"
    eli.thegreenplace.net/2013/07/...
    RUclips playlist of the course:
    • Modern Embedded System...
  • НаукаНаука

Комментарии • 87

  • @Lzzzam
    @Lzzzam 2 года назад +11

    I am absolutely astonished by the quality of these lectures.
    I am going to start soon a really complex embedded firmware development contract position and this course is an awesome source of recap for everything is important. I have no words to say I much grateful I am sir, that's extremely valuable for me. Thank you so much

    • @StateMachineCOM
      @StateMachineCOM  2 года назад +3

      I'm glad to hear that you find this video course useful for your work. Please spread a word, so that others can learn as well !

  • @SpaceSurferGod
    @SpaceSurferGod 19 дней назад +1

    Thank you very much, this is indispensable. I have an interview coming up and this is really great!

  • @suryabharathi2977
    @suryabharathi2977 9 лет назад +16

    Not sure if any academic course teaches embedded systems SW dev. to this extent..
    Great job.. Keep it up!!

  • @damiandomanski1845
    @damiandomanski1845 9 лет назад +22

    Im dissapointed ! I wanted to see lesson 0xE not lesson 14 :D I learned more in 1h with you than I learned in 1 year with books! Are you kidding me? You ARE genious!

  • @rohitk-singh
    @rohitk-singh 9 лет назад +9

    WoW! Just watched all your lessons from 0 to 14 in one sitting! Couldn't get myself to take any break in-between! Hats off to you...Amazing teaching technique! Waiting for upcoming lessons now! :)

  • @hoerbschmidt618
    @hoerbschmidt618 Год назад +1

    What a great course!

  • @clay7970
    @clay7970 4 года назад +2

    As every time, first time watch the video I just understand the idea, but not the details, second time I watch the video I wonder that It's good explained, every word you said it's a great information in embedded systems.
    Thanks a lot Miro

  • @friendman2001
    @friendman2001 8 лет назад +2

    wow i truly respect all the time you spend learning in however may years for you to get to the the knowledge you have now. Truly respectable.

  • @spn8523
    @spn8523 4 года назад +1

    This is a 360 degrees coverage course. Excellent!! Thank you very much!!

  • @04mfjoyce
    @04mfjoyce 2 года назад +1

    I've had to watch these these ones on startup code multiple times, but it's awesome material. Thank you again for making these!

  • @ahmedkhalil2414
    @ahmedkhalil2414 9 лет назад +1

    Thank you very much for your efforts. Your tutorial is the perfect one, it should be the standard to be followed ... please, come up with the rest of the episodes.

  • @GalinaMalakhova
    @GalinaMalakhova 4 года назад +2

    This is a very good explanation of how linking works, wow :D Thanks!

  • @hristohristov1311
    @hristohristov1311 2 года назад +1

    Great lessons!
    I try to get into Embedded Systems Development and it really helps!!
    Graduate from Technical University!
    You really rock and have a lot of knowledge and understandings!

  • @zhitailiu3876
    @zhitailiu3876 4 года назад

    Outstanding tutorial!

  • @koceilamessaoudene5982
    @koceilamessaoudene5982 5 лет назад

    Just awsome, Thank you.

  • @DuyguBoubou
    @DuyguBoubou 9 лет назад +7

    thank you for the amazing tutorials!! i searched a long time for something like that!
    i cant wait for lesson about RTOS now.. hope its not far on the schedule ;)

  • @rifatalam4268
    @rifatalam4268 9 лет назад +4

    I am looking forward to the next videos. It has been a long time since the last one. This course is very helpful, so can you please do some more videos, specially on Interrupts?

  • @bh9090
    @bh9090 9 лет назад +1

    Thanks for these amazing videos. Could you please post the other lessons as fast as possible. It completely breaks the flow if only 1 lesson is available every month.

  • @ArnasCel
    @ArnasCel 9 лет назад

    Great video cheers!

  • @dinakrishnamoharana6494
    @dinakrishnamoharana6494 5 лет назад

    Excellent video

  • @bbogdanmircea
    @bbogdanmircea 3 года назад +1

    Finally after many years of Computer Science at School and Work, some things I took for granted are becoming more understandable! Your knowledge about how embedded software works in detail is astonishing, Miro! I wonder how you got all this knowledge, if it was from school or from work experience! In my defense, I worked more on the application software side for the last 8 years, so I knew some things about the basic software only from school and my own projects. How can one find out about how obj files, map files and other file sections work and the relation between them? I suppose it has to be documented somewhere for each type of hardware?

  • @faizanqureshi9837
    @faizanqureshi9837 9 лет назад

    Great Keep it Up

  • @KananDethin
    @KananDethin 8 лет назад +1

    Thank you

  • @rohitkumarmaurya
    @rohitkumarmaurya 9 лет назад +1

    Awesome tutorial ... waiting eagerly for coming episode. Plz upload them as soon as possible. Kindly give some idea to use lwip 1.4.1 (TCP stack). Thanx in advance

  • @thanhcongnguyen4258
    @thanhcongnguyen4258 Год назад

    Very impressive

  • @maciejcebula3353
    @maciejcebula3353 6 лет назад

    Great job;)

  • @amrssrrrdr9254
    @amrssrrrdr9254 5 лет назад

    Many thanks

  • @nikhilsp13
    @nikhilsp13 4 года назад

    Thank you.

  • @amoghjain
    @amoghjain 2 года назад +1

    Woowww!! Thanks!

  • @4four20twenty
    @4four20twenty 8 лет назад +1

    Miro, is there any advantage to using assembly for writing the start up code? For example the startup_lm4f.s provided by ti's cmsis package?

  • @ns5253
    @ns5253 8 лет назад

    Yes. I injected a syntax error into the file startup_tm4c.c and the compiler detected it.
    Are there any other settings that I need to change in IAR ?
    I have compiled the file startup_tm4c.c individually and IAR did not give any errors, so I know that the syntax is correct. The only explanation left is that the file is not being linked in with the final project output for some unknown reason.
    Any suggestions ?
    Thanks.

  • @lusher00
    @lusher00 6 лет назад

    I have written a USB bootloader which is intended to load code into RAM at runtime. The bootloader has handled all the startup code so I would like to strip it all out of the ramcode. When I load the ramcode at runtime I see it execute a few instructions but then it returns to the bootloader. I can't figure out what code is running or why it is returning prematurely. I have used __low_level_init to copy the vector table from 0x0 to 0x2007000 and then update the SCB_VTOR to point to the new vector table. __low_level_init is returning 0 so it should be skipping the rest of the startup code right? Do you have an example of this by any chance? Could I possibly share my project with you?

  • @shriefelshorbagy7122
    @shriefelshorbagy7122 7 лет назад

    will i am doing the same steps that you are doing i opened the cmd on the directory that has the lesson 14 it is the the file disk H then i copy the link of the iar tool wirting iafldrumarm.exe and then i pressed enter the cmd shows
    this message c:\program is not recognized as an internal or external command,operable program or batch file so what i am missing

  • @siddhantkulkarni4244
    @siddhantkulkarni4244 11 месяцев назад

    Hi Miro,
    I am trying to write this stratup code for vector table using Keil uvision but as i have included device-> statup from Manage run time environment i am getting an error --vectors is defined multiple times, I think as IAR search for standard library to check for vector table Keil is taking it as obj file given by controller. is there any otherway to modify Vector table and __initial_sp

  • @malgailany
    @malgailany 9 лет назад +1

    I waited for a long time for lesson 14 to come out. Great as usual.
    I wonder if you can do a lesson on different build configurations. I'm using the STM32F4-Discovery board and trying to build a code that resides in RAM instead of Flash memory. It would be very interesting to show us how to do different build configurations in your impressive style.
    Thanks.

    • @StateMachineCOM
      @StateMachineCOM  9 лет назад +4

      The STM32-Discovery boards are really sweet and I like them a lot. Also, there are other good toolsets for ARM, such as Keil-MDK, Sourcery CodeBench, and others. But I think that introducing too much different stuff could become really confusing really quickly to the viewers. I mean, there are many options to choose from already...
      But perhaps a lesson about placing the code in RAM could be interesting. For now, I would recommend my ESD article "Building Bare Metal ARM Systems with GNU" (see www.embedded.com/design/mcus-processors-and-socs/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started ). The article is about the "classic" ARM (ARM7/9/11), but placing code in RAM is similar for Cortex-M.
      --Miro

    • @sodasurfer731
      @sodasurfer731 9 лет назад

      Quantum Leaps, LLC Many thanks for a great work. I followed the lessons with the STM32F4 Discovery board and had no problems to run the lessons on the ST uc. To map the required GPIO registers/bits is possible by checking the ST Datasheet and Reference Manual.

  • @pitrya2533
    @pitrya2533 7 лет назад +1

    Hi, I was just curious! Why Compiler and Linker are seperate and has seperate jobs to do, I mean compiler alone could have also given the linker's job and vice versa. We always need both, I guess it has something to do with cross compilation but I am not clear. Please help me.

  • @lbrieden1
    @lbrieden1 9 лет назад +1

    Another great lesson. Really looking forward to the next. One question though, I can't find the link to the article on linking that was mentioned in the video. I don't see a link here and I'm not finding the lesson notes on state-machine.com.

    • @StateMachineCOM
      @StateMachineCOM  9 лет назад

      The description of this lesson has been updated and the link to the article "Library order in static linking" has been added at the end.
      Also, the project downolad and class notes have been added online at the web-page accompanying this course at state-machine.com/quickstart

  • @williams9345
    @williams9345 8 лет назад

    My cpp.map has two __vector_tables now. __vector_table 0x00000000 0x26c Data Lc startup_ewarm.o [1]
    __vector_table 0x0000026c Data Gb vector_table_M.o [4]How do I get rid of the second one?Thanks.

  • @benravin6547
    @benravin6547 4 года назад +1

    How to pass the arguments in main such as 'argc' and 'argv' in embedded platform ?

    • @StateMachineCOM
      @StateMachineCOM  4 года назад +3

      In embedded systems you simply cannot pass 'argc' and 'argv' into main(). This need for passing arguments into main comes from the UNIX operating system (for which the C language was created), where applications were launched by the operating system and then always *returned* to the operating system. This makes no sense in a deeply embedded application, because the application is NOT launched by an operating system and main() in these applications never returns. There is simply no operating system to "return to".

  • @rolandoaguilera3114
    @rolandoaguilera3114 7 лет назад

    This is a silly question, but not clear for me. Is CSTACK the same as RAM or is just a piece of memory in the RAM? Thank you!!!!!

    • @StateMachineCOM
      @StateMachineCOM  7 лет назад

      The CSTACK is a contiguous area in RAM that is used for calling functions and servicing interrupts. Please watch the following lessons: lesson-8 "Functions and the Stack", lesson-9 "Modules, Recursion and AAPCS", and lesson-10 "Stack Overflow and the Pitfalls of Functions". --MMS

  • @nevzattanver8879
    @nevzattanver8879 3 года назад +1

    I wonder something. At the end of the lesson, Miro Samek said that initialize the vector table with following safe values. But what does 0x20004000 and 0x9 make sense ? Are they important ?

    • @bbogdanmircea
      @bbogdanmircea 3 года назад +4

      According to the previous lesson, the first one is where the stack is located, and the second one is where main is located. So in this case the startup code just says: Stack begins at 0x20004000 and then sets PC to 0x9 (actually 0x8). At least this is my understanding. Maybe in the next lesson the startup code will do something more interesting?

  • @MuhammadtahirRana-nn1cb
    @MuhammadtahirRana-nn1cb Год назад

    Hello sir. Can you please add some lectures on timers?

  • @francocardillo8735
    @francocardillo8735 4 года назад

    When I tried adding "int const __vector_table[] @ ".intvec"". I get link error of duplicate definitions "Error[Li006]: duplicate definitions for "__vector_table"; in "..\Obj\startup_tm4c.o", and "vector_table_M.o(rt7M_tl.a)"". Thanks for any help!

    • @StateMachineCOM
      @StateMachineCOM  4 года назад

      You mist be linking in both: the generic IAR vector table and your own, customized vector table. The easiest way to correct it is to simply download the IAR project file for this lesson from www.state-machine.com/quickstart, unzip it, and build the project. You can then compare the downloaded project with your own to see the difference. --MMS

  • @dhaneshprabhu72
    @dhaneshprabhu72 3 года назад

    This is getting interesting. But 1 doubt, so whenever, we specify any address in our code, it's considered as an offset. The after linking, the exact address of that instruction is mapped to the memory by adding offset to the base address. Am I right?

    • @StateMachineCOM
      @StateMachineCOM  3 года назад

      Actually, most addresses we specify in embedded programming are absolute and not just offsets. For example, all addresses of peripheral registers (GPIO) are absolute, so are addresses of registers within the NVIC (interrupt controller), etc. Specifically to this lesson about startup code and vector table, it is also at absolute address 0. So, I'm not sure which addresses you mean in this question... --MMS

  • @mohamedhafez1641
    @mohamedhafez1641 2 года назад

    I have a question, my vector table default address is the first address of the Flash which is 0x08000000. Shall I change it to 0x00000000?

    • @StateMachineCOM
      @StateMachineCOM  2 года назад +1

      I suppose that your Flash is aliased also at the address 0x0, exactly to allow the CPU to access the vector table (the initial content of the SP register and the Reset vector.) So, if your system works and you make sure that the vector table at 0x08000000 *is* actually used, you don't need to change anything. --MMS

  • @FM1908Y
    @FM1908Y 3 месяца назад

    Hello Mr. Samek, thank you once again for this course provided to us. I have a question regarding keil/iar differences.
    I am using keil mVision. Maybe I am not looking correctly but I do not see elfdump.exe in my keil folder(where it is located w/relevant files).
    My arm cortex M file lesson structure is as follows:
    Modder embedded C prog:
    Lessons 1-49
    Lesson 14 (for example):
    Stm keil
    Tm4c iar
    Tm4c keil:
    Listings
    Objects:
    main.o
    delay.o
    Lesson.uvprojx
    main.c
    delay.c
    ...
    I see keil documentation refers to command prompts UV4 ... ... but I am not sure how to proceed. I will keep trying but any clarification would be appreciated. Thanks again.

    • @StateMachineCOM
      @StateMachineCOM  3 месяца назад +2

      Indeed, KEIL uVision does not seem to provide an equivalent to "objdump" utility. But you can use *any* objdump utility because uVision produces objects and final image (.axf file) in the standard ELF format. For example, you could use the objdump utlility from the free GNU-ARM compiler. One way of obtaining that compiler along with a bunch of other useful Unix-type utiliies is by downloading the QP-bundle (www.state-machine.com/#Downloads ) The utilty is called arm-none-eabi-objdump.exe and is located in the qp\qtools\gnu_arm-none-eabi\bin folder (assuming you installed QP-bundle). I just checked that the utiliy works for the *.o and *.axf files produced by uVision. --MMS

    • @FM1908Y
      @FM1908Y 3 месяца назад

      @@StateMachineCOM Thank you very much, this helps a lot. Once again, thank you.

  • @franxxxalooo
    @franxxxalooo 9 лет назад +2

    Very good tutorials!
    I found maybe a small mistake, in the custom vector table file, the symbol before the ".intvec" is not an ampersand (&), is the at sign(@)

    • @bbogdanmircea
      @bbogdanmircea 3 года назад

      I get this warning after adding the const, any idea what the problem is? Warning[Lc059]: the section name in this pattern caused it to not match any sections. Similar section names in the program are: ...project.icf 26

  • @lukaspfeiffer179
    @lukaspfeiffer179 5 лет назад

    During this video I corrupted my IAR toolset. When comiling I stay in an infinite loop ("Starting debugger session: Flashing" and "Programming flash memory"). When cancelling I get the following errors:
    Load debugee \...\Embedded Workbench 8.2\arm\config\flashloader\TexasInstruments\FlashLM3SxxxRAM32K.out
    Target reset
    HardFault exception
    The processor has escalated a configurable-priority excetion to HardFault.
    A bus fault has occurred on an instruction prefetch (CFSR.IBUSERR.BFAR)
    An instruction executed with an invalid EPSR.T or EPSR.IT field (CFSR.INVSTATE).
    Excection occurred at PC= 0x20000114, LR=0xffffffff
    See the call stack for more information.
    Can anybody help me please?

    • @StateMachineCOM
      @StateMachineCOM  5 лет назад +2

      I really can't repeat enough to please visit the companion web-page to this video course at www.state-machine.com/quickstart/ . Specifically to this problem, you can recover a locked TivaC LauchPad board by using the LMFlash utility. All of this, plus other troubleshooting tips are described in the document "Troubleshooting TivaC LaunchPad", which is available on the companion page. Please visit! --MMS

    • @lukaspfeiffer179
      @lukaspfeiffer179 5 лет назад

      @@StateMachineCOM Works just fine again. Thank you so much for the quick response !

  • @housseinfakih1958
    @housseinfakih1958 11 месяцев назад

    Where are the class notes they are not online can you please provide them

    • @StateMachineCOM
      @StateMachineCOM  11 месяцев назад

      Class notes are provided on the companion web-page advertised in every video: state-machine.com/quickstart . Specifically, in the "Videos and Projects" table, you can find the "Transcript" column, where you have the exact transcript of each lesson. --MMS

    • @housseinfakih1958
      @housseinfakih1958 11 месяцев назад

      @@StateMachineCOM thank you i thought there would be some summary pdfs of the lessons to recap them since the lessons are full of details and things to take note of. Thank you.

  • @mahalinga2006
    @mahalinga2006 3 года назад

    Greetings Team QP,
    When I try to Convert my object file using CMD prompt using "ielfdumparm.exe", the file gets converted but when I try to save in .txt format it prompts Access denied, Is there any other way or should I change any options in my command prompt, Kindly advice

    • @StateMachineCOM
      @StateMachineCOM  3 года назад

      The "access denied" problem on Windows typically comes up when you try to access a file or a directory while having insufficient privileges. This happens if you’re not an administrator or if you don’t have ownership over a folder. Please check your situation. Also you might want to google for "access denied on Windows". --MMS

    • @mahalinga2006
      @mahalinga2006 3 года назад

      @@StateMachineCOM Thanks Team for prompt response, much appreciated!!!

    • @mahalinga2006
      @mahalinga2006 3 года назад

      When I "Run on administrator mode" I could able to convert obj files

  • @Terszel
    @Terszel 9 лет назад

    Okay it okay now. I fixed it by reflashing the board with LM Flash Programmer here: www.ti.com/tool/lmflashprogrammer. Selected proper board and did Hardware Reset and Program using an example program from TivaWare but please next time warn if we are doing something that may affect the board BEFORE we actually do it

  • @ns5253
    @ns5253 8 лет назад

    Hi Miro,
    I have created the file startup_tm4c.c and added the code -
    /* startup code for TM4C MCU */
    int const __vector_table[] @ ".intvec" = {
    0,
    0
    };
    When I make the project it compiles successfully.
    However, when I look at the c.map file the __vector_table[]
    array is linked from the object file vector_table_M.o instead of the object
    file startup_tm4c.0. Why ?
    Is there a linker setting that I have to change ?
    Thanks

    • @StateMachineCOM
      @StateMachineCOM  8 лет назад

      +ns5253 Are you sure that you have *included* your file startup_tm4c.c in the IAR project? Please check in the Project Explorer pane on the left. Also, you can inject a syntax error in the file and try to re-build the project (F7). If the project builds without errors, you know that the file is not included in the build.

  • @Terszel
    @Terszel 9 лет назад

    "May prevent you from programming your board"
    Why you wait until after to tell this? Is there no way to fix it?

    • @StateMachineCOM
      @StateMachineCOM  9 лет назад +2

      Potpourri
      The TivaC MCUs can reprogram the pins that are usually assigned to the debugger, to be used as GPIO. When this happens, the debugger can no longer take control of the MCU. Unfortunately, the pin re-programming can happen inadvertently, by a faulty program. There should be some kind of protection, like writing a specific "unlock key" value to a specific register.
      Anyway, the code that is being constantly modified in the video is not suitable for download to the board at any random time. Sometimes the code is simply incomplete, and yet I need to stop and explain that particular stage. I can't wait until the code is complete and ready for testing. I would think that it should make sense to you.
      However, each lesson generally ends with code that is safe to try on the board.
      --MMS

  • @neoyang4965
    @neoyang4965 5 лет назад +1

    I saved five years of pocket money to buy the launchpad and it broken like this. I have no money to buy it again, crying.....

    • @StateMachineCOM
      @StateMachineCOM  5 лет назад +1

      You don't describe how your TivaC LaunchPad board is broken. But if it is locked, meaning that it cannot be reprogrammed, you can still **recover** it. Please visit the companion web-page at www.state-machine.com/quickstart/ and read the instructions about the LMFLASH tool, which you can download from TI. Good luck! --MMS

    • @neoyang4965
      @neoyang4965 5 лет назад

      @@StateMachineCOM It‘s worked, thank you very much, your video is cool, I have learned a lot. Thank you very much

  • @cNewbi
    @cNewbi 5 лет назад

    I wonder why there are downvotes

  • @classyjohn1923
    @classyjohn1923 Год назад

    Hi, I'm using stm32cube IDE to follow along in your videos and I understand that every toolchain has their own implementation. I tried defining the vector table in a separate C file as you have shown here except without the @".intvec". I am unable to do that, probably because this is an IAR feature. When I try to define the vector table using the same name as it is in the startup file, I get linker errors complaining about multiple definitions so its not overriding the startup file's definition. Do you know if this approach you mentioned can be applied across all toolchains? Otherwise, I would have to modify it directly in the startup file.

    • @StateMachineCOM
      @StateMachineCOM  Год назад

      I don't use STM32Cube IDE, but my understanding is that it comes with the startup code already (typically in the Startup folder of the generated project). This is typically where the vector table is defined. You might want to look at this. Also, the qpc framework contains some examples of startup code for STM32 and the GNU-ARM compiler (the one used in the Eclipse-based STM32Cube IDE). You need to look in the directory qpc\3rd_party\STM32CubeH7
      ucleo-h743zi\gnu , for example. The startup code is in C with GNU extensions. --MMS

    • @classyjohn1923
      @classyjohn1923 Год назад

      @@StateMachineCOM ah, I understand now. After excluding the startup code autogenerated by STM32Cube, I am able to use my user-defined C startup file. Thank you!