From 40c23a414df82d3c926d2dcc2dd097b094c60be9 Mon Sep 17 00:00:00 2001 From: Yindong Date: Fri, 20 Dec 2024 15:01:19 +0800 Subject: [PATCH] add the explanation of stateReg usage in FSM. --- source/SpinalHDL/Libraries/fsm.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/SpinalHDL/Libraries/fsm.rst b/source/SpinalHDL/Libraries/fsm.rst index 041e834dc39..96883552db2 100644 --- a/source/SpinalHDL/Libraries/fsm.rst +++ b/source/SpinalHDL/Libraries/fsm.rst @@ -347,3 +347,17 @@ Example: STATE_B.whenIsActive(goto(STATE_C)) STATE_C.whenIsActive(goto(STATE_B)) } + +Notes about using state value +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In cases that users want to retrieve the state value for purpose, where state value could be accessed by `stateReg`. +However, the `stateReg` is not initialized during elaboration of state machine, so any access of `stateReg` directly could cause error. +Use the `postBuild` method as below can solve this problem. + +.. code-block:: scala + + // After or inside the fsm's definition. + fsm.postBuild{ + io.status := fsm.stateReg.asBits //io.status is the signal user want to assigned to. + }