tag:blogger.com,1999:blog-6997440551610060560.post3148498907908993876..comments2023-05-20T03:34:03.651-05:00Comments on Nathan's Development Blog: VolatileNathanhttp://www.blogger.com/profile/14248157226095069791noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6997440551610060560.post-5612384048039812382015-06-12T09:57:03.754-05:002015-06-12T09:57:03.754-05:00Yeah, casting to 8-bit and making a loop used to w...Yeah, casting to 8-bit and making a loop used to work, back in 2008 :)<br /><br />Ah well, I guess that probably explains it. (Alternatively, I probably could have gone the really cheesy way and left some of my debugging code in there!)Nathanhttps://www.blogger.com/profile/02763963217187530121noreply@blogger.comtag:blogger.com,1999:blog-6997440551610060560.post-45763755879910728012015-06-12T09:52:19.100-05:002015-06-12T09:52:19.100-05:00I also tried casting data to 8-bit and making a lo...I also tried casting data to 8-bit and making a loop... but no dice.<br />So I finally choose to use a 'shadow-copy' in regular RAM and write two small custom ARM ASM routine to move data from and to SRAM.<br />Also, no$debug can detect if you're writing to SRAM using illegal opcodes.<br />sverxhttps://www.blogger.com/profile/13552101081332715415noreply@blogger.comtag:blogger.com,1999:blog-6997440551610060560.post-33434919317465647502015-06-12T09:35:27.084-05:002015-06-12T09:35:27.084-05:00Yeah, that makes sense. I dunno -- maybe it does h...Yeah, that makes sense. I dunno -- maybe it does have to do with the compiler trying to optimize it into 16 or 32-bit writes. (despite me casting the data to a 8-bit value and looping through writing it 8 bits as a time). I wonder if marking it volatile tricked the compiler into not over-optimizing that.Nathanhttps://www.blogger.com/profile/02763963217187530121noreply@blogger.comtag:blogger.com,1999:blog-6997440551610060560.post-8517440850207310952015-06-12T06:49:51.226-05:002015-06-12T06:49:51.226-05:00volatile? There must be some mistake.
I never had ...volatile? There must be some mistake.<br />I never had to declare variables in SRAM as 'volatile', because in fact they aren't (unless you've got an Interrupt Service Routine changing them too!)<br />The real mess with SRAM and C, it's that this memory can be written ONLY using 8-bit writes and the C compiler will instead try to optimize the writes using 16-bit and 32-bit writes, which can FAIL (not write anything or even mix up data!)sverxhttps://www.blogger.com/profile/13552101081332715415noreply@blogger.com