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

The History of the Sidbox

sidbox0.jpgThe day I began to play with the microcontrollers was fun and interesting, from just turning on motors to lighting up LED’s.

While these where fun and I did make some pretty cool devices, such as a home automation. I began to yern for things like audio.

In the end I learned what I could get my hands on, and one day while listening to good old Sid tunes with Sidplay.exe, I thought, I’d love to hear this stuff on a chip, instant ON battery powered SIDPlay.

I created my own audio Sidchip with 8 channels, but it was fairly basic, didnt’ have Ring mod, PWM controls… So I desperately looked into how the C64 played its chip tunes and I found it was a lot more involved than I initially thought… As a result I slumped and almost gave up, after about a year I decided to have another go.

Starting with the need for the 6502 Core, and I wrote a small program on it and found that the core did work, the CORE emulation worked on a PIC MCU running on a 40Mhz chip!

So I proceeded to learn about the SID 8582 (it was the only chip I physically had) and begin to learn how this bird sang.

After MONTHS of tearing hair our, punching walls and crying, I got a sidchip working, but it wasn’t enough, the SIDCHIP worked in my c64, but i wanted to have it independently PLAY music from the MCU it self, that required the CPU emulation also, which sadly the 40Mhz MCU worked well enough to produce a very very low quality sid noise

Upgrading from an 8BIT MCU i used the dsPIC24, 16bit running at 70Mhz which MADE alot of difference, and built this…

This little device did everything I needed, so I added a very basic file system FAT16 to it, and would only read ONE file on the root, but it loaded that sid tune into its small ram, 32K (so only a small sid file was allowed, 1k) and more programming time was thrown into this.

It picked up the file and BADLY played the SID tune, BUT it gave it a go.
After many more weeks of figuring out whats going on, was a stupid signed char, not a unsigned char that made the difference…
Gates worked, pitch and audio stepping and phase worked!

this chip could only produce a small 22khz output but it was more than good enough for tiny speakers.

I started to think this was IT, a portable SID player! instant on, ready to go in a second and playing music! (greating cards anyone?)

sidbox_start.jpgI wonder if I could make a 4 channel amiga MOD play on this, there wasn’t enough memory to perform this action here, so I upgraded to another dsPIC33 which had 512k Rom, and 128k Ram,

THEN this little machine was born

this was the very very first sidbox made, it had no volume control nor a DAC, it was purely done with an amp, the TDA2822 with a PWM source in, wow the pure clean sound (lol) it was grainy and alot of electrical noise appeared on this amp too! no filtering (since I was still researching how to do this)

I used this for a few days, before I began to really redesign the mainboard, this has a volume control and much better noise handling however the PCB still was a 2 layer board so all the signal and power rails where all mixed up on the 2 layers, yupp that was a rookie mistake right there…

sidbox3.jpg

still this unit and I got on with each other for just a year.

Then microchip sent me a sample chip, just turned up at the door and I thought, ok I’ll see what this does…

THAT was the PIC32MZ that we all know and love today!

pic32mz.jpg

it currently runs our sidbox now. I’ve been developing the OS and the players and a total redesign of the PCB, 4 layer board, with the two power plates inside the board, giving it a nice capacitor feel so everything got a nice gulp of power where it needed, and shielding. all the signals on the top and bottom layers for ram and display and virtually ZERO noise! there was some from the display but that was gone when I tethered a ground wire from the displays shield plate! now, there is no sound at all! Well not that I can tell. even with the Scopes!

sidbox4.jpg

This is what the sidbox is today.

We have begun a nice facebook group and is gaining interest everyday!

Soon we’ll be able to start the kickstarter!

With everyone backing and supporting this project, we’ll go far!!!

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!!

Sunday, April 26, 2020

About the Sidbox

Using the microchips MCU and an EXTERNAL SRAM 512k worth, it allows cache the tunes into that area, it allows to run 6502 from there also and the internal 512k SRAM is used for the video graphics, and ton of functions.

The unit has the power to unLHA good old archvies into ram, and then play them.

PLEASE NOTE: The unit is unavailable for sales at the moment, multple sections still not programmed and debugged.

The Sidbox

sidbox.jpg I’ve decided to try to do a blog on the progress of the Sidbox project.

you can find more out about this in the Sidbox Facebook Group

This is the sound of the sidbox as it stands right now

Songs list

  1. 1: Make Love (not war) Atari ST (With EQ on) (YM)
  2. 1: Make Love (not war) Atari ST (With EQ off) (YM)
  3. 2: Sanxion C64 SID (With EQ on) (SID)
  4. 2: Sanxion C64 SID (With EQ off) (SID)
  5. 3: Kefmania-Theme Amiga MOD (With EQ on) (MOD)
  6. 3: Kefmania-Theme Amiga MOD (With EQ off) (MOD)
  7. 4: Dispostable Hero CD32 WAV (With EQ on) (WAV)
  8. 4: Dispostable Hero CD32 WAV (With EQ off) (WAV)

have a good listen to!