Skip to content

SoftConsole example rendering mandelbrot fractal with ASCII characters running Mi-V floating point core

Notifications You must be signed in to change notification settings

AntonKrug/miv-rv32imaf-mandelbrot-uart

Repository files navigation

Mandelbrot fractal ASCII renderer

This SoftConsole example project demonstrates how to use floating point arithmetic on a Mi-V Soft processor running at 40MHz.

Examples of output:

::::::::::::::-=-:::::::::::::::::::::::::::::::::::::::::::::::--==---=+#++*+=-----+--*=:::::::::::::::::::::
::::::::::::--=+*==-:::::::::::::::::::::::::::::::::::::::::::--=*+* +=+###*%+#@===+*#+-:::::::::::::::::::::
-:::::-++-----=+----:::::::::::::::::::::::::::::::::::::::::::-----=+%++ *##++==@#**==+=-::::::::::::::::::::
-------=+=--=#+-----:::::::::::::::::::::::::::::::::::::::::::------====++*@+===---------::::::::::::::::::::
-++**===++=+*#=-----::::::::::::::::::::-* ------:::::::::::::--------===+# %===---------:::::::::::::::::::::
----===+#*+===-------::::::::::::::::::---=# ++*+----:::::::---------===+#  +===--------::::::::::::::::::::::
-----*+*++ *==---------::::::::::::::---%=++#+==------------------+ *+==++@%%*+==------:::::::::::::::::::::::
----++=====***+=+*-----------::-----------=++**==----------=#======+*%#%**#@#*+@% ----::::::::::::::::::::::::
-=+#=------==+***=====##@-----------------==* +==----------=%#+ ++##      #++*==------::::::::::::::::::::::::
=+=+-------+#=++* * #%+==-----=---------=% +# ++==-------=*%#*%   @*%  %**+===--------::::::::::::::::::::::::
::::::---------==+    #++=++=+*==-------==+* #**+==========+++* #+++++% #% +==--------::::::::::::::::::::::::
::::::::::------=+ #**+*%@*# *====----====++*@*++=========+++#@ ++++====+ +==----------:::::::::::::::::::::::
:::::::::::::---=++=====+*#*% ++===========+  %*++====+#*#* ## # %+========--------------:::::::::::::::::::::
::::::::::::::--------=+%%+++*  * **+#+===++# %% +++++#@      %#%*+======-------------------::::::::::::::::::
:::::::::::::::-------- =====+#*@@  #*++++++*   *++++**  ### @*++=======---------------------------:::::::::::
::::::::::::::::------------==+*++ **   %%***% #***      ****% +========------------------------------------::
::::::::::::::::-------------=====+++* @%   #% %#   %% %%++++++==========--------------------------------@%---
::::::::::::::::-------------=======++++**##%    %@#***+++++++============----------------------------- @  *=-
:::::::::::::::-------------========++++*##  @%@ %#****++++++==============-----------------=%===-----==++#*==
:::::::::::::::-----------=======++* **#   %####%   #****+++++================------------==+*  +====+ ** #@=-
:::::::::::::-----------==+*+==++# @@%    ##***#    %##  #  *++++++++*+==+#@+=======-=======++*  # +++* #*++==
:::::::::------------=*=+ *@*+++#@  @#****+++****%#   %%  @ #*++++++*  *+   +================@*#  ***# %#@ #@#
::::::-====---------==%# %   @   @ @% %#+++++++**##%          #*++**   @# %#@#+==+=========+ @   @###% @  %#**
::::::-==#===------===++ # *****@##%#++++++++++**#        %%##*******%     @## @@% +=======++ **#@ @%%        
::::::---=+# @======  *%  %*+++++++++++=====++++*#   @@     %# %@  ###%%   % @ #  +++=====+++++*@ %@        ##
::::::-+=+++%+=====++*#     +++===============++*** @##       @   @%%      @##***++++++++++++++****##%%%@  %%*
::::---==+* #*+*#%#***#%@ *@*@================++++****##%@                @%%#*****++*##++**++*****###%      *
::=+--=*%+*#*+%#+++*@ **++++++===============++++++***#                        #***#        ***###  %%      #%
:-=#+**===*@+=====+*++@ *====----===========%++******#%                         ####%     %###                
---#+-----==**=-------== =-----------======*%@   %#####%@                      %%%@ @@       %%@              
::::::----= *=-------------------------======++*   %#                                                         
:::::::::--==---------------------------=====*     @                                                          
:::::::::::::----------------------------==++@% @  @@                                                       @ 
::::::::::::::::::-----------------------== #@ *# @%###%@                                                     
::::::::::::::::::::::-------------------=====+*# %#**%                                                       
::::::::::::::::::::::::-----------------=====+@@******    @                                                  
:::::::::::::::::::::::::---------------========+++++****##%@@                                                
::::::::::::::::::::::::::-----------============+++* %###%

:::-=---+=-:::::::::::--+--:::::::::::::::::::::::::::::::=--*-=--+-:::::-=--#---::--=------==--:::::::::=::+:
::-=---=%=----:::::::--+---::::::::::::::::-::::::::::::::::::-====::::::+=-=--------+-+=---+-----:::::-:---*:
::::::--==----=-::::::-=------+:::=-::::::-=:::::::::::::::::::--+-=-::::-=-=-==-----====+=*+=-=--:::::---::::
::::--+====--+--::::::--=---=------*-:::::-+--=:::::::::::::::*--@==+-:::-----*=+=======-+=--+=+---:::-+--::::
::::--==--==++=--=-::---==--+=*-=-==-:::::----::::::::::::::::-===#------------+**+%+=+---=---=@--------=-==::
::----:---+=-+=--=-------=----=+*+*--=-+----=-=::::+:::::::::-+*--==--=-#--====+#%+=-----------==+--#---+---==
:::-+::::----=*=-*+--#==+%-----=--+=--=----=+--:::-+-::=-::::-----=#=--==---=#+==+*==----::::-=--+**=-=+--::::
::##::::::---+=+++=+===+----------=@+*#*---+%=--:--=---+--::------=+====+%++*+=+-*=+------::::::**--==*=--::::
:-::-:::::::-=+--#-==-----:::::----====+++=*=------=-=---------===%*=+#+%=--+----=-==+----:::::-*----=%#=-::::
:::::::::::----:::-----::::::::----%---===%=-+-----=++------+=--=*+=----=---==-------=--=-::::::::::+-++-=---:
:::::::::::::--::::@--::::::::::%===*-----+==+=------=+==----**+=++==---------+:::--#-::-=::::::::::--+=-==--:
::::::::::::=#-::::::::::::::::::--=*-----+*#=-------==#===+==*===-=------:::::::::=--::--:::::::::::-=-----=-
:::::::::::::::::::::::::::::::::--+-----+==+ =--*-=-==#===+*#===--------::::::::::-=::::::::::::::---=--::--=
::::::::::::::::::::::::::::::::::---------#*#==+=====+%+#+*%%====--------::::::::::::::::::::::::-:=::--:::--
:::::::::::::::::::::::::::::::::::::-----==#++===++==+***#% *#+==----=-=--:::::::::::::::::::::::::::-*:::-+-
:::::::::::::::::::::::::::::::::::::----#+==#+===+%++@#    #+*==----===-=*-::::::::::::::::::::::::::-::::*=:
:::::::::::::::::::::::::::::::::::::--++--===#+*++%* %     %*+===+=-=+-----::::::::::::::::::::::::::::::::--
::::::::::::::::::::::::::::::::::::--------==+**%# @        #@*+== +--++-::::::::::::::::::::::::::::::::::#:
:::::::::::::::::::::::::::::::::----------*=+# @            *++=++=---=+-:::::::::::::::::::::::::,,,,,,:::::
:::::::::::::::::::::::::::::::-==------=-=+=+#            @#*+=====*---=-*::::::::::::::::::::::,,,,,,,,,,,,,
::::::::::::::::::::::::::::::::-= ----==+===**             %*++++-------::::::::::::::::::::::::,,,,,,,,,,,,,
::::::::::::::::::::::::::::::::-=+=----==+%#+%#             #*+==-----::::::::::::::::::::::::::,,,,,,,,,,,,,
::::::::::::::::::::::::::::::::--=+---*+%=+++*@            %*+==---=--::::::::::::::::::::::::::,,,,,,,,,,,,,
:::::::::::::::::::::::::::::::----=*=========**@            %**==*=----:::::::::::::--::::+:::::,,,,,,,,,,,,,
::::::::::::::::::::::::::::--==-----==-----==* *#% @       @#%=* =-------::::::::=---#-:::=-:::::,,,,,,,,,,,,
:::::::::::::::::::::::::::-=--+%+-+=*=----=+=*#+*+*%%@   *++%====+==---=--:::::---===-=--=#:::::::,,,,,,,,,,,
::::::::::::::::::::::::::::::-=++=#==------==#==++*++@*++*+==++-==%=----=---::--+------=-=-=:::=::,,,,,,,,,,,
:::::::::::::::::::::::::::::::-------------==+=== #*==+==+*=-----==#= =+=----------::::+:=--:::-::,,,,,,,,,,,
:::::::::::::::::::::::::::::::----------------==+*==--===#+*-----#-=====+++-=-=-=-=:::::::--%=-:::,,,,,,,,,,,
:::::::::::::::::::::::::::::::::-------------==+% =+----===+=*-----==---=------=--=-::::::+:%--=::,,,,,,,,,,,
::::::::::::::::::::::::::::::::::--------=--=++*+=#+==------*-+---==--::::--::-::-#--:::::::----:::,,,,,,,,,,
:::::::::::::=--::::::::::::::::::---------==++++=-----=----+-- -::=---:::::-:::::---::::::::---::::-:,,,,,,,,
::::::::::::::- -+::::::::::::::::-------%%+=+*++@==----:--*-::=::::----::::::::::-+-:-::::::::*--:::=:,,,,,,,
:::=:::::::::==+--::::::::::::::-----------===+#=-=----:::::::::::::=-:-:::::::::::---:::::::::=:::+,,,,,,,,,,
-=--:-:::::-=*#*--:::::::---=----==-=------=*+@=-------::::::::::::::::::::::::::----::::::,,,,:,,,:,,,,,,,,,,
:---+*-::::--+=----:::::--=-=-----+-=--=+=+=@+===----=##:::::::::::::::::::::::::--+-:::::,,,,,,,,,,,,,,,,,,,,
:::-*==-:::-##=-----:::---+=%=+----==+==+++#+=*++=--+--:::::::::::::::::::::::::::--+-=::,,,,,,,,,,,,,,,,,,,,,
:::+-#=-----##---------------==#----=+*#*%==@==+*=#=*-+-::::::::::::::::::::::::::+-:::::,,,,,,,,,,,,,,,,,,,,,

,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::                                                                                                                                                                 
,,,,,,,,,,::::::::::::::::::::::::::::-----------------------------------:::::::::::::::::::::::::::::::::::::                                                                                                                                                                 
,,,,,,,::::::::::::::::::::---------------------------------------------------------::::::::::::::::::::::::::                                                                                                                                                                 
,,,,,:::::::::::::::-------------------------------------=========+****++++======----------:::::::::::::::::::                                                                                                                                                                 
,,,::::::::::::------------------------------------===========++++**#  @*****+=========---------::::::::::::::
,::::::::::-----------------------------------==============+++++**##%@      #*++==========---------::::::::::
:::::::-----------------------------------===============++++++**#%@@       %%#*+++++=========----------::::::
::::----------------------------------===============++++++***#%@              %#*+++++++=======-----------:::
:---------------------------------==============++++*******###%%@              %%##****+++++++====------------
------------------------------============+++++**%      @@@                          %######@ %*+===----------
--------------------------========++++++++++****#%                                              *++===--------
---------------------=====+++++++++++++++*****#%%@                                            %#*+++===-------
--------------=====++*******+++++++*******###%                                                %##*+++===------
----==========++++**%  %%%####%@ %%######%%%%                                                     #++====-----
==========+++++++**##%                 @@@                                                      @#**+=====----
=======+++++++++*####@                                                                           %*++======---
===++++++++**#@ @@@@                                                                            #*+++======---
********#####@@                                                                               %#**+++======---
                                                                                            @%#**++++=======--
********#####@@                                                                               %#**+++======---
===++++++++**#@ @@@@                                                                            #*+++======---
=======+++++++++*####@                                                                           %*++======---
==========+++++++**##%                 @@@                                                      @#**+=====----
----==========++++**%  %%%####%@ %%######%%%%                                                     #++====-----
--------------=====++*******+++++++*******###%                                                %##*+++===------
---------------------=====+++++++++++++++*****#%%@                                            %#*+++===-------
--------------------------========++++++++++****#%                                              *++===--------
------------------------------============+++++**%      @@@                          %######@ %*+===----------
:---------------------------------==============++++*******###%%@              %%##****+++++++====------------
::::----------------------------------===============++++++***#%@              %#*+++++++=======-----------:::
:::::::-----------------------------------===============++++++**#%@@       %%#*+++++=========----------::::::
,::::::::::-----------------------------------==============+++++**##%@      #*++==========---------::::::::::
,,,::::::::::::------------------------------------===========++++**#  @*****+=========---------::::::::::::::
,,,,,:::::::::::::::-------------------------------------=========+****++++======----------:::::::::::::::::::
,,,,,,,::::::::::::::::::::---------------------------------------------------------::::::::::::::::::::::::::
,,,,,,,,,,::::::::::::::::::::::::::::-----------------------------------:::::::::::::::::::::::::::::::::::::
,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


                               .''+'''''';'++++###'
                       ,';:::::::;;;;;;;;''''''''+''++''';'''#:
                 `+';';;;;;;::::::;;;;;;;'''''''''''''`:@+++'';;;;;#
             `;'''''''';;;;;:::::::;:;#':;''''';'+#''''''#  @'+++;;;;;:#
          ,'''''''''''';;;;;::;::::,::';          +@;++,'''+'   @'+;;;;;;;#
        ''''''''''''''''';;;;;;:+;:`                    @@.''''@   #'':';;;;:
      ''''''''''''''+::;;;''++++;                          @@''''@    ;':,;;'+#
     ':, `::;+'''''''''';#@@;                                 ;+'''@    ,:+#+:
    @';;.,;##+.  ;'''                                           '#+''
                 :';;#                                           @+;''@
                 ;#';;+                                            +#`.,    ```.,,,.
       :''''     `:;;;;+                                       .:;,`.........,..,.,,.
   ';;;;;;:,:     ';#;;;;                                `......`````..........,,..`@
   '`';;;;;;;'     :;@';;;'                            `.........``.````........,,, @
   ';'';;;;;;;'     +;,:;;;;:+                        ..............`.``.......... @
    .;',';;;;;;;'    `;'@;;;;;;;':                 ;...................``````..., +@
      ';:.';;;;;;;'    +;;@;;;;;;;;:;:::;'++##:..,,,,,,.................``.``.` @+@
        ;;;';;;;;;;;'    '''#;;;;;;;;;::::::::,,,,,,,,,,,...................` +''
          ';;':,';;;;;;'   #'+'#;;;;;;:::::::::,,,,,,,,,,,,............... @@;'@
             ;;;',,.';;;;;:' #'++#,,':;;;:::::::,,,,,,,,,,,,,,,.,.....`+'',;:
                ';;;;+,..,'';;;;::##'#.;'::;::::::,,,,,,,,,,,,,,..@#@.`.,,`
                    +:;;;;;'+;;;'###+';:::,,.......,,;+@@@@+#@+.`.....`
                         ,+;;''''''''''''''+++++++++++++''';;:,::
                                  `;+###+'''''++###@@#+,
     ___                   ___         ___         ___         ___         ___         ___
    /\__\        ___      /\  \       /\  \       /\  \       /\  \       /\  \       /\__\        ___
   /  |  |      /\  \    /  \  \     /  \  \     /  \  \     /  \  \     /  \  \     /  |  |      /\  \
  / | |  |      \ \  \  / /\ \  \   / /\ \  \   / /\ \  \   / /\ \  \   / /\ \  \   / | |  |      \ \  \ 
 / /| |__|__    /  \__\/ /  \ \  \ /  \~\ \  \ / /  \ \  \ _\ \~\ \  \ /  \~\ \  \ / /| |__|__    /  \__\
/ / |    \__\__/ /\/__/ /__/ \ \__/ /\ \ \ \__/ /__/ \ \__/\ \ \ \ \__/ /\ \ \ \__/ / |    \__\__/ /\/__/
\/__/~~/ /  /\/ /  /  \ \  \  \/__\/_|  \/ /  \ \  \ / /  \ \ \ \ \/__\ \~\ \ \/__\/__/~~/ /  /\/ /  /
      / /  /\  /__/    \ \  \        | |  /  / \ \  / /  / \ \ \ \__\  \ \ \ \__\       / /  /\  /__/
     / /  /  \ \__\     \ \  \       | |\/__/   \ \/ /  /   \ \/ /  /   \ \ \/__/      / /  /  \ \__\
    / /  /    \/__/      \ \__\      | |  |      \  /  /     \  /  /     \ \__\       / /  /    \/__/
    \/__/                 \/__/       \|__|       \/__/       \/__/       \/__/       \/__/
                                                                   Power Matters (tm)
         -=- IEEE 754 Single floating point mandelbrot fractal demonstration -=-
                                                  

Mi-V Soft processor

This example uses a Mi-V Soft processor MiV_RV32IMAF_L1_AHB. The design is built for debugging MiV_RV32IMAF_L1_AHB through the SmartFusion2 FPGA programming JTAG port using a FlashPro5. There is second configuration "Debug-softfloat" which doesn't require F extension and can be used on non-F cores as well. It's slower and larger because all the aritmetics are implemented in software, it will need a DDR design as the binary might be too large for SRAM.

All the platform/design specific definitions such as peripheral base addresses, system clock frequency (preconfigured for 40MHz) etc. are included in hw_platform.h. The hw_platform.h is located at the root folder of this project.

The MiV_RV32IMAF_L1_AHB firmware projects need the riscv_hal and the hal firmware (RISC-V HAL).

The RISC-V HAL is available through Firmware catalog as well as from the GitHub repository:

https://github.com/RISCV-on-Microsemi-FPGA/riscv-hal

How to use this example

This example project requires USB-UART interface to be connected to a host PC. The project is not using anything else than UART, no other internal/external peripheral is required. It's using default settings at 115200 baud rate. By default it's requiring 110x40 characters terminal window. On Windows The host PC must connect to the serial port using a terminal emulator such as HyperTerminal or PuTTY configured as follows:

  • 115200 baud
  • 8 data bits
  • 1 stop bit
  • no parity
  • no flow control

Linux users could use:

screen /dev/ttyUSB0 115200

Or any equivalent serial terminal application (e.g. minicom). For more help see:

https://wiki.archlinux.org/index.php/working_with_the_serial_console

Project has enabled the C Compiler Preprocessor defines and using the SERIAL_TERMINAL_ANIMATION to use the VT100 control escape sequences to move cursor and turn the output into pseudo "animation". If the terminal is not supporting the control escape sequences then it might display strangely rendered symbols on the first line. If this is not desired, removing the define from the project settings will disable this "animation" feature.

Project settings have predefined MSCC_STDIO_THRU_CORE_UART_APB so all regular printf calls should be redirected to UART. This allows the code be generic enough to run on x86 Linux host. A script runOnLinuxHost.sh script and Raytracer-on-Linux-host launcher are made for this purpose.

The launcher should be visible from external tools. If it's not, then it might be required to disable Filter Configuration Types filter first. If this project was cloned from the GitHub repository it might have default file permission on the script and then the launcher will fail, the permissions can be changed within the SoftConsole with a right click on the script and clicking Properties.

screenshot

The program is called withing few loops so the sphere will be "rendered" under different "zoom" levels and under different lighting conditions. All the output can be observed only through UART (not GPIO LEDs or anything else present).

Features

  • Small source codebase, single file under 200 lines of code.
  • Using 11 shades of ASCII
  • Multitarget, thanks to MSCC_STDIO_THRU_CORE_UART_APB it runs on x86/amd64 Linux and on RV32IMAF cores without any sourcecode change.

Resources

Links which might be useful:

https://rosettacode.org/wiki/Mandelbrot_set

https://en.wikipedia.org/wiki/Mandelbrot_set

http://mathworld.wolfram.com/MandelbrotSet.html

https://www.youtube.com/watch?v=gEw8xpb1aRA

https://www.youtube.com/watch?v=NGMRB4O922I

http://natureofcode.com/book/chapter-8-fractals/

Target hardware

This example project is targeted at a SmartFusion2 M2S090 Security Eval Kit design which has CoreUART enabled. The example project is built using a clock frequency of 40MHz. Trying to execute this example project on a different design will result in incorrect baud rate being used by CoreUART.

Target board photo

This example project can be used with another design using a different clock configuration. This can be achieved by overwriting the content of this example project's "hw_platform.h" file with the correct data from your Libero design.

The release mode configuration for this example project uses microsemi-riscv-ram.ld linker script. This Linker script is specific for the SmartFusion2 target. It creates the executable image for the SRAM memory area. Compared to other examples (i.e. blinky) this ld script is using 64KB instead of 32KB and using both eSRAM_0 and eSRAM_1 of the SmartFusion2.

An example design of a soft-float core for SmartFusion2 90 Security Eval Kit is available at:

https://github.com/RISCV-on-Microsemi-FPGA/M2S090-Security-Eval-Kit

Silicon revision dependencies

This example is tested on M2S090 device.

About

SoftConsole example rendering mandelbrot fractal with ASCII characters running Mi-V floating point core

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published