
{"id":142,"date":"2015-01-29T17:02:49","date_gmt":"2015-01-29T17:02:49","guid":{"rendered":"http:\/\/www.elvisneedsboats.com\/?p=142"},"modified":"2016-03-10T18:47:45","modified_gmt":"2016-03-10T18:47:45","slug":"compile-environment-for-braillebuzz-stm32f103","status":"publish","type":"post","link":"https:\/\/timallen.name\/index.php\/2015\/01\/29\/compile-environment-for-braillebuzz-stm32f103\/","title":{"rendered":"Compile environment for BrailleBuzz (STM32F103)"},"content":{"rendered":"<p>Okay three big topics here: crt0 (also known as c0), crt1 (also known as c1), and the linking scripts. crt0 is the code that needs to run before your main, it sets up things like the stack. crt1 is the low level stuff that would normally be OS calls. I sorta simulate an OS because we don&#8217;t have one, so I simulate a heap and malloc, etc. The linking scripts tell the linker where to put things in the address space.<\/p>\n<h2>crt0<\/h2>\n<p>This is the code that executes before your main function gets called. Execution starts at 0000h (actually it may be a pointer on this implementation). But before one can actually run any C one has to do some set-up stuff. Traditionally one writes crt0 in assembly and indeed my original was in assembly. If your careful and don&#8217;t use certain C constructs you can write crt0 in c itself. There is heavy interaction with the linker script as we need to prepare things like the BSS, EBSS, stack etc. Remember C is gonna need to know where in the address space (which changes from implementation to implementation) things like RAM(rw), flash(ro) and heap are.<\/p>\n<p>crt0.c <\/p>\n<pre class=\"lang:default decode:true \" title=\"crt0.c\" >\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &lt;stm32f10x_conf.h&gt;\r\n#include \"irq.h\"\r\n\r\nextern int main();\r\n\r\nextern void* _estack;\r\nextern void* _sdata;\r\nextern void* _edata;\r\nextern void* _sidata;\r\nextern void* _sbss;\r\nextern void* _ebss;\r\nextern void* _eusrstack;\r\n\r\nvoid _start();\r\nextern void _init_crt1();\r\n\r\n\/* IRQ vector table *\/\r\n__attribute__ ((section(\".isr_vector\")))\r\nstruct configword_struct\r\n{\r\n\tconst void* stackpointer;\r\n\tvoid (* const vectors[165])(void);\r\n} configword =\r\n{\r\n\t&amp;_estack,\r\n\t{\r\n\t\t_start,\r\n\t\tNMIException,\r\n\t\tHardFaultException,\r\n\t\tMemManageException,\r\n\t\tBusFaultException,\r\n\t\tUsageFaultException,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tSVC_Handler,\r\n\t\tDebugMon_Handler,\r\n\t\tNULL,\r\n\t\tPendSV_Handler,\r\n\t\tSysTick_Handler,\r\n\t\tWWDG_IRQHandler,\r\n\t\tPVD_IRQHandler,\r\n\t\tTAMPER_IRQHandler,\r\n\t\tRTC_IRQHandler,\r\n\t\tFLASH_IRQHandler,\r\n\t\tRCC_IRQHandler,\r\n\t\tEXTI0_IRQHandler,\r\n\t\tEXTI1_IRQHandler,\r\n\t\tEXTI2_IRQHandler,\r\n\t\tEXTI3_IRQHandler,\r\n\t\tEXTI4_IRQHandler,\r\n\t\tDMA1_Channel1_IRQHandler,\r\n\t\tDMA1_Channel2_IRQHandler,\r\n\t\tDMA1_Channel3_IRQHandler,\r\n\t\tDMA1_Channel4_IRQHandler,\r\n\t\tDMA1_Channel5_IRQHandler,\r\n\t\tDMA1_Channel6_IRQHandler,\r\n\t\tDMA1_Channel7_IRQHandler,\r\n\t\tADC1_2_IRQHandler,\r\n\t\tUSB_HP_CAN1_TX_IRQHandler,\r\n\t\tUSB_LP_CAN1_RX0_IRQHandler,\r\n\t\tCAN1_RX1_IRQHandler,\r\n\t\tCAN1_SCE_IRQHandler,\r\n\t\tEXTI9_5_IRQHandler,\r\n\t\tTIM1_BRK_IRQHandler,\r\n\t\tTIM1_UP_IRQHandler,\r\n\t\tTIM1_TRG_COM_IRQHandler,\r\n\t\tTIM1_CC_IRQHandler,\r\n\t\tTIM2_IRQHandler,\r\n\t\tTIM3_IRQHandler,\r\n\t\tTIM4_IRQHandler,\r\n\t\tI2C1_EV_IRQHandler,\r\n\t\tI2C1_ER_IRQHandler,\r\n\t\tI2C2_EV_IRQHandler,\r\n\t\tI2C2_ER_IRQHandler,\r\n\t\tSPI1_IRQHandler,\r\n\t\tSPI2_IRQHandler,\r\n\t\tUSART1_IRQHandler,\r\n\t\tUSART2_IRQHandler,\r\n\t\tUSART3_IRQHandler,\r\n\t\tEXTI15_10_IRQHandler,\r\n\t\tRTCAlarm_IRQHandler,\r\n\t\tUSBWakeUp_IRQHandler,\r\n\t\tTIM8_BRK_IRQHandler,\r\n\t\tTIM8_UP_IRQHandler,\r\n\t\tTIM8_TRG_COM_IRQHandler,\r\n\t\tTIM8_CC_IRQHandler,\r\n\t\tADC3_IRQHandler,\r\n\t\tFSMC_IRQHandler,\r\n\t\tSDIO_IRQHandler,\r\n\t\tTIM5_IRQHandler,\r\n\t\tSPI3_IRQHandler,\r\n\t\tUART4_IRQHandler,\r\n\t\tUART5_IRQHandler,\r\n\t\tTIM6_IRQHandler,\r\n\t\tTIM7_IRQHandler,\r\n\t\tDMA2_Channel1_IRQHandler,\r\n\t\tDMA2_Channel2_IRQHandler,\r\n\t\tDMA2_Channel3_IRQHandler,\r\n\t\tDMA2_Channel4_5_IRQHandler,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL,\r\n\t\tNULL\r\n\t}\r\n};\r\n\r\nvoid null_driver_reset()\r\n{\r\n}\r\n\r\nvoid _start()\r\n{\r\n\t\/* copy data segment from flash to ram *\/\r\n\t{\r\n\t\tconst size_t datalen = (size_t) &amp;_edata - (unsigned int) &amp;_sdata;\r\n\t\tmemcpy(&amp;_sdata, &amp;_sidata, datalen);\r\n\t}\r\n\r\n\t\/* zero out bss segment *\/\r\n\t{\r\n\t\tconst size_t bsslen = (size_t) &amp;_ebss - (unsigned int) &amp;_sbss;\r\n\t\tmemset(&amp;_sbss, 0x0, bsslen);\r\n\t}\r\n\r\n\tSystemInit();\r\n\r\n\t\/* set process stack *\/\r\n\t__set_PSP((uint32_t) &amp;_eusrstack);\r\n\r\n\t(void) _init_crt1();\r\n\t(void) main();\r\n}\r\n\r\n<\/pre>\n<h2>crt1<\/h2>\n<p>This is the low level operating system type stuff. Well, we don&#8217;t have one, but we&#8217;d still like things like printf and malloc to work or at least not crash. Remember after you call printf, somewhere down the pike some ascii (or unicode) has to go somewhere. In our case we&#8217;re going to output it to one of the UARTs. This is <strong>very<\/strong> convenient when debugging! This code took a long time to sort out and is incomplete. I got some of the stubs from the manufacturer. Recall that in a unix OS we would be opening files (in dev), reading from and writing to them but here we don&#8217;t have an OS or a file-system so we make some assumptions, lots of assumptions.<\/p>\n<p>crt1.h<\/p>\n<pre class=\"lang:default decode:true \" title=\"crt1.h\" >\r\n#ifndef __CRT1_H__\r\n#define __CRT1_H__\r\n\r\nvoid _init_crt1();\r\n\r\n#endif \/* __CRT1_H__ *\/\r\n<\/pre>\n<p>crt1.c<\/p>\n<pre class=\"lang:default decode:true \" title=\"crt1.c\" >\r\n#include &lt;stdint.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &lt;errno.h&gt;\r\n#include &lt;sys\/stat.h&gt;\r\n#include \"stm32f10x_usart.h\"\r\n\r\n#include \"irq.h\"\r\n\r\nextern int8_t _sheap;\r\nextern int8_t _eheap;\r\nstatic const int8_t* eheap_p = &amp;_eheap;\r\nstatic const int8_t* sheap_p = &amp;_sheap;\r\nstatic intptr_t heap_ptr;\r\n\r\nsize_t heap_peak = 0x0;\r\n\r\nlong _write_r(struct _reent *_r, int fd, const void *buf, int cnt)\r\n{\r\n\tint n;\r\n\tconst char *ptr = buf;\r\n\tfor (n = 0; n &lt; cnt; n++) {\r\n\r\n\t\twhile ((USART2-&gt;SR &amp; USART_FLAG_TC) == 0x0000);\r\n\t\tUSART2-&gt;DR = (*ptr++ &amp; 0x01FF);\r\n\r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nlong _read_r(struct _reent *_r, int fd, char *ptr, int len )\r\n{\r\n\t\twhile ((USART2-&gt;SR &amp; USART_FLAG_RXNE) == 0x0000);\r\n\t\t*ptr = (char) (USART2-&gt;DR &amp; 0x01FF);\r\n  return 1;\r\n}\r\n\r\noff_t _lseek_r( struct _reent *_r, int fd, off_t pos, int whence )\r\n{\r\n   return 0;\r\n}\r\n\r\nint _isatty( struct _reent *_r, int fd)\r\n{\r\n  return 1;\r\n}\r\n\r\nint _fstat_r ( struct _reent *_r, int fd, struct stat *pstat)\r\n{\r\n   pstat-&gt;st_mode = S_IFCHR;\r\n   return 0;\r\n}\r\n\r\nlong _close_r(struct _reent *_r, int fd)\r\n{\r\n  _r-&gt;_errno = EBADF;\r\n  return -1;\r\n}\r\n\r\n\/*\r\nint _open_r (struct _reent *_r, const char *file, int flags, int mode)\r\n{ \r\n  _r-&gt;_errno = ENODEV;\r\n  return -1;\r\n}\r\n*\/\r\n\r\n\r\nvoid *_sbrk_r(struct _reent *r, intptr_t incr)\r\n{\r\n  void* retval = 0;\r\n  intptr_t newbrk = (intptr_t)((size_t)heap_ptr + (size_t)incr);\r\n\r\n  if(newbrk &gt;=  (intptr_t)eheap_p)\r\n    {\r\n      r-&gt;_errno = ENOMEM;\r\n      retval = (void *)-1;\r\n    }\r\n  else \r\n    {\r\n      const size_t new_size = ((size_t)newbrk) - ((size_t)sheap_p);\r\n      heap_peak = (heap_peak &lt; new_size) ? new_size : heap_peak;\r\n      retval = (void*)heap_ptr;\r\n      heap_ptr = newbrk;\r\n      \r\n    }\r\n\r\n  return  retval;\r\n}\r\n\r\nvoid _init_crt1() \r\n{\r\n  \/* set the heap with 0xff *\/\r\n  {\r\n    const size_t heapsize = ((size_t)(eheap_p)) - ((size_t)sheap_p);\r\n    memset(&amp;_sheap, 0xff, heapsize);\r\n    heap_ptr = (const intptr_t)sheap_p;\r\n  }\r\n}\r\n\r\nvoid _exit(int i) {\r\n\twhile(1);\r\n\r\n}\r\n<\/pre>\n<h2>linker script<\/h2>\n<p>We need to tell the linker where to put things. What addresses correspond to RAM? What addresses correspond to ROM(flash)? Where&#8217;s the &#8220;heap&#8221;, how big is it.<\/p>\n<p>stm32.ld<\/p>\n<pre class=\"lang:default decode:true \" title=\"stm32.ld\" >\r\n\/* default stack sizes. \r\n\r\nThese are used by the startup in order to allocate stacks for the different modes.\r\n*\/\r\nENTRY(_start)\r\n\r\n__Stack_Size = 1024 ;\r\n\r\nPROVIDE ( _Stack_Size = __Stack_Size ) ;\r\n\r\n__Stack_Init = _estack  - __Stack_Size ;\r\n\r\n\/*\"PROVIDE\" allows to easily override these values from an object file or the commmand line.*\/\r\nPROVIDE ( _Stack_Init = __Stack_Init ) ;\r\n\r\n_Heap_Size = 0x10000;\r\n\r\n\/*\r\nThere will be a link error if there is not this amount of RAM free at the end.\r\n*\/\r\n_Minimum_Stack_Size = 0x100 ;\r\n\r\n\r\n\/* include the memory spaces definitions sub-script *\/\r\n\/*\r\nLinker subscript for STM32F10x definitions with 512K Flash and 1024K RAM *\/\r\n\r\n\/* Memory Spaces Definitions *\/\r\n\r\nMEMORY\r\n{\r\n  RAM (xrw) : ORIGIN     = 0x20000000, LENGTH = 96K\r\n  FLASH (rx) : ORIGIN    = 0x08000000, LENGTH = 1024K\r\n  FLASHB1 (rx) : ORIGIN  = 0x00000000, LENGTH = 0\r\n  EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0\r\n  EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0\r\n  EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0\r\n  EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0\r\n}\r\n\r\n\/* higher address of the user mode stack *\/\r\n_estack = 0x20017fff;\r\n\r\n\r\n\r\n\/* include the sections management sub-script for FLASH mode *\/\r\n\r\n\/* Sections Definitions *\/\r\n\r\nSECTIONS\r\n{\r\n    \/* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH *\/\r\n    .isr_vector :\r\n    {\r\n\t. = ALIGN(4);\r\n        KEEP(*(.isr_vector))            \/* Startup code *\/\r\n\t. = ALIGN(4);\r\n    } &gt;FLASH\r\n \r\n    \/* the program code is stored in the .text section, which goes to Flash *\/\r\n    .text :\r\n    {\r\n\t    . = ALIGN(4);\r\n\t    \r\n        *(.text)                   \/* remaining code *\/\r\n        *(.text.*)                   \/* remaining code *\/\r\n        *(.rodata)                 \/* read-only data (constants) *\/\r\n        *(.rodata*)\r\n        *(.glue_7)\r\n        *(.glue_7t)\r\n\r\n\t    . = ALIGN(4);\r\n   \t _etext = .;\r\n\t    \/* This is used by the startup in order to initialize the .data secion *\/\r\n   \t _sidata = _etext;\r\n    } &gt;FLASH\r\n    \r\n \r\n\r\n    \/* This is the initialized data section\r\n    The program executes knowing that the data is in the RAM\r\n    but the loader puts the initial values in the FLASH (inidata).\r\n    It is one task of the startup to copy the initial values from FLASH to RAM. *\/\r\n    .data  : AT ( _sidata )\r\n    {\r\n\t    . = ALIGN(4);\r\n        \/* This is used by the startup in order to initialize the .data secion *\/\r\n        _sdata = . ;\r\n        \r\n        *(.data)\r\n        *(.data.*)\r\n\r\n\t    . = ALIGN(4);\r\n\t    \/* This is used by the startup in order to initialize the .data secion *\/\r\n   \t _edata = . ;\r\n    } &gt;RAM\r\n    \r\n    \r\n\r\n    \/* This is the uninitialized data section *\/\r\n    .bss :\r\n    {\r\n\t    . = ALIGN(4);\r\n        \/* This is used by the startup in order to initialize the .bss secion *\/\r\n        _sbss = .;\r\n        \r\n        *(.bss)\r\n        *(COMMON)\r\n        \r\n\t    . = ALIGN(4);\r\n\t    \/* This is used by the startup in order to initialize the .bss secion *\/\r\n   \t _ebss = . ;\r\n    } &gt;RAM\r\n    \r\n    PROVIDE ( end = _ebss );\r\n    PROVIDE ( _end = _ebss );\r\n\r\n    ._usrheap :\r\n    {\r\n\t_sheap = .;\r\n\t. = . + _Heap_Size;\r\n\t_eheap = .;\r\n    } &gt;RAM\r\n    \r\n    \/* This is the user stack section \r\n    This is just to check that there is enough RAM left for the User mode stack\r\n    It should generate an error if it's full.\r\n     *\/\r\n    ._usrstack :\r\n    {\r\n\t    . = ALIGN(4);\r\n        _susrstack = . ;\r\n        \r\n        . = . + _Minimum_Stack_Size ;\r\n        \r\n\t    . = ALIGN(4);\r\n        _eusrstack = . ;\r\n    } &gt;RAM\r\n    \r\n\r\n   \r\n    \/* this is the FLASH Bank1 *\/\r\n    \/* the C or assembly source must explicitly place the code or data there\r\n    using the \"section\" attribute *\/\r\n    .b1text :\r\n    {\r\n        *(.b1text)                   \/* remaining code *\/\r\n        *(.b1rodata)                 \/* read-only data (constants) *\/\r\n        *(.b1rodata*)\r\n    } &gt;FLASHB1\r\n    \r\n    \/* this is the EXTMEM *\/\r\n    \/* the C or assembly source must explicitly place the code or data there\r\n    using the \"section\" attribute *\/\r\n    \r\n    \/* EXTMEM Bank0 *\/\r\n    .eb0text :\r\n    {\r\n        *(.eb0text)                   \/* remaining code *\/\r\n        *(.eb0rodata)                 \/* read-only data (constants) *\/\r\n        *(.eb0rodata*)\r\n    } &gt;EXTMEMB0\r\n    \r\n    \/* EXTMEM Bank1 *\/\r\n    .eb1text :\r\n    {\r\n        *(.eb1text)                   \/* remaining code *\/\r\n        *(.eb1rodata)                 \/* read-only data (constants) *\/\r\n        *(.eb1rodata*)\r\n    } &gt;EXTMEMB1\r\n    \r\n    \/* EXTMEM Bank2 *\/\r\n    .eb2text :\r\n    {\r\n        *(.eb2text)                   \/* remaining code *\/\r\n        *(.eb2rodata)                 \/* read-only data (constants) *\/\r\n        *(.eb2rodata*)\r\n    } &gt;EXTMEMB2\r\n    \r\n    \/* EXTMEM Bank0 *\/\r\n    .eb3text :\r\n    {\r\n        *(.eb3text)                   \/* remaining code *\/\r\n        *(.eb3rodata)                 \/* read-only data (constants) *\/\r\n        *(.eb3rodata*)\r\n    } &gt;EXTMEMB3\r\n    \r\n    \r\n    \r\n    \/* after that it's only debugging information. *\/\r\n    \r\n    \/* remove the debugging information from the standard libraries *\/\r\n    DISCARD :\r\n    {\r\n     libc.a ( * )\r\n     libm.a ( * )\r\n     libgcc.a ( * )\r\n     }\r\n\r\n    \/* Stabs debugging sections.  *\/\r\n    .stab          0 : { *(.stab) }\r\n    .stabstr       0 : { *(.stabstr) }\r\n    .stab.excl     0 : { *(.stab.excl) }\r\n    .stab.exclstr  0 : { *(.stab.exclstr) }\r\n    .stab.index    0 : { *(.stab.index) }\r\n    .stab.indexstr 0 : { *(.stab.indexstr) }\r\n    .comment       0 : { *(.comment) }\r\n    \/* DWARF debug sections.\r\n       Symbols in the DWARF debugging sections are relative to the beginning\r\n       of the section so we begin them at 0.  *\/\r\n    \/* DWARF 1 *\/\r\n    .debug          0 : { *(.debug) }\r\n    .line           0 : { *(.line) }\r\n    \/* GNU DWARF 1 extensions *\/\r\n    .debug_srcinfo  0 : { *(.debug_srcinfo) }\r\n    .debug_sfnames  0 : { *(.debug_sfnames) }\r\n    \/* DWARF 1.1 and DWARF 2 *\/\r\n    .debug_aranges  0 : { *(.debug_aranges) }\r\n    .debug_pubnames 0 : { *(.debug_pubnames) }\r\n    \/* DWARF 2 *\/\r\n    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }\r\n    .debug_abbrev   0 : { *(.debug_abbrev) }\r\n    .debug_line     0 : { *(.debug_line) }\r\n    .debug_frame    0 : { *(.debug_frame) }\r\n    .debug_str      0 : { *(.debug_str) }\r\n    .debug_loc      0 : { *(.debug_loc) }\r\n    .debug_macinfo  0 : { *(.debug_macinfo) }\r\n    \/* SGI\/MIPS DWARF 2 extensions *\/\r\n    .debug_weaknames 0 : { *(.debug_weaknames) }\r\n    .debug_funcnames 0 : { *(.debug_funcnames) }\r\n    .debug_typenames 0 : { *(.debug_typenames) }\r\n    .debug_varnames  0 : { *(.debug_varnames) }\r\n}\r\n<\/pre>\n<h2>IRQ handlers<\/h2>\n<p>Lastly we have the irq handlers. We mostly just go into an infinite loop. Naturally we really should do better than this but I never got round to it.<\/p>\n<p>irq.h<\/p>\n<pre class=\"lang:default decode:true \" title=\"irq.h\" >\r\n#ifndef IRQ_H__\r\n#define IRQ_H__\r\n\r\nvoid IRQHandler(void);\r\n\r\nvoid NMIException(void);\r\nvoid HardFaultException(void);\r\nvoid MemManageException(void);\r\nvoid BusFaultException(void);\r\nvoid UsageFaultException(void);\r\n\r\nvoid SVC_Handler(void);\r\nvoid DebugMon_Handler(void);\r\nvoid PendSV_Handler(void);\r\nvoid SysTick_Handler(void);\r\nvoid WWDG_IRQHandler(void);\r\nvoid PVD_IRQHandler(void);\r\nvoid TAMPER_IRQHandler(void);\r\nvoid RTC_IRQHandler(void);\r\nvoid FLASH_IRQHandler(void);\r\nvoid RCC_IRQHandler(void);\r\nvoid EXTI0_IRQHandler(void);\r\nvoid EXTI1_IRQHandler(void);\r\nvoid EXTI2_IRQHandler(void);\r\nvoid EXTI3_IRQHandler(void);\r\nvoid EXTI4_IRQHandler(void);\r\nvoid DMA1_Channel1_IRQHandler(void);\r\nvoid DMA1_Channel2_IRQHandler(void);\r\nvoid DMA1_Channel3_IRQHandler(void);\r\nvoid DMA1_Channel4_IRQHandler(void);\r\nvoid DMA1_Channel5_IRQHandler(void);\r\nvoid DMA1_Channel6_IRQHandler(void);\r\nvoid DMA1_Channel7_IRQHandler(void);\r\nvoid ADC1_2_IRQHandler(void);\r\nvoid USB_HP_CAN1_TX_IRQHandler(void);\r\nvoid USB_LP_CAN1_RX0_IRQHandler(void);\r\nvoid CAN1_RX1_IRQHandler(void);\r\nvoid CAN1_SCE_IRQHandler(void);\r\nvoid EXTI9_5_IRQHandler(void);\r\nvoid TIM1_BRK_IRQHandler(void);\r\nvoid TIM1_UP_IRQHandler(void);\r\nvoid TIM1_TRG_COM_IRQHandler(void);\r\nvoid TIM1_CC_IRQHandler(void);\r\nvoid TIM2_IRQHandler(void);\r\nvoid TIM3_IRQHandler(void);\r\nvoid TIM4_IRQHandler(void);\r\nvoid I2C1_EV_IRQHandler(void);\r\nvoid I2C1_ER_IRQHandler(void);\r\nvoid I2C2_EV_IRQHandler(void);\r\nvoid I2C2_ER_IRQHandler(void);\r\nvoid SPI1_IRQHandler(void);\r\nvoid SPI2_IRQHandler(void);\r\nvoid USART1_IRQHandler(void);\r\nvoid USART2_IRQHandler(void);\r\nvoid USART3_IRQHandler(void);\r\nvoid EXTI15_10_IRQHandler(void);\r\nvoid RTCAlarm_IRQHandler(void);\r\nvoid USBWakeUp_IRQHandler(void);\r\nvoid TIM8_BRK_IRQHandler(void);\r\nvoid TIM8_UP_IRQHandler(void);\r\nvoid TIM8_TRG_COM_IRQHandler(void);\r\nvoid TIM8_CC_IRQHandler(void);\r\nvoid ADC3_IRQHandler(void);\r\nvoid FSMC_IRQHandler(void);\r\nvoid SDIO_IRQHandler(void);\r\nvoid TIM5_IRQHandler(void);\r\nvoid SPI3_IRQHandler(void);\r\nvoid UART4_IRQHandler(void);\r\nvoid UART5_IRQHandler(void);\r\nvoid TIM6_IRQHandler(void);\r\nvoid TIM7_IRQHandler(void);\r\nvoid DMA2_Channel1_IRQHandler(void);\r\nvoid DMA2_Channel2_IRQHandler(void);\r\nvoid DMA2_Channel3_IRQHandler(void);\r\nvoid DMA2_Channel4_5_IRQHandler(void);\r\n\r\n#endif \/\/ IRQ_H__\r\n<\/pre>\n<p>irq.c<\/p>\n<pre class=\"lang:default decode:true \" title=\"irq.c\" >\r\n#include &lt;stdint.h&gt;\r\n#include &lt;stdio.h&gt;\r\n#include \"irq.h\"\r\n\r\nextern void _start();\r\n\r\nvoid SVC_Handler_main(uint32_t* svc_args)\r\n{\r\n\tuint32_t svc_number;\r\n\r\n\tsvc_number = ((char *) svc_args[6])[-2];\r\n\r\n\tswitch (svc_number)\r\n\t{\r\n\tcase 0:\r\n\t\tbreak;\r\n\tdefault:\r\n\t\tbreak;\r\n\t}\r\n}\r\n\r\nvoid NMIException(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid HardFaultException(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid MemManageException(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid BusFaultException(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid UsageFaultException(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DebugMon_Handler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid PendSV_Handler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid SysTick_Handler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid WWDG_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid PVD_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TAMPER_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid RTC_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid FLASH_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid RCC_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI0_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI1_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI2_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI4_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel1_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel2_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel4_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel5_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel6_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA1_Channel7_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid ADC1_2_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid USB_HP_CAN1_TX_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid USB_LP_CAN1_RX0_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid CAN1_RX1_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid CAN1_SCE_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI9_5_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM1_BRK_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM1_UP_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM1_TRG_COM_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM1_CC_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM2_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM4_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid I2C1_EV_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid I2C1_ER_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid I2C2_EV_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid I2C2_ER_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid SPI1_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid SPI2_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid USART1_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid USART2_IRQHandler(void)\r\n{\r\n\r\n}\r\nvoid USART3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid EXTI15_10_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid RTCAlarm_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid USBWakeUp_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM8_BRK_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM8_UP_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM8_TRG_COM_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM8_CC_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid ADC3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid FSMC_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid SDIO_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM5_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid SPI3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid UART4_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid UART5_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM6_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid TIM7_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA2_Channel1_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA2_Channel2_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA2_Channel3_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\nvoid DMA2_Channel4_5_IRQHandler(void)\r\n{\r\n\tfor (;;)\r\n\t\t;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Okay three big topics here: crt0 (also known as c0), crt1 (also known as c1), and the linking scripts. crt0 is the code that needs to run before your main, it sets up things like the stack. crt1 is the low level stuff that would normally be OS calls. I sorta simulate an OS because &hellip; <a href=\"https:\/\/timallen.name\/index.php\/2015\/01\/29\/compile-environment-for-braillebuzz-stm32f103\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Compile environment for BrailleBuzz (STM32F103)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-aph","category-embedded"],"_links":{"self":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":18,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/142\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}