[sdiy] Executing guest synthesizer code on stm32f4

charlie charlie at finitemonkeys.com
Tue Dec 30 21:19:22 CET 2014


Hi,

Here is one approach, first things PC relative code (-fpic) and/or
data references, so you move the code around freely and it'll still
work. predefine the functions. then just use linker scripts to setup
areas in RAM that are executable, have a default routine in there or
such to start off with. The routines then will have predefined
addresses, just like normal code.

http://sourceware.org/binutils/docs/ld/Output-Section-LMA.html

the stm32's have SYSCFG_MEMRMP but from what i recall that might be
all or nothing, needs IV"s in RAM etc, so all the code is in RAM, but
take a look i don't recall the limitations of that.

You can also just copy chunks of pc relative code to a RAM location
and set a ptr to it then call it in the normal way, but all references
in that copied code have to be relative.

so the questions, how do you know ram, prefix it in the LD scripts,
that'll make it easier and manageable since everything is known, if
its going to be more complex, you'd need to make a simple memory
allocation routine that knows what and where is left. Static
allocation is the simplest.  for labels if you mean intra jump labels
in functions for C/asm code , PC relative code, for inter jumps
function pointers in C like

void (*my_awesome_routine)(char *buffer, int length) ;

where you set my_awesome_routine to point to the location of where the
copied code is , can either by ROM or RAM as long as its (a)
addressable by the CPU for code, and (B) pc relative.

so say the RAM location is 0x10000; you copy the function to 0x10000
then set my_awesome_routine to 0x10000. This is essentially what the
LMA sections do in the LD scripts, and the linker handles it with nice
names and such, but with LD its fixed location and lengths at runtime,
though you can choose to override it later, but might as well go with
the first approach.

with the prefixed routines if the user needs to call back to the host
ROM code, you can define it as a lookup table like an interupt vector,
so have a table that there is a global prefixed function able to be
always read from anywhere, that returns a pointer to the table, the
table is then a list of jump vectors, that you predefine, that way the
user code only needs to know the address of one function to get the
base address, and there's a fixed index to the routine they wanted.
the amiga OS did this, with a fixed location in memory as a baseline,
as an example.

http://amigadev.elowar.com/read/ADCD_2.1/Libraries_Manual_guide/node0290.html

its more or less how C++ classes work for functions, you can simulate
a C++ class in C this way, with FP's.



cheers,
charlie

On 30 December 2014 at 08:16, nvawter <nvawter at media.mit.edu> wrote:
>
> Hello All!
>
> I made a nice instrument based on the stm32f4 and I want people to be able
> to upload their own synth code into it via microphone.  Has anyone got any
> suggestions for how to do this?
>
> I think in theory the idea is to reserve some space in the linker file for
> the "guest code" (plug-in).  Then, use the main program to listen to the
> microphone, demodulate into the binary, then write the guest binary block
> into flash memory.  Then, have the main program call the guest code, leaving
> all of the sensor variables (such as control voltage, knob inputs, patch
> select knob, etc.) in a magic place, have the synth code execute, return a
> block of data, and have the main program write that to the DAC.
>
> Questions I'm having are: how does the guest code know what ram locations
> are available?  Should I statically allocate some RAM for the main program
> and some for the guest program?  How do I use labels in the code to jump
> back and forth between funcions?  E.g. if I write a "CV_to_pitch()" function
> and keep it in the main program, and I want the guest code to use that
> function.  Should I make an intermediate table of where those functions are
> in the flash code, for when they move around, creating my own linker in
> effect?
>
> Has anyone ever done this before?  Are there any reference examples like
> this around?  If anyone has any suggestions/tips/ideas, etc, please let me
> know.
>
> Also, I reached out to the stm32f4 subreddit with the same question, if
> anyone would like to respond there, or read the same request for help with
> different working:
> http://www.reddit.com/r/stm32f4/comments/2qtnsx/how_would_i_do_this_upload_blocks_of_binary_code/
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy



More information about the Synth-diy mailing list