Author Topic: Really Bare Metal Programming on CubieTruck  (Read 21031 times)

Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #15 on: March 23, 2015, 07:04:05 pm »
Hi Thomas

Unfortunately I don't have a device with an SPI input.

However, I will see if I can use NDMA to copy from SDRAM to SDRAM and let you know.


Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #16 on: March 28, 2015, 08:38:42 pm »
Hi Thomas

I have been unable to get the DRAM to work on my Banana PI board.

Could you please post the DRAM initialisation code that you used to get it working on your CubieBoard.

Once I get the DRAM working I can continue with the DMA tests.

Thanks Thomas.

Offline Goatfreed

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #17 on: March 31, 2015, 01:29:27 am »
Hi baremetal,

I will do so. But it might take 'till tuesday next week, if i don't find the time today (vacation :) )

Regards,
Thomas

Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #18 on: April 04, 2015, 07:07:40 am »
No problem Thomas.

Enjoy your break!

Offline Goatfreed

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #19 on: April 07, 2015, 04:19:32 am »
Hi,

as promised, find attached "my" code to initialize the DRAM.
The function "DRAM_initialize" is the only one that needs to be called from outside.
Please note that I researched a lot to get this running as there is no open documentation available for the DRAM-Controller in A20.
Therefore this code is not that pretty (test-coding, not yet refactored) and there might be unneeded or non-optimal code in it.
But it worked for me (at least with CPU-access, not with DMA).
The following code was my test access (WORD_PTR is defined as " volatile unsigned int * "):
Code: [Select]
    unsigned int regval;
    CCU_PLL5_set_factor_K(0);
    CCU_PLL5_set_factor_M(0);
    CCU_PLL5_set_factor_P(0);
    CCU_PLL5_set_factor_N(20);
    CCU_PLL5_enable();
    timer_wait_micro_seconds(0,10000);
    CCU_PLL5_enable_ddr();
    timer_wait_micro_seconds(0,5500);
// setup mbus clock (PLL5)
    regval = 0x82000000U;
    *((WORD_PTR)(0x01C20000+0x15C)) = regval;
    timer_wait_micro_seconds(0,5500);

// close and open DRAMC and DLL gating
    regval = *((WORD_PTR)(0x01C20000+0x60));
    regval &= ~(0x3<<14);
    *((WORD_PTR)(0x01C20000+0x60)) = regval;
    timer_wait_micro_seconds(0,5500);
    regval = *((WORD_PTR)(0x01C20000+0x60));
    regval |= 0x3<<14;
    *((WORD_PTR)(0x01C20000+0x60)) = regval;
    timer_wait_micro_seconds(0,5500);

    DRAM_initialize();
    timer_wait_micro_seconds(0,5500);

    *((WORD_PTR)0x40000008) = 0xAAAAAAAA;
    *((WORD_PTR)0x40001008) = 0xBBBBBBBB;

I think setting the clock should not be an issue, so I do not include that coding here, but if I should for any reason, just ask for it (anyone).

Regards,
Thomas

Offline Mike Kaiser

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #20 on: April 10, 2015, 05:17:10 am »
Hmmm I thought I might be able to help out and start looking at your DRAM / DMA problem but I'm stuck at the first hurdle.

When I compile my code, if I keep it nice and simple and just toggle some LEDs, it's fine. But the moment the code gets a little complicated GCC pushes some registers on the stack. At that moment, the CPU just hangs. It even hangs if I do a push from entry.s so I'm trying to fathom out the right MMU / DRAM registers / values to poke to let me do anything more complicated (I'm assuming memory is readonly and an exception in being generated).

Once there, I hope I can help out somehow.

Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #21 on: April 14, 2015, 05:20:03 am »
Hi Thomas and Mike

Apologies for the delay in responding.

I do all of my work in hand coded assembler so I need to port the C code that Thomas provided to ARM7 assembler.

The other reason for the delay is that the Banana Pi Board uses different RAM chips to the ones used on the Cubieboard, so I need to adjust the code to deal with that.

This would all be fairly easy if Allwinner published the details of the DRAM controller that they use in the A20, but of course they don't!

I am going to spend a few more hours on trying to get the DRAM to work, but if I don't succeed then I will need to give up because of other projects that I am working on.

Thomas, I presume you know that DRAM is much slower than SRAM so unless you need a large amount of memory to do whatever you want to do, you should just use the SRAM in the A20.



Offline Goatfreed

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #22 on: April 15, 2015, 02:02:40 am »
Hi baremetal,

no need to apologise.
I find it very generous that you are willing to take effort to help us.

Yea, don't know why they don't publish that controllers' documents. Would make it much more easy.

If you have no more time for it, thats not a problem to me. Hopefully i find the solution myself some time (I also am not working "full-spare-time" on it because of other parallel projects).

Yes, I know SRAM is faster. I need it to push data to an LCD-Module (not character-like, but pixel-like).
For know the SRAM might be enough, though I would need to calculate. But in future i want to use a bigger screen (then probably not with SPI, as this wouldn't do it any longer I guess).
Maybe I consider the SRAM-solution as intermediate until i get the DRAM-DMA transfer working...

Regards,
Thomas

Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #23 on: April 15, 2015, 08:47:10 pm »
Hi Thomas

Unfortunately I have not been able to initialise the DRAM on my Banana Pi Board.

It is impossible to troubleshoot the issue because there is no documentation on more than 90% of the SDRAM registers that are involved so blindly setting values from Linux C code is a waste of time (especially when different RAM chips are involved).

I am actually going to abandon the Banana Pi altogether now as the Allwinner A20 Manual does not contain any details on the Gigabit Ethernet system either and I needed to use Gigabit Ethernet for the project that I am working on. The Allwinner documentation is terrible and they should really look at other vendors (eg Microchip) to see the standard that they need to come up.

I am happy to assist you when you do some PIC work as I have a lot of experience with PIC16 and PIC32 chips. They are also very well documented and supported by Microchip and can be programmed in hand-coded assembler very easily.

Sorry I was not able to help out on the DMA.

Offline Goatfreed

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #24 on: April 16, 2015, 01:34:49 am »
Hi baremetal,

no problem whatsoever.
I will try a little longer and if i don't get it to work, I will as well change "my chipset" for that project and use the cubietruck for something else (which will still be baremetal programming).
This time I'm gonna be looking at the documentation in detail first. For the Cubietruck I only took a short look (as I did not really have clue that time anyway) and then a long look at the specs (which are awesome).

Yea as first project with the PICs I want to build a simple (and later maybe more advanced) digital clock with an 20x2 Character LCD and a RealTimeClock chip.
The PIC can already drive the Character LCD (not a problem at all, and of course Assembly :) ).
I think the PIC I am currently using is PIC18F??K20 or something.
Probably overpowered for that, but hey, its my first usage :)
But for questions and answers for PICs I guess this is the wrong forum, isnt it?

Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #25 on: April 16, 2015, 08:27:05 am »
Hi Thomas

I had one more bash at it tonight and managed to get the DRAM going.

I then tweaked the DMA Code snippet that I posted the other week and successfully transferred one Word from DRAM to DRAM.

Here is the amended code. Let me know how you go.

/* Make the first four bytes of DRAM 77's */
    ldr r0, =0x77777777
    ldr   r1, =0x40000000
    str r0, [r1]

    /* Turn AHB Gating for DMA on */
    ldr   r1, =0x01C20060
    ldr r0, [r1]
    orr r0, r0, 0x40
    str r0, [r1]

    /* Disable DMA IRQ Interrupts */
    mov r0, 0x00
    ldr   r1, =0x01C02000
    str r0, [r1]

    /* Enable NDMA Auto Gating */
    mov r0, 0x00
    ldr   r1, =0x01C02008
    str r0, [r1]

    /* Set r1 to the Base Address for Channel 0 */
    ldr   r1, =0x01C02100

    /* Set Source Address */
    ldr r0, =0x40000000
    str r0, [r1, #0x04]

    /* Set Destination Address */
    ldr r0, =0x40000010
    str r0, [r1, #0x08]

    /* Set Byte Count */
    mov r0, 0x04
    str r0, [r1, #0x0C]

    /* Configure and Start DMA Transfer */
    /* (Use DRAM as the Source and Destination) */
    ldr r0, =0x84760476
    str r0, [r1]

Offline baremetal

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #26 on: April 16, 2015, 04:41:30 pm »
Hi Thomas

If my new code snippet works for you, but you still have problems transferring things to the SPI module using DMA, you should try a 16 bit data width just in case the internal connections between the DMA controller and the SPI module are not 8 bit (which is what my original code snippet uses) or 32 bit (which is what my new code snippet uses). Good luck!

Offline Goatfreed

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #27 on: April 21, 2015, 01:07:44 am »
Hi baremetal,

thanks again.
I try to find the time to check it this week or weekend and inform you here about the result.

Offline Goatfreed

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Really Bare Metal Programming on CubieTruck
« Reply #28 on: May 21, 2015, 01:57:07 am »
Just a quick note, in case anyone waits for the results of my current problem.
I did not forget to post it, just had no time to even try it.
Hopefully this weekend I will have time, but no guarantee (In fact it is even unprobable).

Sorry for that, but i will eventually test it and post the result.