-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | STLink USB interface in Haskell -- -- This package contains a Haskell driver for ST-Link USB dongles. My use -- case for this driver is the STM32-Zombie library. The STM32-Zombie -- library turns a STM32 micro-controller into a powerful -- Haskell-hackable hardware interface. The library is a based on -- information from the openocd library. @package STLinkUSB @version 0.1.1 -- | This module contains low-level functions for initializing the USB -- connection. In most setups runSTLink does all the work and -- there is no need to include this module. module STM32.STLinkUSB.USBUtils findDefaultEndpoints :: IO (Ctx, Device, EndpointAddress, EndpointAddress, EndpointAddress) findUSBDevices :: Ctx -> ProductId -> IO [Device] defaultSTLProductID :: ProductId findEndpoints :: Ctx -> Device -> IO (Ctx, Device, EndpointAddress, EndpointAddress, EndpointAddress) withUSB :: Device -> (DeviceHandle -> IO a) -> IO a usbReadTimeout :: Int usbWriteTimeout :: Int -- | The bits, bytes and constants of the STLink protocoll. The constants -- have been looked up a corresponding driver that is part of the openocd -- library. Some parts have been added for completeness (but have not -- been tested so far). module STM32.STLinkUSB.Commands data Version Version :: Word16 -> Word16 -> Word16 -> Version [stlink] :: Version -> Word16 [jtag] :: Version -> Word16 [swim] :: Version -> Word16 -- | APIV1 is NOT supported ! Todo remove old APIV1 stuff. | todo data API APIV1 :: API APIV2 :: API type Addr = Word32 data DebugCmd ENTER_JTAG :: DebugCmd GETSTATUS :: DebugCmd FORCEDEBUG :: DebugCmd READMEM_32BIT :: Addr -> Word16 -> DebugCmd WRITEMEM_32BIT :: Addr -> Word16 -> DebugCmd RUNCORE :: DebugCmd STEPCORE :: DebugCmd READMEM_8BIT :: Addr -> Word16 -> DebugCmd WRITEMEM_8BIT :: Addr -> Word16 -> DebugCmd APIV1_CLEARFP :: DebugCmd APIV1_SETWATCHPOINT :: DebugCmd ENTER_SWD :: DebugCmd EXIT :: DebugCmd READCOREID :: DebugCmd APIV1_SETFP :: DebugCmd ENTER :: API -> DebugCmd APIV2_READ_IDCODES :: DebugCmd RESETSYS :: API -> DebugCmd READREG :: API -> DebugCmd WRITEREG :: API -> DebugCmd WRITEDEBUGREG :: API -> Addr -> Word32 -> DebugCmd APIV2_READDEBUGREG :: Addr -> DebugCmd READALLREGS :: API -> DebugCmd GETLASTRWSTATUS :: DebugCmd APIV2_DRIVE_NRST :: DebugCmd APIV2_START_TRACE_RX :: Word16 -> Word32 -> DebugCmd APIV2_STOP_TRACE_RX :: DebugCmd APIV2_GET_TRACE_NB :: DebugCmd APIV2_SWD_SET_FREQ :: DebugCmd APIV2_DRIVE_NRST_LOW :: DebugCmd APIV2_DRIVE_NRST_HIGH :: DebugCmd APIV2_DRIVE_NRST_PULSE :: DebugCmd data Cmd GET_VERSION :: Cmd DEBUG_COMMAND :: DebugCmd -> Cmd DEBUG_COMMANDs :: [DebugCmd] -> Cmd DFU_COMMAND_EXIT :: Cmd SWIM_COMMAND :: SWIM_Cmd -> Cmd GET_CURRENT_MODE :: Cmd GET_TARGET_VOLTAGE :: Cmd data SWIM_Cmd SWIM_ENTER :: SWIM_Cmd SWIM_EXIT :: SWIM_Cmd cmdToByteString :: Cmd -> ByteString data DevMode DEV_DFU_MODE :: DevMode DEV_MASS_MODE :: DevMode DEV_DEBUG_MODE :: DevMode DEV_SWIM_MODE :: DevMode DEV_BOOTLOADER_MODE :: DevMode data Status DEBUG_ERR_OK :: Status DEBUG_ERR_FAULT :: Status SWD_AP_WAIT :: Status SWD_AP_FAULT :: Status SWD_AP_ERROR :: Status SWD_AP_PARITY_ERROR :: Status JTAG_WRITE_ERROR :: Status JTAG_WRITE_VERIF_ERROR :: Status SWD_DP_WAIT :: Status SWD_DP_FAULT :: Status SWD_DP_ERROR :: Status SWD_DP_PARITY_ERROR :: Status SWD_AP_WDATA_ERROR :: Status SWD_AP_STICKY_ERROR :: Status SWD_AP_STICKYORUN_ERROR :: Status UnknownStatus :: Word8 -> Status toStatus :: Word8 -> Status instance GHC.Classes.Ord STM32.STLinkUSB.Commands.Status instance GHC.Classes.Eq STM32.STLinkUSB.Commands.Status instance GHC.Show.Show STM32.STLinkUSB.Commands.Status instance GHC.Enum.Enum STM32.STLinkUSB.Commands.DevMode instance GHC.Classes.Ord STM32.STLinkUSB.Commands.DevMode instance GHC.Classes.Eq STM32.STLinkUSB.Commands.DevMode instance GHC.Show.Show STM32.STLinkUSB.Commands.DevMode instance GHC.Show.Show STM32.STLinkUSB.Commands.Cmd instance GHC.Show.Show STM32.STLinkUSB.Commands.SWIM_Cmd instance GHC.Classes.Eq STM32.STLinkUSB.Commands.DebugCmd instance GHC.Show.Show STM32.STLinkUSB.Commands.DebugCmd instance GHC.Classes.Eq STM32.STLinkUSB.Commands.API instance GHC.Show.Show STM32.STLinkUSB.Commands.API instance GHC.Show.Show STM32.STLinkUSB.Commands.Version instance Data.Binary.Class.Binary STM32.STLinkUSB.Commands.Version instance Data.Binary.Class.Binary STM32.STLinkUSB.Commands.DebugCmd instance Data.Binary.Class.Binary STM32.STLinkUSB.Commands.Cmd -- | The STLT Monad is just a reader transformer of STLinkEnv. module STM32.STLinkUSB.Env type STLT m a = ReaderT STLinkEnv m a type STL a = forall m. MonadIO m => ReaderT STLinkEnv m a runSTLink :: STLT IO a -> IO a runSTLink_verbose :: STLT IO a -> IO a runSTLink' :: Logger -> (STLinkEnv -> IO a) -> IO a runSTLinkWith :: Logger -> (Ctx, Device, EndpointAddress, EndpointAddress, EndpointAddress) -> (STLinkEnv -> IO a) -> IO a data STLinkEnv STLinkEnv :: Ctx -> EndpointAddress -> EndpointAddress -> EndpointAddress -> DeviceHandle -> API -> Logger -> STLinkEnv [usbCtx] :: STLinkEnv -> Ctx [rxEndpoint] :: STLinkEnv -> EndpointAddress [txEndpoint] :: STLinkEnv -> EndpointAddress [traceEndpoint] :: STLinkEnv -> EndpointAddress [deviceHandle] :: STLinkEnv -> DeviceHandle [dongleAPI] :: STLinkEnv -> API [debugLogger] :: STLinkEnv -> Logger asksDongleAPI :: STL API data LogLevel Debug :: LogLevel Info :: LogLevel Warn :: LogLevel Error :: LogLevel type Logger = LogLevel -> String -> IO () debugSTL :: LogLevel -> String -> STL () defaultDebugLogger :: Logger verboseDebugLogger :: Logger instance GHC.Classes.Ord STM32.STLinkUSB.Env.LogLevel instance GHC.Classes.Eq STM32.STLinkUSB.Env.LogLevel instance GHC.Show.Show STM32.STLinkUSB.Env.LogLevel -- | This module contains low-level functions for USB data transfers. Don't -- use theses functions directly, the prefered API is the MemRW module. module STM32.STLinkUSB.USBXfer data XferStatus XferOK :: XferStatus XferRetry :: XferStatus XferDongleError :: XferStatus XferUSBError :: (Either USBException Status) -> XferStatus writeBulkSTL :: Cmd -> STL (Size, Status) readBulkSTL :: STL (ByteString, Either USBException Status) xferStatus :: Cmd -> STL (ByteString, Either USBException Status) xferBulkWrite :: Cmd -> ByteString -> STL () xfer :: Cmd -> STL ByteString xferRetry :: Cmd -> STL ByteString xferReadTrace :: STL (ByteString, Either USBException Status) instance GHC.Classes.Eq STM32.STLinkUSB.USBXfer.XferStatus instance GHC.Show.Show STM32.STLinkUSB.USBXfer.XferStatus -- | Functions for initializing, reseting and mode-change of the STLink -- dongle. module STM32.STLinkUSB.Dongle -- | Init the dongle and set debug mode. A Haskell translation of the same -- function in the openocd library. initDongle :: STL () reset :: STL () readVersion :: STL Version readVoltage :: STL Float readCurrentMode :: STL DevMode data Mode MODE_DFU :: Mode MODE_MASS :: Mode MODE_DEBUG_JTAG :: Mode MODE_DEBUG_SWD :: Mode MODE_DEBUG_SWIM :: Mode modeEnter :: Mode -> STL () modeLeave :: Mode -> STL () writeDebugReg :: Word32 -> Word32 -> STL () dumpTrace :: STL () instance GHC.Enum.Enum STM32.STLinkUSB.Dongle.Mode instance GHC.Classes.Ord STM32.STLinkUSB.Dongle.Mode instance GHC.Classes.Eq STM32.STLinkUSB.Dongle.Mode instance GHC.Show.Show STM32.STLinkUSB.Dongle.Mode -- | Read and Write to the memory of an attached STM32 controller. module STM32.STLinkUSB.MemRW checkRWStatus :: STL () maxTransferBlocksize :: Word16 newtype TransferBlock TransferBlock :: ByteString -> TransferBlock [_unTransferBlock] :: TransferBlock -> ByteString unsafeToTransferBlock :: ByteString -> TransferBlock newtype TransferLen TransferLen :: Word16 -> TransferLen [_unTransferLen] :: TransferLen -> Word16 unsafeToTransferLen :: Word16 -> TransferLen writeMem8' :: Addr -> TransferBlock -> STL () writeMem32' :: Addr -> TransferBlock -> STL () readMem8' :: Addr -> TransferLen -> STL ByteString readMem32' :: Addr -> TransferLen -> STL ByteString writeMem8 :: Addr -> ByteString -> STL () writeMem32 :: Addr -> ByteString -> STL () writeChunks :: (Addr -> TransferBlock -> STL ()) -> Addr -> ByteString -> STL () chunkBS :: Addr -> ByteString -> [(Addr, TransferBlock)] chunkAddr :: Addr -> Int -> [(Addr, TransferLen)] readChunks :: (Addr -> TransferLen -> STL ByteString) -> Addr -> Int -> STL ByteString readMem8 :: Addr -> Int -> STL ByteString readMem32 :: Addr -> Int -> STL ByteString instance GHC.Show.Show STM32.STLinkUSB.MemRW.TransferLen instance GHC.Show.Show STM32.STLinkUSB.MemRW.TransferBlock -- | Starting and stopping the attached CPU module STM32.STLinkUSB.CortexM halt :: STL () resetHalt :: STL () run :: STL () readCpuID :: STL ByteString _CPUID :: Word32 _DCB_DHCSR :: Word32 _DCB_DCRSR :: Word32 _DCB_DCRDR :: Word32 _DCB_DEMCR :: Word32 _DBGKEY :: Word32 _C_DEBUGEN :: Word32 _C_HALT :: Word32 -- | Test the connetion to the STLink dongle and read the CPU ID of the -- attached controller. module STM32.STLinkUSB.Test -- | Test the dongle and connection to the board. This test fails if no -- board is attached test :: IO () -- | Using two Boards/Dongles in parallel. module STM32.STLinkUSB.TwoBoards type STLTT m a = ReaderT (STLinkEnv, STLinkEnv) m a runSTLinkAB :: STLTT IO a -> IO a runSTLinkAB_verbose :: STLTT IO a -> IO a runSTLinkAB' :: (Logger, Logger) -> ((STLinkEnv, STLinkEnv) -> IO a) -> IO a runSTLinkWithAB :: (Device, Device) -> (DeviceHandle -> STLinkEnv, DeviceHandle -> STLinkEnv) -> ((STLinkEnv, STLinkEnv) -> IO a) -> IO a taggedLogger :: String -> Logger -> Logger boardA :: STLT IO a -> STLTT IO a boardB :: STLT IO a -> STLTT IO a testTwoBoards :: IO () -- | This module exports a small driver for the STLink dongles. The focus -- of this API is on reading and writing to the memory of and attached -- STM32 controller. The STM32 architecture use memory mapped IO -- registers to program IO ports a hardware peripherals. Therefor a -- STLink dongle with an attached STM32 board in combination with this -- library makes a nice Haskell-controlled IO extension board. module STM32.STLinkUSB -- | Test the dongle and connection to the board. This test fails if no -- board is attached test :: IO () type STLT m a = ReaderT STLinkEnv m a type STL a = forall m. MonadIO m => ReaderT STLinkEnv m a data STLinkEnv runSTLink :: STLT IO a -> IO a -- | Init the dongle and set debug mode. A Haskell translation of the same -- function in the openocd library. initDongle :: STL () resetHalt :: STL () writeDebugReg :: Word32 -> Word32 -> STL () writeMem8 :: Addr -> ByteString -> STL () writeMem32 :: Addr -> ByteString -> STL () readMem8 :: Addr -> Int -> STL ByteString readMem32 :: Addr -> Int -> STL ByteString data LogLevel type Logger = LogLevel -> String -> IO () xfer :: Cmd -> STL ByteString