Sunday, May 24, 2020

Executing with in Ram

After working out how to get the SDRAM working on the new hardware via the FMC (Stm32). Now testing and It APPEARS to be working.
Thats 8 Megabyte of RAM!.

Inside the 2 Meg ROM I have written something that will load a BIN file into the RAM and execute.
After that would perform a CPU jump!

The following section is called to jump to the program that is stored at memory location!

#define APPLICATION_ADDRESS 0xD0000000
typedef  void (*pFunction)(void);
pFunction JumpToApplication;
void Jump( void ) {
	GPIOD->BSRR = (1 << 11);// << 16;
	HAL_Delay(500);
	//CPU_CACHE_Disable();
	SysTick->CTRL = 0;
	//__disable_irq();
	JumpToApplication = (pFunction) (*(__IO uint32_t*) (APPLICATION_ADDRESS + 4));
	__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
	SCB->VTOR = APPLICATION_ADDRESS;
	flogf("Address to Application: %lXrn", JumpToApplication);
	JumpToApplication();
}

—————
The LINKER file for the “bootloader” - our program that is in 2MB Rom -
IN the linker there is a memory section named MADDI, this is where the external ram is located, the FMC takes care of the bus and signals needed, basically this is a SDRAM memory controller - it allows for very large variables and arrays[s].

eg…
MADDI (xrw) : ORIGIN = 0xD0000000, LENGTH = 8M

/**
 ******************************************************************************
 * @file      LinkerScript.ld
 * @author    Auto-generated by STM32CubeIDE
 * @brief     Linker script for STM32F767IGTx Device from STM32F7 series
 *                      1024Kbytes FLASH
 *                      512Kbytes RAM
 *
 *            Set heap size, stack size and stack location according
 *            to application requirements.
 *
 *            Set memory bank area and size if external memory is used
 ******************************************************************************
 * @attention
 *
 * <h2><center>© Copyright (c) 2020 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);	/* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200 ;	/* required amount of heap  */
_Min_Stack_Size = 0x400 ;	/* required amount of stack */

/* Memories definition */
MEMORY
{
  RAM   (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
  FLASH (rx)  : ORIGIN = 0x8000000,  LENGTH = 1024K
  MADDI (xrw) : ORIGIN = 0xD0000000, LENGTH = 8M
}

/* Sections */
SECTIONS
{
  /* The startup code into "FLASH" Rom type memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

  /* The program code and other data into "FLASH" Rom type memory */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH

  /* Constant data into "FLASH" Rom type memory */
  .rodata :
  {
    . = ALIGN(4);
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    . = ALIGN(4);
  } >FLASH

  .ARM.extab   : { 
    . = ALIGN(4);
    *(.ARM.extab* .gnu.linkonce.armextab.*)
    . = ALIGN(4);
  } >FLASH
  
  .ARM : {
    . = ALIGN(4);
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
    . = ALIGN(4);
  } >FLASH

  .preinit_array     :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
    . = ALIGN(4);
  } >FLASH
  
  .init_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
    . = ALIGN(4);
  } >FLASH
  
  .fini_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
    . = ALIGN(4);
  } >FLASH

  /* Used by the startup to initialize data */
  _sidata = LOADADDR(.data);

  /* Initialized data sections into "RAM" Ram type memory */
  .data : 
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */

    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
    
  } >RAM AT> FLASH

  /* Uninitialized data section into "RAM" Ram type memory */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss section */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM

  /* User_heap_stack section, used to check that there is enough "RAM" Ram  type memory left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM
  
  	.extram :
    {
    	//. = ALIGN(8);
        *(.extram)           /* .data sections */
    	*(.extram*)          /* .data* sections */
    	KEEP (*(SORT(.extram.*)))
    	KEEP (*(.extram*))
    } >MADDI
  

  /* Remove information from the compiler libraries */
  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

  .ARM.attributes 0 : { *(.ARM.attributes) }
}

if you notice the “ROM” area is in 0xD0000000 THIS is where the FMC bus looks up the SDRAM-BANK1

/**
 ******************************************************************************
 * @file      LinkerScript.ld
 * @author    Auto-generated by STM32CubeIDE
 * @brief     Linker script for STM32F767IGTx Device from STM32F7 series
 *                      1024Kbytes FLASH
 *                      512Kbytes RAM
 *
 *            Set heap size, stack size and stack location according
 *            to application requirements.
 *
 *            Set memory bank area and size if external memory is used
 ******************************************************************************
 * @attention
 *
 * <h2><center>© Copyright (c) 2020 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);	/* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200 ;	/* required amount of heap  */
_Min_Stack_Size = 0x400 ;	/* required amount of stack */

/* Memories definition */
MEMORY
{
  RAM    (xrw)     : ORIGIN = 0xD0400000,   LENGTH = 2M
  FLASH    (rx)    : ORIGIN = 0xD0000000,    LENGTH = 2M
}

/* Sections */
SECTIONS
{
  /* The startup code into "FLASH" Rom type memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

  /* The program code and other data into "FLASH" Rom type memory */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH

  /* Constant data into "FLASH" Rom type memory */
  .rodata :
  {
    . = ALIGN(4);
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    . = ALIGN(4);
  } >FLASH

  .ARM.extab   : { 
    . = ALIGN(4);
    *(.ARM.extab* .gnu.linkonce.armextab.*)
    . = ALIGN(4);
  } >FLASH
  
  .ARM : {
    . = ALIGN(4);
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
    . = ALIGN(4);
  } >FLASH

  .preinit_array     :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
    . = ALIGN(4);
  } >FLASH
  
  .init_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
    . = ALIGN(4);
  } >FLASH
  
  .fini_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
    . = ALIGN(4);
  } >FLASH

  /* Used by the startup to initialize data */
  _sidata = LOADADDR(.data);

  /* Initialized data sections into "RAM" Ram type memory */
  .data : 
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */

    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
    
  } >RAM AT> FLASH

  /* Uninitialized data section into "RAM" Ram type memory */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss section */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM

  /* User_heap_stack section, used to check that there is enough "RAM" Ram  type memory left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM

  /* Remove information from the compiler libraries */
  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

  .ARM.attributes 0 : { *(.ARM.attributes) }
}

with the Application it appears that you just create something as you would normally!

NOTE: compile to the BIN file, this wont work with .HEX or .ELF file!
the bin file contains OP codes

also this is said to run at about 5 times slow.. but have to rememeber, each step, the processor has to fetch a command, the fetch the data, then act upon the data, then store the result in one pipe.

where was program runs from the ROM and stores thigns in ram, this can be done with in just 2 cycles.

Sunday, May 17, 2020

A working DMA AUDIO output

sidboxv5begin.png The project begins to take life now; While its taken me a LONG time and most of my hair is still present!
I still have a long way to go, but I do have something that is causing us some excitement!

While working on the SDCARD (which now appears to be fully working now) I wanted to see if I could get the SDCARD to stream some audio.

At first I did this the old way as the Sidbox 4 does this, uses an interupt with a read and write audio buffer positions. While this works really well on the Sidbox 4 OS, this chip has 400Mhz and a few DMA channels, one of which is a DAC.

I can setup an audio buffer, and have that memory transferred at 441khz to the DAC, leaving the CPU free to do something else! The issue I got with this though is the DMA seems to collide a bit while using the FatFS (but thats just a current bug for now)

So the while it plays it just choses to put the new data in to the audio buffer

To Get this to work I had to wire up the following.

Note that this has NO Card Select! I was confused by this, but I found that I had to find away to tie the CS to 3.3v, the SDMMC1 port onthe STM32 takes care of everything else.

wiring-the-sdcard.jpg

So Now I have the SDCARD playing 8Bit Wav Files at 44100Hz and its done via the DMA,
all the CPU has to do when called via an interupt is to fetch another 1k of audio and stuff it in to the audio buffer.

Sunday, May 10, 2020

STM32H743ZI - Nucleo

nucleo.jpg While this bit of kit is nice looking, it has caused me alot of heart ache and frustration. It is MUCH different to that of the Microchips Eco System!

So if you are planning on moving away from Microchips to ST… BE Prepared to be spending alot of time getting to learn about the IDE and the example codes.

I Find my self stripping out code and learning how the chip works via the registers.

This Eco system by ST use something called HAL and it seems very bulky… However for right now I have no choice but to use the HAL_ stuff.

After pulling my hair out for days with the us of the SDCARD, and using MX to work out how to get things configured, I gave up.
I couldn’t find the research needed to help, and the manuals would take a long time. SO I did a cheat thing and found the demonstration code.

THIS allowed me to ensure that at least my wiring was correct and that it wasn’t the card that was broken or miss configured.

SO the demo code and the SDCAARD work

cleosd1.jpg The next issue I Faced was the problem of the card not really working well beyond the 2Gig. which would be a nightmware since out project needs to support up to about 32GIG, Fat32… Sadly the exFat comes with a hefty licence and just simply too expensive for us right now.

What this program does now is creats a text file, and spits “Hello world, this is a test file” then close the file
REMEMBER to close the file after you’ve done… some how it never gets commited to the card and looks like its doing nothing!

I am still having some seriously difficult times with this board due to its HAL and their eco system. The way the IDE copes with finding files and naming files I found to be an issue also.

The NEXT part I have to control now is making the UART to work, and that was tough enough as it was too.

WISH me luck.

BUT At least we got

  • Uart working (Debug and text output and input)
  • SDCard working (but not completely stable and signed off)
  • Able to use the GP I/O’s
  • I’ve already done the screen before so these screens work
  • DAC also works direct from this processor, so no external DAC is required.
  • STILL TO DO: External PSRAM access 133Mhz
  • Make Lots of money ;)

We’ll keep you posted as and when we get more features working on the new hardware.

The BOOT loader option might be a little tricky now since ST have no seperate rom for this, or at least i cant see how to make use of it yet, i need to get a demo of this working!

BUT that might come down later in the developement stage

Monday, May 4, 2020

And So, It begins!

sidboxv5begin.png AND so it begins, this is the info being returned from the new processor.

Took me all night, and I finally got it to do something!

The process of learning and being eager to get started and having some problems with the new IDE and methods for getting chips to turn on legs and not as fast as possible.

My Targets here is to get the following working…

  • Working: Serial port via a interupt.
  • Working: A Flashing light.
  • Working: BASIC: DAC with a basic Sawtooth output, i want to make this a DMA so I just dump audio into the DAC buffers.
  • TO DO: Display Driver.
  • TO DO: Buttons interfacing.
  • TO DO: SDCARD interfacing (this will be its own blog I believe. alot of work will be needed here I think.

sidbox5scope1.png

I hope to keep everyone updated here.

Monday, April 27, 2020

Sidbox 5 - Testing Board

It has come to our attention that the sidbox could do with a little more horse power, So what we have found was a new chip, the STM32H743

nucleo.jpg

It is 400Mhz (Can be 480 it appears!) of ARM CPU power! has 1 Meg of RAM ONBOARD!! and with 144 pin outs, This should allow for this like fast framerates, more animations on screen, and the ability to use external RAM transparently.

What we thought was to have this newer model come with 4 Meg of RAM, or 8 if we can find the same chip. I am still looking into what kind of RAM we can use, PSDRAM, DRAM or just good old (but expensive) SRAM.

So the new specs will be as follows!

  • 400 Mhz CPU
  • 1 Meg Internal Ram (for video and fast cache audio) with 4Meg External Ram
  • Internal DAC
  • DMA Screen data transfer (so the cpu can continue doing work while the screen is being updated!
  • Possible USB action, easy firmware update, it seems you just plug in the sidbox and it shows up like a drive letter, plop the new firmware on it and thats it!
  • More players, XM modules, and MORE S3M channels, i REALLY want to get TFMX to work

As We find out more about this chip and what it can do, We are sure to see some amazing things happening here

** This will not change the developement time because everything else is already done, unless we have to totally redesign the PCB and CASE which took me only a few weeks anyway **

I Really hope this new board will pose some serious applications!

Who knows! maybe a Sidbox Micro? Who wants to do some good BASIC on a Sidbox Micro? HANGS UP!!