Skip to main content
an_it
Associate III
October 12, 2012
Question

Read out Start-Up RAM values

  • October 12, 2012
  • 27 replies
  • 5560 views
Posted on October 12, 2012 at 11:28

Hey there,

I am pretty new to micrcontrollers and such. I recently bought a STM32VL Discovery, which I am programming with CoCoox IDE.

My goal is to read out the start-up values of internal RAM. By start-up values I mean the values of RAM cells just after the power-up of the device when no other application interferred with the ram.

Is this possible somehow? Could you guys guide me to some literature or give me some hints?

Thanks in advance!

#describe-the-goal-not-the-step
    This topic has been closed for replies.

    27 replies

    Tesla DeLorean
    Guru
    November 14, 2012
    Posted on November 14, 2012 at 17:01

    The chip could be flashed from blank via USB, so i assume there is some kind of

     

    bootrom with USB/USART drivers. The actual reset is probably sent to the bootrom, boot pins checked, and reset vectors then read, and execution passed ?

     

     

    Or the bootrom is not even mapped without boot request, the actual logic reads

     

    the reset vector and passes execution to flash ?

     

    The BOOTx pins define what memory is mapped at ZERO during startup, this can be FLASH, RAM or ROM. The ROM where the system loader is present always exists in it's native location 0x1FFFFxxx or whatever. It's possible to call this loader from a user application.

    RAM retains it's content across a processor reset, how it clears/sets at a power on event is another matter. Some of the memory has a TAMPER based clear.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    M0NKA
    Associate III
    November 15, 2012
    Posted on November 15, 2012 at 14:56

    Hi,

    Tnx for the info. In this case disassembly of the bootrom is useless. The OP just need

    to code a small asm routine to init one of the USARTs and loop all ram bytes on the

    TX pin as you suggested earlier. ARM offers enough registers anyway to code this

    without touching the RAM.

    Regards

    an_it
    an_itAuthor
    Associate III
    November 15, 2012
    Posted on November 15, 2012 at 16:27

    Hi folks,

    first off thanks for your help. M0NKA could you give me more detail on what would be a good solution?

    You suggest to write some ASM code to iterate over 0x20000000-0x20002000 and put every byte on USART TX to send ot to some kind of hyperterminal?

    Furthermore the ASM code can only work with the mcu's registers so it doesn't interfer with the ram.

    But where would i need to put the asm code? At the position we already have been talkin about: right at the beginning of the reset handler?

    Cheers

    Tesla DeLorean
    Guru
    November 15, 2012
    Posted on November 15, 2012 at 18:41

    You'd put the code at the point I have identified, and use a fairly simple loop to output to the serial port. This could be done with registers, and without calling or stacking.

    If you put this in a .C file you've probably already lost control. You'd need to disassemble the prologue code and confirm it wasn't doing anything.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    M0NKA
    Associate III
    November 16, 2012
    Posted on November 16, 2012 at 10:25

    Hi,

    I just checked, there is quite a lot of init needed for USART, and not forget the CPU

    clocks, PLL, etc. The easiest way is to create a new project, in C that reads the whole

    ram via USART. Then slowly start to remove all library calls and implementing it in

    a single function (main), using max optimization. You can continuously disassemble

    the result (IDAPro, your tool, etc) and see if the stack usage is completely removed.

    Finally you can copy the resulting asm (from IDAPro dump or asm output of compilier)

    and build new project in asm only.

    Not sure if it is possible to use the USART with default clock/pll values on startup. Also

    it is too much code to do by hand only in ASM, so maybe best to use the above method.

    Hope this helps.

    an_it
    an_itAuthor
    Associate III
    November 16, 2012
    Posted on November 16, 2012 at 10:40

    Hey M0NKA,

    thanks for your help. Phew..Looks like this exceeds my skills. It would take ages for me to accomplish this. I guess I'm kind of stuck here. I will have to postpone this when I've got more spare time.

    Thanks anyway.

    Andrew Neil
    Super User
    November 16, 2012
    Posted on November 16, 2012 at 11:49

    Why not just use the debugger to read the RAM contents?

    Then you wouldn't need any code in the chip at all!

    (well, maybe just an infinite loop in the reset vector to stop it executing rubbish).
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Tesla DeLorean
    Guru
    November 16, 2012
    Posted on November 16, 2012 at 12:43

    Not sure if it is possible to use the USART with default clock/pll values on startup. Also it is too much code to do by hand only in ASM, so maybe best to use the above method.

    Everything is runs at 16 MHz, you have to enable the peripheral/pin clocks, obviously, but USART setting only requires that you know what the core is actually running at.

    Your assembler coding methodology seems unnecessarily complicated. I can't see this taking more than a few dozen lines of code, figure about 20-30 minutes of effort. Now I've written Flashing libraries for these parts in assembler, as well as boot loaders, so my perspective here is a bit skewed.

    In this case disassembly of the bootrom is useless.

    Got one of those too.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    M0NKA
    Associate III
    November 16, 2012
    Posted on November 16, 2012 at 13:33

    Hi,

    I guess just the code generated by GCC, even with best optimization is bit rubish.

    Got spoiled by many years using ADS 1.2. But agree with you, the best would be

    to dig all registers and flags from the pdf and quickly code by hand. But this

    apply only for somebody who does a lot of assembler, on everyday basis.

    My method is maybe best for people who don't usually do asm coding/debugging.

    About the default clock, yeah i recalled that CoIDE startup do not include the SystemInit() call by default and all works, but was too late, already posted.

    BR, Chris

    Tesla DeLorean
    Guru
    November 16, 2012
    Posted on November 16, 2012 at 15:31

    Sorry, 8 MHz for the F1 series, way off in F2 and F4 land these days.

    ldr r0, =0x40021000 ; RCC
    ldr r1, =0x00004004 ; USART1EN | IOPAEN (GPIOA)
    str r1, [r0, #0x18] ; RCC_APB2ENR
    ldr r0, =0x40010800 ; GPIOA
    ldr r1, =0x444444B4 ; PA.9 USART1_TX 50MHz AF_PP
    str r1, [r0, #4] ; GPIOx_CRH
    ldr r0, =0x40013800 ; UART1
    movs r1, #0
    strh r1, [r0, #4] ; +4 USART_DR
    movs r1, #69 ; 8MHz / 69 == 115200
    strh r1, [r0, #8] ; +8 USART_BR
    movs r1, #0x0600
    strh r1, [r0, #16] ; +16 USART_CR2 = 0x600
    movs r1, #0
    strh r1, [r0, #16] ; +16 USART_CR2 = 0
    movs r1, #0
    strh r1, [r0, #24] ; +24 USART_GTPR = 0 - Prescaler
    movw r1, #0x200C ; 8-bit, no parity, enable TX,TX
    strh r1, [r0, #12] ; +12 USART_CR1
    ldr r2, =0x2000 ; Size = Length (8K)
    ldr r3, =0x20000000 ; Mem = RAM Address
    iu1 ldrh r1, [r0, #0] ; USART->SR
    ands r1, #0x80 ; TXE
    beq iu1
    ldrb r1, [r3], #1 ; [Mem++]
    strh r1, [r0, #4] ; USART->DR
    subs r2, r2, #1 ; Size--
    bne iu1

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..