<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Program Memory Constants</title><link>https://community.arm.com/developer/tools-software/tools/f/armds-forum/516/program-memory-constants</link><description> Note: This was originally posted on 22nd July 2013 at http://forums.arm.com I am using a Cortex-M0 with Keil uVision4.&amp;#160; How are constants located in program memory and how can these program memory constants be changed by code? </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Program Memory Constants</title><link>https://community.arm.com/thread/1089?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:56:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:895b8587-2724-4e2d-8d1d-089a3f5be0cf</guid><dc:creator>Scott Douglass</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 25th July 2013 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;There are two parts to the problem:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;1. getting the compiler to store the constants in just one place in FLASH&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;2. updating that place.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;The surest way of accomplishing #1 would be to define the the constants in a separate asm file.&amp;#160; But, using asm is probably a bit overkill; if you define them in a separate C file (and don&amp;#39;t let the compiler optimize across source files) you&amp;#39;ll probably be fine:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;calibration.h&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;struct CalibrationData {&lt;br /&gt;&amp;#160; ...&lt;br /&gt;};&lt;br /&gt;extern const struct CalibrationData mycal;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;constants.c:&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &amp;quot;calibration.h&amp;quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;extern const struct CalibrationData mycal __attribute__((section(&amp;quot;cal_data&amp;quot;))) = {&lt;br /&gt;&amp;#160; ...&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Now you can specify where in FLASH to place the &amp;quot;cal_data&amp;quot; section in the scatter file/linker script.&amp;#160; You&amp;#39;re code can find the values with mycal.foo, &amp;amp;mycal and sizeof(mycal).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I can&amp;#39;t really help with part #2; it is specific to the microcontroller and FLASH parts that you&amp;#39;re using.&amp;#160; Find out from the manufacturer(s) if they have examples/libraries to do In-Application FLASH Programming (IAP).&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program Memory Constants</title><link>https://community.arm.com/thread/1090?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:56:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:86c339a3-4208-42c9-8c56-d8f340879c68</guid><dc:creator>tom g</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 24th July 2013 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I want to store calibration constants for an external sensor in program flash since there is no onboard EEPROM. I have code that performs the calibration and determines the constants. Most MCU&amp;#39;s that I have worked with have assembler commands that write directly to program flash.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program Memory Constants</title><link>https://community.arm.com/thread/1088?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:56:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fe15d9af-5916-4a18-99fa-3792c1a184da</guid><dc:creator>Scott Douglass</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 24th July 2013 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;What is it that you&amp;#39;re trying to accomplish?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;If they change then they are not really constants; if the code is running and you change the constants (say, from a debugger) then there&amp;#39;s no guarantee that the code will still work.&amp;#160; For example two functions might share part of a constant literal.&amp;#160; It might be better to store the values in variables.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;The compiler has various ways encoding constants.&amp;#160; A constant might be part of an instruction, a piece of data in the same section as code or as a separate (read only) data section.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Changing a constant at runtime (once you&amp;#39;ve located it) might be simple if it&amp;#39;s in RAM or tricky if it&amp;#39;s in FLASH.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>