ACM_Automat.icf 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. // ACM "Automat" Edition :)
  2. // Based on MCU: STM32L151CB or STM32L151CB-A
  3. // STM32L151CB, ROM 128K, RAM 16K:
  4. // Flash Memory Begins from 0x08000000
  5. // Flash Memory Ends at 0x0801FFFF
  6. // RAM Memory begins from 0x20000000
  7. // RAM Memory ends at 0x20003FFF
  8. // STM32L151CB-A, ROM 128K, RAM 32K:
  9. // Flash Memory Begins from 0x08000000
  10. // Flash Memory Ends at 0x0801FFFF
  11. // RAM Memory begins from 0x20000000
  12. // RAM Memory ends at 0x20007FFF
  13. // Relative addresses of ROM:
  14. // Base address: 0x08000000
  15. //
  16. // Static firmware: Bootloader program + Vector table + Priveleged section
  17. // Bootloader fw. total: 32KiB - 256 priveleged bytes - 256 intvec bytes
  18. // 0x00000 0x00100 0x07F00 0x07FFF
  19. // | | | |
  20. // +-----------------+----------------------------------+---------------------+
  21. // | Interrupt | Bootloader program | Priveleged |
  22. // | Table | | section |
  23. // | Bootloader | 32,256 bytes | 256 bytes |
  24. // | .intvec | | |
  25. // +-----------------+----------------------------------+---------------------+
  26. // |<- sizeIntVect ->|<--------- sizeBootloader ------->|<- sizePriveleged ->|
  27. // | |
  28. // |<------------------------- sizeFixedFirmware ---------------------------->|
  29. // Dynamic firmware: Application program + Vector table + Progversion section
  30. // Application total: 96KiB - 256 program version bytes - 256 intvec bytes
  31. // 0x80000 0x81000 0x1FF00 0x1FFFF
  32. // | | | |
  33. // +-----------------+----------------------------------+---------------------+
  34. // | Interrupt | Application | Program |
  35. // | Table | program | version |
  36. // | Application | | section |
  37. // | .intvec | 97,792 bytes | .progversion * |
  38. // +-----------------+----------------------------------+---------------------+
  39. // |<- sizeIntVect ->|<--------- sizeApplication ------>|<- sizeProgversion ->|
  40. // | |
  41. // |<-------------------------- sizeDynamicFirmware ------------------------->|
  42. //
  43. // *Note: Program version section includes CRC32 (4 bytes) section for checksum.
  44. //
  45. //
  46. // Relative addresses of RAM:
  47. // Base address: 0x20000000
  48. // RAM (Application), STM32L151CB and STM32L151CB-A
  49. //
  50. // Bootloader:
  51. // 0x00000 0x00C00 0x00C10 0x03FFF
  52. // | | | |
  53. // +---------------+------------+------------------------------------------+
  54. // | | Service | |
  55. // | CSTACK | BOOTSIGN | Common RAM |
  56. // | 3KiB | section | |
  57. // | | .bootsign | 13,296 bytes |
  58. // +---------------+------------+------------------------------------------+
  59. // |<- sizeStack ->|<- ****** ->|<------------- sizeCommonRam ------------>|
  60. // / \
  61. // sizeRamBootsign
  62. // Application:
  63. // 0x00000 0x00C00 0x00C10 0x01C10 0x03FFF
  64. // | | | | |
  65. // +---------------+------------+--------------+---------------------------+
  66. // | | Service | | |
  67. // | CSTACK | BOOTSIGN | HEAP | Common RAM |
  68. // | 3KiB | section | .heap | |
  69. // | | .bootsign | 4KiB | 9,200 bytes |
  70. // +---------------+------------+--------------+---------------------------+
  71. // |<- sizeStack ->|<- ****** ->|<- sizeHeap ->|<----- sizeCommonRam ----->|
  72. // / \
  73. // sizeRamBootsign
  74. // Relative addresses of RAM:
  75. // Base address: 0x20000000
  76. // RAM (Application), STM32L151CB-A only
  77. //
  78. // Bootloader and Application:
  79. // 0x04000 0x07FFF
  80. // | |
  81. // +-------------------------------------------------------------------+
  82. // | |
  83. // | Common RAM |
  84. // | |
  85. // | 16 KiB |
  86. // +-------------------------------------------------------------------+
  87. // |<------------------------- +++sizeCommonRam ---------------------->|
  88. // BOOTSIGN - service region of RAM dedicated for storing the application/bootloader flags
  89. // Common - general purpose application RAM region
  90. // HEAP - application dynamic memory region (Application only)
  91. // CSTACK - main thread stack
  92. // ======================== Symbols and Sizes =================================
  93. // Check for wheither symbol 'BOOTLOADER' is defined
  94. if(!isdefinedsymbol(BOOTLOADER))
  95. {
  96. // this is app, BOOTLOADER is not defined
  97. define symbol BOOTLOADER = 0;
  98. }
  99. if( !isdefinedsymbol(STM32L151CBA) )
  100. {
  101. define symbol STM32L151CBA = 0;
  102. }
  103. // Check for wheither symbol 'APPIMGINBOOT' is defined
  104. if(!isdefinedsymbol(APPIMGINBOOT))
  105. {
  106. // by default, APPIMGINBOOT = 0, that means
  107. // no application image is placed in bootloader project
  108. define symbol APPIMGINBOOT = 0;
  109. }
  110. // Define memory size:
  111. define memory mem with size = 4G;
  112. // Base hard-addresses:
  113. define symbol baseROM = 0x08000000; // @baseROM: Chip-ROM
  114. define symbol baseRAM = 0x20000000; // @baseRAM: Chip-RAM
  115. // Region sizes:
  116. define symbol sizeChipRom = 0x20000; // @sizeChipRom: Whole Chip-ROM size
  117. define symbol sizeFixedFirmware = 0x04000; // @sizeFixedFirmware: Fixed Firmware Size, aka "Bootloader" + some constant data
  118. // @sizeDynamicFirmware: Size of re-writable firmware and data
  119. define symbol sizeDynamicFirmware = sizeChipRom - sizeFixedFirmware;
  120. define symbol sizeIntVect = 0x00100; // @sizeIntVect: size of interrupt vector table
  121. if( STM32L151CBA )
  122. {
  123. // Region sizes:
  124. define symbol sizeChipRam = 0x08000; // @sizeChipRam: Whole Chip-RAM size, 32KiB for STM32L151CBA
  125. }
  126. else
  127. {
  128. // Region sizes:
  129. define symbol sizeChipRam = 0x04000; // @sizeChipRam: Whole Chip-RAM size, 16KiB for STM32L151CB
  130. }
  131. // ----------------------------------------------------------------------------------------------------
  132. define exported symbol sizeRamBootsign = 0x00010; // @sizeRamBootsign: size of service RAM-region (app-->boot flags)
  133. define exported symbol sizePriveleged = 0x00100; // @sizePriveleged: Priveleged section: contains constant device data
  134. define exported symbol sizeProgversion = 0x00100; // @sizeProgversion: Program Version Sector size
  135. define exported symbol sizeProgverCRC = 0x00004; // @sizeProgverCRC: Program Version Checksumm size
  136. // @sizeProgverData: Program Version Data size
  137. define exported symbol sizeProgverData = sizeProgversion - sizeProgverCRC;
  138. // @sizeBootloader: Bootloader program ROM size
  139. define exported symbol sizeBootloader = sizeFixedFirmware - sizePriveleged;
  140. // @sizeApplication: Application program ROM size
  141. define exported symbol sizeApplication = sizeDynamicFirmware - sizeProgversion;
  142. if( BOOTLOADER )
  143. {
  144. // For Bootloader:
  145. define symbol sizeStack = 0x01000; // @sizeStack: CStack size (RAM)
  146. define symbol sizeHeap = 0x00000; // @sizeHeap: Heap size (RAM) - NO HEAP in bootloader
  147. define symbol sizeUsbBuffRam = 0x01000; // @sizeUsbBuffRam: logical sector for USB-Buffers
  148. }
  149. else
  150. {
  151. // For Application:
  152. define symbol sizeStack = 0x01000; // @sizeStack: CStack size (RAM)
  153. define symbol sizeHeap = 0x01000; // @sizeHeap: Heap size (RAM)
  154. define symbol sizeUsbBuffRam = 0x01000; // @sizeUsbBuffRam: logical sector for USB-Buffers
  155. }
  156. // @sizeCommonRam: common readwrite memory
  157. // The readwrite memory is reserved for CSTACK (@sizeStack),
  158. // Service RAM-region (@sizeRamBootsign) and HEAP(@sizeHeap).
  159. // The rest part of the chip RAM is common readwrite memory.
  160. define symbol sizeCommonRam = sizeChipRam - sizeRamBootsign - sizeStack - sizeHeap;
  161. // Predefined IAR-symbol '__ICFEDIT_size_cstack__' must be defined:
  162. define symbol __ICFEDIT_size_cstack__ = sizeStack;
  163. // Predefined IAR-symbol '__ICFEDIT_size_heap__' must be defined:
  164. define symbol __ICFEDIT_size_heap__ = sizeHeap;
  165. // Absolute ranges (Region edjes):
  166. // 1) Fixed Firmware Region:
  167. // begins since the start of ROM and takes @sizeFixedFirmware bytes:
  168. define symbol addrFixedFirmware = baseROM;
  169. define symbol addrFixedFirmwareEnd = baseROM + sizeFixedFirmware - 1;
  170. // 1.1) Bootloader's Interrupt Vector Table:
  171. // table begins at @addrFixedFirmware and takes @sizeIntVect bytes:
  172. define exported symbol addrIntVectBoot = addrFixedFirmware;
  173. // Note: 'addrIntVectBoot' is referred by bootloader program
  174. define symbol addrIntVectBootEnd = addrIntVectBoot + sizeIntVect - 1;
  175. // 1.2) Bootloader's program:
  176. // follows the bootloader's interrupt vector table and takes @sizeBootloader:
  177. define symbol addrBootloader = addrIntVectBootEnd + 1;
  178. define symbol addrBootloaderEnd = addrBootloader + sizeBootloader - 1;
  179. // 1.3) Priveleged section:
  180. // the end of the fixed firmware region:
  181. define exported symbol addrPriveleged = addrFixedFirmwareEnd - sizePriveleged + 1;
  182. define symbol addrPrivelegedEnd = addrFixedFirmwareEnd;
  183. // 2) Dynamic firmware:
  184. // follows the fixed one - the rest part of the chip's ROM
  185. define symbol addrDynamicFirmware = addrFixedFirmwareEnd + 1;
  186. define symbol addrDynamicFirmwareEnd = addrDynamicFirmware + sizeDynamicFirmware - 1;
  187. // 2.1) Application's Interrupt Vector Table:
  188. // table begins at @addrDynamicFirmware and takes @sizeIntVect bytes:
  189. define exported symbol addrIntVectApp = addrDynamicFirmware;
  190. // Note: 'addrIntVectApp' is referred by bootloader program
  191. define symbol addrIntVectAppEnd = addrIntVectApp + sizeIntVect - 1;
  192. // 2.2) Application program:
  193. // follows the application's interrupt vector table and takes @sizeApplication:
  194. define symbol addrApplication = addrIntVectAppEnd + 1;
  195. define symbol addrApplicationEnd = addrApplication + sizeApplication - 1;
  196. // 2.3) Program Version Sector:
  197. // located in the tail of the dynamic firmware sector:
  198. define symbol addrProgversion = addrDynamicFirmwareEnd - sizeProgversion + 1;
  199. define symbol addrProgversionEnd = addrDynamicFirmwareEnd;
  200. // 2.3.1) Program Version Sector Data region
  201. // located at the beginning of the progversion section:
  202. define symbol addrProgverData = addrProgversion;
  203. define symbol addrProgverDataEnd = addrProgversionEnd - sizeProgverCRC;
  204. // 2.3.2) Program Version Sector Checksumm region
  205. // located at the end of the progversion section:
  206. define symbol addrProgverCRC = addrProgversionEnd - sizeProgverCRC + 1;
  207. define symbol addrProgverCRCEnd = addrProgversionEnd;
  208. // Note: 'symChecksum' will be used by 'ielftool.exe' to reference start address of checksum section.
  209. define exported symbol symChecksum = addrProgverCRC;
  210. // Note: 'symProgVers' is used by application to place the PROGVERSION structure using '@'
  211. define exported symbol symProgVers = addrProgversion;
  212. if( BOOTLOADER )
  213. {
  214. // Interrupt Vector Table: global definition for bootloader
  215. define exported symbol addrIntVect = addrIntVectBoot;
  216. define symbol addrIntVectEnd = addrIntVectBootEnd;
  217. define symbol addrProgram = addrBootloader;
  218. define symbol addrProgramEnd = addrBootloaderEnd;
  219. }
  220. else
  221. {
  222. // Interrupt Vector Table: global definition for application
  223. define exported symbol addrIntVect = addrIntVectApp;
  224. define symbol addrIntVectEnd = addrIntVectAppEnd;
  225. define symbol addrProgram = addrApplication;
  226. define symbol addrProgramEnd = addrApplicationEnd;
  227. }
  228. // CSTACK RAM-region:
  229. // Takes the first @sizeStack bytes from @baseRAM.
  230. // If overflows, it does not damage any other data.
  231. define symbol addrStackStart = baseRAM;
  232. define symbol addrStackEnd = addrStackStart + sizeStack - 1;
  233. // Service RAM-region:
  234. // Follows the CSTACK RAM-region and takes @sizeRamBootsign bytes
  235. define symbol addrSvcRamStart = addrStackEnd + 1;
  236. define symbol addrSvcRamEnd = addrSvcRamStart + sizeRamBootsign - 1;
  237. // Heap RAM-region:
  238. // Follows the Service RAM-region and takes @sizeHeap bytes
  239. define symbol addrHeapStart = addrSvcRamEnd + 1;
  240. define symbol addrHeapEnd = addrHeapStart + sizeHeap - 1;
  241. // Common RAM-region:
  242. // Follows the Heap RAM-region and takes @sizeCommonRam bytes
  243. define symbol addrRamStart = addrHeapEnd + 1;
  244. define symbol addrRamEnd = addrRamStart + sizeCommonRam - 1;
  245. // ============================= REGIONS ======================================
  246. // ------------------------------------------------------------------------------
  247. // Bootloader/Application Interrupt Vector Table (current project):
  248. define region regionIntVec = mem:[ from addrIntVect to addrIntVectEnd ];
  249. // Bootloader/Application program region (current project execution ROM):
  250. define region regionReadonly = mem:[ from addrProgram to addrProgramEnd ];
  251. // ------------------------------------------------------------------------------
  252. // Service RAM region:
  253. define region regionSvcRAM = mem:[ from addrSvcRamStart to addrSvcRamEnd ];
  254. // Common RAM region:
  255. define region regionRAM = mem:[ from addrRamStart to addrRamEnd ];
  256. if( sizeHeap > 0)
  257. {
  258. // HEAP RAM region:
  259. define region regionHeap = mem:[ from addrHeapStart to addrHeapEnd ];
  260. }
  261. // CSTACK RAM region:
  262. define region regionStack = mem:[ from addrStackStart to addrStackEnd ];
  263. // Program Version ROM-region (data only, no checksum):
  264. define region regionProgversion = mem:[ from addrProgverData to addrProgverDataEnd ];
  265. // Program Version Checksumm ROM-region (only checksum):
  266. define region regionProgverCRC = mem:[ from addrProgverCRC to addrProgverCRCEnd ];
  267. if( !BOOTLOADER )
  268. {
  269. // Bootloader-image region
  270. define region regionBootImg = mem:[ from addrFixedFirmware to addrFixedFirmwareEnd ];
  271. }
  272. else
  273. {
  274. // Application-image region
  275. define region regionAppImg = mem:[ from addrDynamicFirmware to addrDynamicFirmwareEnd ];
  276. }
  277. // ============================= BLOCKS ======================================
  278. // Defining blocks:
  279. // Main stack:
  280. define block CSTACK with alignment = 8, size = sizeStack { section .cstack };
  281. if( sizeHeap > 0 )
  282. {
  283. // Dynamic memory (Heap):
  284. define block HEAP with alignment = 8, size = sizeHeap { };
  285. }
  286. // Bootloader signature (App-->Boot data exchange)
  287. define block BOOTSIGN with alignment = 8, size = sizeRamBootsign { readwrite data section .bootsign };
  288. // USB-Buffers (logical block)
  289. define block USBBUF with alignment = 8, size = sizeUsbBuffRam { section .usbbuf };
  290. if( !BOOTLOADER )
  291. {
  292. // For Application:
  293. // Bootloader-image block: contains full fixed firmware image
  294. define block BOOTIMG with alignment = 4, size = sizeFixedFirmware { readonly data section .bootimg };
  295. // Application program version sector
  296. define block PROGVERSION with alignment = 4, size = sizeProgverData { section .progver };
  297. define block PROGVERCRC with alignment = 4, size = sizeProgverCRC { section .progvercrc };
  298. }
  299. else
  300. {
  301. // For Bootloader:
  302. if( APPIMGINBOOT )
  303. {
  304. // Application-image block: contains full dynamic firmware image
  305. define block APPIMG with alignment = 4, size = sizeDynamicFirmware { section .appimg };
  306. }
  307. }
  308. // ========================= Initializers ====================================
  309. // Initializers:
  310. initialize by copy { readwrite };
  311. do not initialize { section .noinit };
  312. do not initialize { section .bootsign };
  313. // =========================== Placement =====================================
  314. // Current project Interrupt Vector Table:
  315. place in regionIntVec { readonly section .intvec };
  316. // Current project executable readonly memory:
  317. place in regionReadonly { readonly };
  318. // Current project common readwrite memory (non-marked + marked):
  319. place in regionRAM { readwrite, section .flashram, section .grombuf, last block USBBUF };
  320. // Service RAM-region: BOOTSIGN block
  321. place in regionSvcRAM { first block BOOTSIGN };
  322. if( sizeHeap > 0 )
  323. {
  324. // Heap RAM-region
  325. place in regionHeap { first block HEAP };
  326. }
  327. // CSTACK region:
  328. place in regionStack { first block CSTACK };
  329. if( !BOOTLOADER )
  330. {
  331. // For Application:
  332. place in regionBootImg { first block BOOTIMG };
  333. place in regionProgversion { first block PROGVERSION };
  334. place in regionProgverCRC { first block PROGVERCRC };
  335. keep { section .bootimg, block BOOTIMG , section .progver, section .progvercrc };
  336. }
  337. else
  338. {
  339. // For Bootloader:
  340. if( APPIMGINBOOT )
  341. {
  342. place in regionAppImg { first block APPIMG };
  343. keep { section .appimg };
  344. }
  345. }
  346. keep { section .intvec, section .bootsign, block BOOTSIGN };