Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #1

Open
wants to merge 2 commits into
base: data-stm32-poc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Hello/Tests/SimpleBlink.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Ivory.Tower
import Ivory.HW.Module

import Ivory.BSP.STM32.Peripheral.GPIO --F4
import Ivory.BSP.STM32.ClockConfig (ClockConfig)

-- This artificial Tower program toggles LED when
-- message arrives on its channel
Expand Down Expand Up @@ -47,13 +48,13 @@ ledToggle ledPin = do
return (cIn)

-- main Tower of our application
app :: (e -> GPIOPin) -> Tower e ()
app toledpin = do
app :: (e -> GPIOPin) -> (e -> ClockConfig) -> Tower e ()
app toledpin tocc = do
ledpin <- fmap toledpin getEnv

-- creates a period that fires every 500ms
-- `per` is a ChanOutput, specifically ChanOutput ('Stored ITime)
per <- period (Milliseconds 500)
per <- period (Milliseconds 20)

-- create our ledToggle tower
togIn <- ledToggle ledpin
Expand Down
4 changes: 2 additions & 2 deletions test/Pin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
module Pin where

import Port
import Ivory.BSP.STM32.Peripheral.GPIO1.Regs
import Ivory.BSP.STM32.Peripheral.GPIO1.TH
import Ivory.BSP.STM32.Peripheral.GPIO2.Regs
import Ivory.BSP.STM32.Peripheral.GPIO2.TH

mkGPIOPins 'gpioA "pinA"
mkGPIOPins 'gpioB "pinB"
Expand Down
32 changes: 16 additions & 16 deletions test/Port.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ import Ivory.HW



import Ivory.BSP.STM32.Peripheral.GPIO1.Peripheral
import Ivory.BSP.STM32.Peripheral.GPIO2.Peripheral

import Ivory.BSP.STM32F103.MemoryMap
import Ivory.BSP.STM32F103.RCC
import Ivory.BSP.STM32L432.MemoryMap
import Ivory.BSP.STM32L432.RCC


gpioA :: GPIOPort
gpioA = mkGPIOPort gpioa_periph_base
(rccEnable rcc_apb2enr_iopaen)
(rccDisable rcc_apb2enr_iopaen)
(rccEnable rcc_ahb2enr_gpioaen)
(rccDisable rcc_ahb2enr_gpioaen)
0

gpioB :: GPIOPort
gpioB = mkGPIOPort gpiob_periph_base
(rccEnable rcc_apb2enr_iopben)
(rccDisable rcc_apb2enr_iopben)
0
(rccEnable rcc_ahb2enr_gpioben)
(rccDisable rcc_ahb2enr_gpioben)
1

gpioC :: GPIOPort
gpioC = mkGPIOPort gpioc_periph_base
(rccEnable rcc_apb2enr_iopcen)
(rccDisable rcc_apb2enr_iopcen)
0

rccEnable :: BitDataField RCC_APB2ENR Bit -> Ivory eff ()
rccEnable f = modifyReg rcc_reg_apb2enr $ setBit f
rccDisable :: BitDataField RCC_APB2ENR Bit -> Ivory eff ()
rccDisable f = modifyReg rcc_reg_apb2enr $ clearBit f
(rccEnable rcc_ahb2enr_gpiocen)
(rccDisable rcc_ahb2enr_gpiocen)
2

rccEnable :: BitDataField RCC_AHB2ENR Bit -> Ivory eff ()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apb->ahb seems suspicious

rccEnable f = modifyReg rcc_reg_ahb2enr $ setBit f
rccDisable :: BitDataField RCC_AHB2ENR Bit -> Ivory eff ()
rccDisable f = modifyReg rcc_reg_ahb2enr $ clearBit f
21 changes: 17 additions & 4 deletions test/SimpleBlinkTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@ import Hello.Tests.SimpleBlink (app)
import Port
import Pin
import Ivory.BSP.STM32.Peripheral.GPIO
import Ivory.BSP.STM32.ClockConfig

lol = go (matchMCU "STM32F103C8")
lol = go (matchMCU "STM32L432KCU6")
where
go (Just x) = \_ -> x
go Nothing = fail "Unable to match MCU!"


pin = GPIOF1 pinC13
pin = GPIOFX pinB3
cc = const $ ClockConfig { clockconfig_source = Internal
, clockconfig_pll = PLLFactor
{ pll_m = 16 -- arbitrary, not used
, pll_n = 16 * p -- arbitrary, not used
, pll_p = p
, pll_q = 7
}
, clockconfig_hclk_divider = 1
, clockconfig_pclk1_divider = 1
, clockconfig_pclk2_divider = 1
}
where p = 2

main :: IO ()
main = compileTowerSTM32FreeRTOS lol p $
app (\_ -> pin)
main = compileTowerSTM32FreeRTOS lol cc p $
app (\_ -> pin) (\_ -> error "needs ClockConfig")
where
p :: TOpts -> IO ()
p x = return ()
Expand Down