在内部写入at91sam7s256 flash

时间:2015-12-08 13:14:14

标签: c arm embedded atmel flash-memory

我目前正在为基于Atmel的91sam7s256 MCU的设备开发一项功能。该特征是具有预设值的计数器,其在某些点处减小。 我的想法是在内部闪存中实现这​​个计数器,因为大多数闪存空间都没有使用。

我在ld脚本中添加了一个单独的链接器部分,并在此部分中包含了一个变量。链接描述文件:

Private Sub FormatShapeLegend(sheet As Worksheet, legendName As String, targetColor As MsoRGBType)
    Dim shp As Shape
    Dim chrt As Chart
    Dim s As Series

    For Each shp In sheet.Shapes
        If shp.HasChart Then
            Set chrt = shp.Chart

            'Loop the dataseries to find the legend with the desired name.
            For Each s In chrt.SeriesCollection
                'If the name fits, go ahead and format the series.
                If LCase(s.Name) = LCase(legendName) Then
                    s.Format.Fill.ForeColor.RGB = targetColor
                End If
            Next
        End If
    Next
End Sub

计数器递减时使用以下程序:

FormatShapeLegend ActiveSheet, "ISO", RGB(0, 0, 255)

但代码仍然存在 /* FLASH is reserved for internal settings */ MEMORY { CODE (rx) : ORIGIN = 0x00100000, LENGTH = 252k FLASH (rx) : ORIGIN = 0x0013F000, LENGTH = 4k DATA (rwx) : ORIGIN = 0x00200000, LENGTH = 64k } __FIRST_IN_RAM = ORIGIN(DATA); __TOP_STACK = ORIGIN(DATA) + LENGTH(DATA); /* Section Definitions */ SECTIONS { /* first section is .text which is used for code */ . = ORIGIN(CODE); .text : { KEEP(*(.vectorg)) . = ALIGN(4); KEEP(*(.init)) *(.text .text.*) /* remaining code */ *(.gnu.linkonce.t.*) *(.glue_7) *(.glue_7t) *(.gcc_except_table) *(.rodata) /* read-only data (constants) */ *(.rodata.*) *(.gnu.linkonce.r.*) . = ALIGN(4); } >CODE . = ALIGN(4); /* .ctors .dtors are used for c++ constructors/destructors */ .ctors : { PROVIDE(__ctors_start__ = .); KEEP(*(SORT(.ctors.*))) KEEP(*(.ctors)) PROVIDE(__ctors_end__ = .); } >CODE .dtors : { PROVIDE(__dtors_start__ = .); KEEP(*(SORT(.dtors.*))) KEEP(*(.dtors)) PROVIDE(__dtors_end__ = .); } >CODE . = ALIGN(4); _etext = . ; PROVIDE (etext = .); /* .data section which is used for initialized data */ .data : AT (_etext) { _data = . ; KEEP(*(.vectmapped)) . = ALIGN(4); *(.fastrun .fastrun.*) . = ALIGN(4); SORT(CONSTRUCTORS) . = ALIGN(4); *(.data) *(.data.*) *(.gnu.linkonce.d.*) . = ALIGN(4); } >DATA . = ALIGN(4); _edata = . ; PROVIDE (edata = .); /* .bss section which is used for uninitialized data */ .bss (NOLOAD) : { __bss_start = . ; __bss_start__ = . ; *(.bss) *(.bss.*) *(.gnu.linkonce.b.*) *(COMMON) . = ALIGN(4); } >DATA . = ALIGN(4); __bss_end__ = . ; .flash : { . = ORIGIN(FLASH); *(.flash*) . = ALIGN(4); } >FLASH _end = .; PROVIDE (end = .); } 。从未到达下面的行,因为MCU跳转到异常循环(向量表中的地址0x60)。

无论如何,数据似乎写得正确,因为重置后计数器变量减1。

谁能告诉我我做错了什么?代码没有被中断。

1 个答案:

答案 0 :(得分:2)

代码导致异常,因为它在尝试编程闪存时正在执行闪存。写入闪存模式寄存器后,将无法再从闪存中读取指令。编程闪存的功能应该放在RAM中。