I am currently trying to implement the Arduino feature of resetting the microcontroller when a serial connection is made. This allows a new Arduino program to be uploaded without first reconfiguring the ice40, which I currently have to do.
This is turning out to be quite complex.
I thought I could just use the greset signal, but it is not straighforward. greset seems to be high when there is no serial connection and low when there is a connection.
If I reset the CPU when greset goes low, then the bootloader is restarted and its data wiped out. So for a program upload the bootloader is restarted, and the user program is uploaded and started. But if I then open the console, greset goes low and the bootloader is reentered and the program stops. Basically, you can't tell the difference between a program upload and the console (or other serial connection) being opened.
So what I think the standard Arduino bootloader does, is first to detect if there is a program in memory and then wait a little while to see if a program arrives on the serial connection and if so upload and start it, but otherwise restart the user program, if there is one. That may be possible but isn't particularly easy with MuraxArduino, partly because it is difficult to tell the difference between an uploaded program and any other data, and partly because the user program may get wiped out if it or its data is in BRAM.
Another option is to generate an interrupt when greset goes low and work out what to do in the interrupt routine. That has the advantage that the BRAM does not get reset.
Yet another option is not to use greset but to generate a uart break condition when starting the upload of a program. The f32c/arduno tool I am using does this, but the SpinalHDL uart implementation does not seem to detect break conditions. The emard/pjtrellis version of f32/arduino, which use picovor32, fairly recently changed picosoc's simpleuart.v to detect the break condition and use it to reset the cpu. To do this I would have to change the spinal.lib uart implementation and use my own version of it.
I am not sure what the best option is. Any advice would be appreciated.