shithub: MicroHs

Download patch

ref: 45342ab2e1e74fd4805abffe68e507286ebccf43
parent: 04ebecac63e17ce1b808f60217b87a162ea24263
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Fri Jan 12 16:25:41 EST 2024

Simple STM32 project.

--- /dev/null
+++ b/STM32/Blinky.c
@@ -1,0 +1,156 @@
+const unsigned char combexprdata[] = {
+118,55,46,48,10,50,54,10,83,39,32,85,32,75,50,32,75,32,64,32,
+64,32,58,55,48,49,32,66,32,66,32,66,32,67,32,64,32,64,32,64,
+32,66,32,66,32,67,32,64,32,64,32,80,32,64,32,64,32,66,32,66,
+32,66,32,66,32,67,32,64,32,64,32,64,32,64,32,66,32,66,32,66,
+32,67,32,64,32,64,32,64,32,66,32,66,32,67,32,64,32,64,32,80,
+32,64,32,64,32,64,32,80,32,66,32,67,32,73,79,46,62,62,61,32,
+64,32,64,32,66,32,73,79,46,114,101,116,117,114,110,32,64,32,64,32,
+64,32,67,39,32,66,32,64,32,85,32,75,32,64,32,58,52,56,55,55,
+32,64,32,75,32,64,32,95,49,51,54,53,53,32,64,32,64,32,58,49,
+51,54,53,53,32,64,32,73,79,46,114,101,116,117,114,110,32,64,32,83,
+39,32,67,39,66,32,64,32,85,32,75,32,90,32,75,32,64,32,64,32,
+64,32,58,54,57,55,32,64,32,83,39,32,67,39,66,32,64,32,95,54,
+57,55,32,64,32,66,39,32,85,32,75,50,32,65,32,64,32,64,32,58,
+55,48,52,32,64,32,64,32,64,32,95,49,51,54,55,48,32,64,32,64,
+32,83,39,32,66,32,64,32,85,32,75,50,32,90,32,75,32,64,32,64,
+32,64,32,58,54,49,49,32,64,32,67,39,32,85,32,65,32,64,32,64,
+32,85,32,90,32,90,32,90,32,75,32,64,32,64,32,64,32,64,32,58,
+54,48,50,32,64,32,73,32,64,32,64,32,95,49,51,54,54,53,32,64,
+32,64,32,83,39,32,66,32,64,32,95,54,49,49,32,64,32,67,39,32,
+95,52,56,55,55,32,64,32,95,54,48,50,32,64,32,75,32,64,32,64,
+32,95,49,51,54,54,53,32,64,32,64,32,58,49,51,54,54,53,32,64,
+32,73,79,46,62,62,61,32,64,32,73,79,46,62,62,32,64,32,73,79,
+46,114,101,116,117,114,110,32,64,32,58,49,51,54,55,48,32,64,32,64,
+32,67,32,66,32,66,32,73,32,66,32,67,32,64,32,66,32,66,32,89,
+32,64,32,64,32,83,39,32,66,32,64,32,66,39,32,66,32,80,32,64,
+32,67,32,95,55,48,52,32,64,32,73,32,64,32,64,32,64,32,64,32,
+67,39,32,67,39,66,32,64,32,66,32,66,32,67,39,66,32,64,32,64,
+32,66,39,32,95,54,57,55,32,64,32,64,32,64,32,90,32,64,32,64,
+32,64,32,64,32,95,49,51,54,55,48,32,64,32,85,32,75,50,32,75,
+52,32,75,32,64,32,64,32,64,32,66,32,66,32,66,32,66,32,66,32,
+66,32,66,32,67,32,64,32,64,32,64,32,64,32,64,32,64,32,64,32,
+66,32,66,32,66,32,66,32,66,32,66,32,67,32,64,32,64,32,64,32,
+64,32,64,32,64,32,66,32,66,32,66,32,66,32,66,32,67,32,64,32,
+64,32,64,32,64,32,64,32,66,32,66,32,66,32,66,32,67,32,64,32,
+64,32,64,32,64,32,66,32,66,32,66,32,67,32,64,32,64,32,64,32,
+66,32,66,32,67,32,64,32,64,32,80,32,64,32,64,32,64,32,64,32,
+64,32,64,32,67,32,85,32,90,32,90,32,90,32,90,32,90,32,75,32,
+64,32,64,32,64,32,64,32,64,32,64,32,58,56,55,54,51,32,66,32,
+66,32,66,32,66,32,66,32,66,32,67,32,64,32,64,32,64,32,64,32,
+64,32,64,32,66,32,66,32,66,32,66,32,66,32,67,32,64,32,64,32,
+64,32,64,32,64,32,66,32,66,32,66,32,66,32,67,32,64,32,64,32,
+64,32,64,32,66,32,66,32,66,32,67,32,64,32,64,32,64,32,66,32,
+66,32,67,32,64,32,64,32,80,32,64,32,64,32,64,32,64,32,64,32,
+43,32,64,32,45,32,64,32,42,32,64,32,110,101,103,32,64,32,83,32,
+83,32,67,32,85,32,75,50,32,90,32,90,32,90,32,90,32,75,32,64,
+32,64,32,64,32,64,32,64,32,64,32,66,32,66,32,66,32,66,32,66,
+32,66,32,66,32,67,32,64,32,64,32,64,32,64,32,64,32,64,32,64,
+32,66,32,66,32,66,32,66,32,66,32,66,32,67,32,64,32,64,32,64,
+32,64,32,64,32,64,32,66,32,66,32,66,32,66,32,66,32,67,32,64,
+32,64,32,64,32,64,32,64,32,66,32,66,32,66,32,66,32,67,32,64,
+32,64,32,64,32,64,32,66,32,66,32,66,32,67,32,64,32,64,32,64,
+32,66,32,66,32,67,32,64,32,64,32,80,32,64,32,64,32,64,32,64,
+32,64,32,64,32,80,32,61,61,32,64,32,47,61,32,64,32,58,52,57,
+55,53,32,64,32,99,111,109,112,97,114,101,32,64,32,60,32,64,32,60,
+61,32,64,32,62,32,64,32,62,61,32,64,32,67,39,32,67,39,32,83,
+32,64,32,64,32,67,39,32,83,39,32,67,32,64,32,64,32,85,32,75,
+51,32,90,32,90,32,90,32,75,32,64,32,64,32,64,32,64,32,64,32,
+58,56,57,48,50,32,64,32,73,32,64,32,64,32,73,32,64,32,95,52,
+57,57,49,32,64,32,64,32,67,39,32,83,39,32,67,32,64,32,64,32,
+67,39,32,67,39,32,83,32,64,32,64,32,95,56,57,48,50,32,64,32,
+73,32,64,32,64,32,73,32,64,32,95,52,57,57,49,32,64,32,64,32,
+58,52,57,57,49,32,64,32,64,32,35,48,32,64,32,64,32,73,32,64,
+32,64,32,85,32,75,51,32,90,32,90,32,75,32,64,32,64,32,64,32,
+64,32,58,56,55,56,49,32,95,52,57,50,54,32,64,32,64,32,64,32,
+67,32,67,32,67,32,67,32,85,32,75,32,90,32,90,32,90,32,90,32,
+90,32,75,32,64,32,64,32,64,32,64,32,64,32,64,32,64,32,95,52,
+57,57,49,32,64,32,64,32,35,48,32,64,32,64,32,95,56,55,56,49,
+32,95,52,57,50,54,32,64,32,85,32,75,32,75,52,32,65,32,64,32,
+64,32,64,32,58,56,55,57,51,32,95,52,57,50,54,32,64,32,83,32,
+67,39,32,67,32,64,32,83,32,83,39,32,67,39,32,64,32,66,32,83,
+39,32,64,32,60,61,32,35,48,32,64,32,64,32,64,32,67,39,32,67,
+32,64,32,67,39,32,83,39,32,67,39,32,64,32,64,32,61,61,32,64,
+32,66,32,66,32,65,32,110,111,77,97,116,99,104,32,102,114,111,109,85,
+84,70,56,32,34,46,46,47,108,105,98,47,68,97,116,97,47,73,110,116,
+101,103,101,114,95,84,121,112,101,46,104,115,34,32,64,32,64,32,35,50,
+52,32,64,32,35,49,32,64,32,64,32,64,32,64,32,66,32,66,32,80,
+32,65,32,64,32,64,32,64,32,85,32,64,32,64,32,64,32,64,32,80,
+32,65,32,64,32,79,32,35,48,32,64,32,79,32,35,48,32,64,32,79,
+32,35,50,32,64,32,75,32,64,32,64,32,64,32,64,32,64,32,64,32,
+64,32,66,32,66,32,80,32,75,32,64,32,64,32,64,32,85,32,64,32,
+64,32,64,32,89,32,67,39,32,67,32,64,32,66,32,83,32,61,61,32,
+35,48,32,64,32,64,32,64,32,66,32,83,39,32,79,32,64,32,67,32,
+114,101,109,32,64,32,61,61,32,89,32,67,39,32,67,32,64,32,66,32,
+83,39,32,83,39,32,64,32,61,61,32,35,48,32,64,32,64,32,64,32,
+67,39,32,67,39,66,32,64,32,67,32,66,32,64,32,67,32,115,104,114,
+32,64,32,35,49,32,64,32,64,32,64,32,43,32,35,49,32,64,32,64,
+32,64,32,64,32,73,32,64,32,64,32,105,110,118,32,35,48,32,64,32,
+64,32,35,48,32,64,32,64,32,35,54,52,32,64,32,35,51,50,55,54,
+56,32,64,32,35,50,49,52,55,52,56,51,54,52,56,32,64,32,58,54,
+51,55,52,32,64,32,64,32,64,32,67,32,66,32,64,32,67,32,113,117,
+111,116,32,64,32,95,54,51,55,52,32,64,32,64,32,64,32,64,32,64,
+32,75,32,64,32,64,32,64,32,64,32,45,32,35,48,32,64,32,64,32,
+58,54,52,52,49,32,35,49,32,64,32,64,32,64,32,64,32,64,32,35,
+48,32,64,32,64,32,35,49,32,64,32,64,32,85,32,67,39,66,32,66,
+32,42,32,64,32,80,32,35,49,32,64,32,45,32,35,48,32,64,32,35,
+49,32,64,32,64,32,64,32,64,32,80,32,35,48,32,64,32,83,32,80,
+32,64,32,83,39,32,83,39,32,80,32,64,32,64,32,67,39,66,32,43,
+32,64,32,42,32,95,54,51,55,52,32,64,32,64,32,64,32,66,32,66,
+32,90,32,64,32,64,32,67,39,66,32,66,39,32,43,32,64,32,64,32,
+66,32,66,32,42,32,95,54,51,55,52,32,64,32,64,32,64,32,67,39,
+66,32,43,32,64,32,42,32,95,54,51,55,52,32,64,32,64,32,64,32,
+64,32,64,32,64,32,64,32,64,32,64,32,64,32,64,32,58,52,57,50,
+54,32,64,32,64,32,95,56,55,57,51,32,95,52,57,50,54,32,64,32,
+95,54,52,52,49,32,35,49,32,64,32,64,32,64,32,64,32,67,32,85,
+32,75,32,90,32,90,32,90,32,90,32,75,32,64,32,64,32,64,32,64,
+32,64,32,64,32,58,56,55,55,48,32,95,52,57,50,54,32,64,32,64,
+32,95,56,55,57,51,32,95,52,57,50,54,32,64,32,95,54,52,52,49,
+32,35,49,32,64,32,64,32,64,32,64,32,73,32,64,32,73,32,64,32,
+83,32,79,32,64,32,66,32,85,32,75,52,32,90,32,90,32,75,32,64,
+32,64,32,64,32,64,32,58,51,51,54,49,32,95,51,54,55,52,32,64,
+32,64,32,67,32,95,56,55,54,51,32,95,52,57,50,54,32,64,32,64,
+32,35,49,32,64,32,64,32,64,32,64,32,83,39,32,67,39,32,89,32,
+64,32,64,32,66,32,66,32,66,32,83,32,79,32,64,32,64,32,64,32,
+64,32,66,32,66,32,67,32,66,32,64,32,64,32,64,32,66,32,66,32,
+67,32,95,56,55,54,51,32,95,52,57,50,54,32,64,32,64,32,64,32,
+64,32,67,32,95,56,55,55,48,32,95,52,57,50,54,32,64,32,64,32,
+64,32,64,32,64,32,64,32,73,32,64,32,64,32,66,32,67,39,32,66,
+32,89,32,64,32,66,32,66,32,80,32,75,32,64,32,64,32,64,32,67,
+39,66,32,66,32,83,39,32,66,32,64,32,64,32,82,32,75,32,64,32,
+64,32,64,32,67,39,66,32,79,32,64,32,64,32,64,32,64,32,58,55,
+54,56,50,32,64,32,67,32,95,56,57,48,50,32,95,52,57,57,49,32,
+64,32,64,32,64,32,64,32,95,51,51,54,49,32,95,51,54,55,52,32,
+64,32,64,32,64,32,83,39,32,83,32,64,32,83,39,32,83,39,32,83,
+39,32,64,32,64,32,67,32,85,32,75,52,32,90,32,90,32,75,32,64,
+32,64,32,64,32,64,32,95,52,57,57,49,32,64,32,64,32,64,32,66,
+32,66,32,67,39,32,95,55,54,56,50,32,64,32,67,32,85,32,75,32,
+75,52,32,90,32,75,32,64,32,64,32,64,32,64,32,95,52,57,57,49,
+32,64,32,64,32,64,32,64,32,64,32,85,32,75,32,75,52,32,90,32,
+75,32,64,32,64,32,64,32,64,32,58,51,51,54,55,32,95,51,54,55,
+52,32,64,32,64,32,64,32,64,32,66,32,66,32,67,39,32,95,55,54,
+56,50,32,64,32,67,32,95,56,57,48,50,32,95,52,57,57,49,32,64,
+32,64,32,64,32,64,32,64,32,95,51,51,54,55,32,95,51,54,55,52,
+32,64,32,64,32,64,32,64,32,58,51,54,55,52,32,64,32,95,56,55,
+57,51,32,95,52,57,50,54,32,64,32,95,54,52,52,49,32,35,48,32,
+64,32,64,32,64,32,95,56,55,57,51,32,95,52,57,50,54,32,64,32,
+95,54,52,52,49,32,35,51,32,64,32,64,32,64,32,64,32,64,32,64,
+32,64,32,66,32,67,39,32,83,39,32,95,55,48,49,32,95,49,51,54,
+55,48,32,64,32,64,32,64,32,67,32,67,39,66,32,66,32,73,32,64,
+32,94,115,101,116,95,108,101,100,32,64,32,64,32,80,32,35,48,32,64,
+32,35,49,32,64,32,64,32,64,32,64,32,64,32,66,32,66,32,67,39,
+32,115,101,113,32,64,32,67,32,83,32,67,32,85,32,75,32,64,32,95,
+52,57,55,53,32,64,32,64,32,35,48,32,64,32,64,32,66,32,95,52,
+56,51,32,64,32,67,32,95,56,55,55,48,32,95,52,57,50,54,32,64,
+32,64,32,35,49,32,64,32,64,32,64,32,64,32,73,32,64,32,58,52,
+56,51,32,64,32,95,55,48,52,32,95,49,51,54,55,48,32,64,32,73,
+32,64,32,64,32,64,32,64,32,95,56,55,54,51,32,95,52,57,50,54,
+32,64,32,64,32,64,32,64,32,58,52,52,55,32,64,32,65,32,64,32,
+64,32,83,39,32,95,55,48,49,32,95,49,51,54,55,48,32,64,32,64,
+32,67,32,95,52,52,55,32,64,32,75,32,64,32,64,32,66,32,95,52,
+49,50,32,64,32,67,32,95,56,55,54,51,32,95,52,57,50,54,32,64,
+32,64,32,35,49,32,64,32,64,32,64,32,64,32,58,52,49,50,32,35,
+53,48,48,32,64,32,125,
+0 };
+const unsigned char *combexpr = combexprdata;
+const int combexprlen = 3027;
--- /dev/null
+++ b/STM32/Blinky.hs
@@ -1,0 +1,71 @@
+module Blinky(main) where
+--import Primitives
+--import Data.Bool
+import Prelude
+
+--foreign import ccall "set_led" setLed :: Int -> Int -> IO ()
+
+{-
+main :: IO ()
+main = --setLed (0::Int) (1::Int)
+  blinky (500::Int)
+
+blinky :: Int -> IO ()
+blinky n =
+  oneByOne n (1::Int) `primThen`
+  oneByOne n (0::Int) `primThen`
+  blinky (n `primIntAdd` 1)
+
+oneByOne :: Int -> Int -> IO ()
+oneByOne n on =
+  setLed (0::Int) on `primThen`
+  wait n `primThen`
+  setLed (1::Int) on `primThen`
+  wait n `primThen`
+  setLed (2::Int) on `primThen`
+  wait n `primThen`
+  setLed (3::Int) on `primThen`
+  wait n
+
+foreign import ccall "set_led" setLed :: Int -> Int -> IO ()
+
+-}
+
+main :: IO ()
+main = blinky (500::Int)
+
+blinky :: Int -> IO ()
+blinky n = do
+  oneByOne n True
+  oneByOne n False
+  blinky (n + 1)
+
+oneByOne :: Int -> Bool -> IO ()
+oneByOne n on = forM_ [0..3] $ \ led -> do
+  setLed led on
+  wait (n + led)
+{-
+ do
+  setLed (0::Int) on
+  wait n
+  setLed (1::Int) on
+  wait n
+  setLed (2::Int) on
+  wait n
+  setLed (3::Int) on
+  wait n
+-}
+
+foreign import ccall "set_led" set_led :: Int -> Int -> IO ()
+
+setLed :: Int -> Bool -> IO ()
+setLed led on = set_led led $ if on then 1 else 0
+  --print ("setLed",led,on)
+
+wait :: Int -> IO ()
+wait n = do
+  --print ("wait", n)
+  seq (loop n) (return ())
+
+loop :: Int -> ()
+loop n = if n == 0 then () else loop (n - 1)
--- /dev/null
+++ b/STM32/Makefile
@@ -1,0 +1,27 @@
+MHSDIR=..
+BIN=../bin
+TOOLS=../Tools
+
+# Generate combinator file
+blinky.c:	Blinky.hs $(BIN)/Addcombs $(BIN)/mhseval $(BIN)/mhs
+	MHSDIR=$(MHSDIR) $(BIN)/mhs -i$(LIB) Blinky -oBlinky.comb
+	$(BIN)/mhseval +RTS -rBlinky.comb -oBlinky-opt.comb
+	$(BIN)/Addcombs Blinky-opt.comb Blinky.c
+
+$(BIN)/Addcombs:	$(TOOLS)/Addcombs.hs $(BIN)/mhs
+	MHSDIR=$(MHSDIR) $(BIN)/mhs -i$(TOOLS) Addcombs -o$(BIN)/Addcombs
+
+# To compile for STM32 the following files are needed:
+#  src/runtime/bfile.c
+#  src/runtime/config-stm32f4.h
+#  src/runtime/eval-stm32f.c
+#  src/runtime/eval.c
+#  blinky.c
+# The Keil project should include
+#  eval-stm32f.c
+#  blinky.c
+# To get enough memory I modified startup_stm32f407xx.s
+#   Stack_Size      EQU     0x00008000
+#   Heap_Size       EQU     0x0000E000
+# These values are not optimized, they just happen to work
+# for this project.
--