Skip to content

Commit

Permalink
v1.0: changed FctERR enum and added some functions for PWM handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SMFSW committed Jul 25, 2017
1 parent 64ae1da commit 91702f6
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "HARMcksL: ARM HAL toolbox (yet STM32 oriented)"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.7
PROJECT_NUMBER = 1.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
1 change: 0 additions & 1 deletion FctERR.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file FctERR.c
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief errors to SMFSW FctERR code
Expand Down
76 changes: 40 additions & 36 deletions FctERR.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file FctERR.h
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief errors to SMFSW FctERR declarations
Expand All @@ -19,42 +18,47 @@
// *****************************************************************************
/*!\enum FctERR
** \brief Enum of low/mid level functions return state
** \note TODO: Fix !defined lines when __mx_lwip_H set (should not cause any harm, but ugly and set to cause issues sometime, somehow)
**/
typedef enum PACK__ FctERR{
ERR_OK = 0U, //!< OK
ERR_SPEED = 1U, //!< This device does not work in the active speed mode.
ERR_RANGE = 2U, //!< Parameter out of range.
ERR_VALUE = 3U, //!< Parameter of incorrect value.
ERR_OVERFLOW = 4U, //!< Overflow.
ERR_MATH = 5U, //!< Overflow during evaluation.
ERR_ENABLED = 6U, //!< Device is enabled.
ERR_DISABLED = 7U, //!< Device is disabled.
ERR_BUSY = 8U, //!< Device is busy.
ERR_NOTAVAIL = 9U, //!< Requested value or method not available.
ERR_RXEMPTY = 10U, //!< No data in receiver.
ERR_TXFULL = 11U, //!< Transmitter is full.
ERR_BUSOFF = 12U, //!< Bus not available.
ERR_OVERRUN = 13U, //!< Overrun error is detected.
ERR_FRAMING = 14U, //!< Framing error is detected.
ERR_PARITY = 15U, //!< Parity error is detected.
ERR_NOISE = 16U, //!< Noise error is detected.
ERR_IDLE = 17U, //!< Idle error is detected.
ERR_FAULT = 18U, //!< Fault error is detected.
ERR_BREAK = 19U, //!< Break char is received during communication.
ERR_CRC = 20U, //!< CRC error is detected.
ERR_ARBITR = 21U, //!< A node lost arbitration. This error occurs if two nodes start transmission at the same time.
ERR_PROTECT = 22U, //!< Protection error is detected.
ERR_UNDERFLOW = 23U, //!< Underflow error is detected.
ERR_UNDERRUN = 24U, //!< Underrun error is detected.
ERR_COMMON = 25U, //!< Common error of a device.
ERR_LINSYNC = 26U, //!< LIN synchronization error is detected.
ERR_FAILED = 27U, //!< Requested functionality or process failed.
ERR_QFULL = 28U, //!< Queue is full.
ERR_CMD = 29U, //!< Command error is detected
ERR_TIMEOUT = 30U, //!< Abort on timeout error
ERR_NOTIMPLEM = 31U, //!< Function not implemented error
ERR_MEMORY = 32U, //!< Memory error
ERR_INSTANCE = 33U //!< Instance error
typedef enum FctERR{
#if !defined(__mx_lwip_H) // TODO: find a fix to remove this pre-processor ugliness
ERR_OK = 0, //!< OK
#endif
ERR_SPEED = -1, //!< This device does not work in the active speed mode.
ERR_RANGE = -2, //!< Parameter out of range.
#if !defined(__mx_lwip_H) // TODO: find a fix to remove this pre-processor ugliness
ERR_TIMEOUT = -3, //!< Abort on timeout error
#endif
ERR_VALUE = -4, //!< Parameter of incorrect value.
ERR_OVERFLOW = -5, //!< Overflow.
ERR_MATH = -6, //!< Overflow during evaluation.
ERR_ENABLED = -7, //!< Device is enabled.
ERR_DISABLED = -8, //!< Device is disabled.
ERR_BUSY = -9, //!< Device is busy.
ERR_NOTAVAIL = -10, //!< Requested value or method not available.
ERR_RXEMPTY = -11, //!< No data in receiver.
ERR_TXFULL = -12, //!< Transmitter is full.
ERR_BUSOFF = -13, //!< Bus not available.
ERR_OVERRUN = -14, //!< Overrun error is detected.
ERR_FRAMING = -15, //!< Framing error is detected.
ERR_PARITY = -16, //!< Parity error is detected.
ERR_NOISE = -17, //!< Noise error is detected.
ERR_IDLE = -18, //!< Idle error is detected.
ERR_FAULT = -19, //!< Fault error is detected.
ERR_BREAK = -20, //!< Break char is received during communication.
ERR_CRC = -21, //!< CRC error is detected.
ERR_ARBITR = -22, //!< A node lost arbitration. This error occurs if two nodes start transmission at the same time.
ERR_PROTECT = -23, //!< Protection error is detected.
ERR_UNDERFLOW = -24, //!< Underflow error is detected.
ERR_UNDERRUN = -25, //!< Underrun error is detected.
ERR_COMMON = -26, //!< Common error of a device.
ERR_LINSYNC = -27, //!< LIN synchronization error is detected.
ERR_FAILED = -28, //!< Requested functionality or process failed.
ERR_QFULL = -29, //!< Queue is full.
ERR_CMD = -30, //!< Command error is detected
ERR_NOTIMPLEM = -31, //!< Function not implemented error
ERR_MEMORY = -32, //!< Memory error
ERR_INSTANCE = -33 //!< Instance error
} FctERR;


Expand Down
1 change: 0 additions & 1 deletion GPIO_ex.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file GPIO_ex.c
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Simple extension for GPIOs
Expand Down
1 change: 0 additions & 1 deletion GPIO_ex.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file GPIO_ex.h
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Simple extension for GPIOs
Expand Down
Binary file renamed HARMcksL_v0_7.pdf → HARMcksL_v1_0.pdf
Binary file not shown.
41 changes: 36 additions & 5 deletions PWM.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file PWM.c
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Straightforward PWM handling
Expand All @@ -12,7 +11,36 @@
/****************************************************************/


HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq)
HAL_StatusTypeDef init_PWM_Chan(TIM_HandleTypeDef * pTim, uint32_t chan, uint16_t freq)
{
HAL_StatusTypeDef err;

/* Check the parameters */
assert_param(IS_TIM_INSTANCE(pTim->Instance));
assert_param(IS_TIM_CHANNELS(chan));

err = set_TIM_Freq(pTim, freq);
if (err) { return err; }

if (chan == TIM_CHANNEL_ALL)
{
#if defined(TIM_CHANNEL_6)
uint32_t chans[6] = { TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4, TIM_CHANNEL_5, TIM_CHANNEL_6 };
#else
uint32_t chans[4] = { TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4 };
#endif

for (int i = 0 ; i < sizeof(chans) / sizeof(uint32_t); i++)
{
err = set_PWM_Output(pTim, i, true);
if (err) { break; }
}
return err;
}
else return set_PWM_Output(pTim, chan, true);
}

HAL_StatusTypeDef set_TIM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq)
{
const uint32_t coreCLK = HAL_RCC_GetHCLKFreq();
uint32_t per, i;
Expand Down Expand Up @@ -58,11 +86,14 @@ __STATIC_INLINE HAL_StatusTypeDef INLINE__ write_CCR(TIM_HandleTypeDef * pTim, u
assert_param(IS_TIM_INSTANCE(pTim->Instance));
assert_param(IS_TIM_CCX_INSTANCE(pTim->Instance, chan));

if (chan <= TIM_CHANNEL_4) { pCCR = &pTim->Instance->CCR1 + (chan / 4); }
else if (chan <= TIM_CHANNEL_6) { pCCR = &pTim->Instance->CCR5 + (chan / 4) - 4; }
else { return HAL_ERROR; }
if (chan <= TIM_CHANNEL_4) { pCCR = &pTim->Instance->CCR1 + (chan / 4); }
#if defined(STM32F3)
else if (chan <= TIM_CHANNEL_6) { pCCR = &pTim->Instance->CCR5 + (chan / 4) - 4; }
#endif
else { return HAL_ERROR; }

*pCCR = CCR_val;

return HAL_OK;
}

Expand Down
22 changes: 19 additions & 3 deletions PWM.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file PWM.h
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Straightforward PWM handling
Expand All @@ -21,13 +20,30 @@
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/*!\brief Set TIM module PWM frequency for channel
/*!\brief Init TIM PWM module channel with frequency and starts the channel
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
** \param[in] freq - Desired PWM frequency
**/
HAL_StatusTypeDef init_PWM_Chan(TIM_HandleTypeDef * pTim, uint32_t chan, uint16_t freq);


/*!\brief Set TIM module frequency
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] freq - Desired PWM frequency
**/
HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq);
HAL_StatusTypeDef set_TIM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq);


/*!\brief Set PWM channel output on/off
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
** \param[in] on - Channel Output state 0: off, 1: on
** \return HAL Status
**/
__INLINE HAL_StatusTypeDef INLINE__ set_PWM_Output(TIM_HandleTypeDef * pTim, uint32_t chan, bool on) {
return on ? HAL_TIM_PWM_Start(pTim, chan) : HAL_TIM_PWM_Stop(pTim, chan); }

/*!\brief Set TIM module PWM duty cycle (scaled)
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ Doxygen generated documentation can be found in "HARMcksL_vXXX.pdf"


## Release Notes
Detailed changes will come after v1.0 release

- v0.6: current
- Still in beta for some time
See [release notes](https://github.com/SMFSW/HARMcksL/ReleaseNotes.md)


## License

The MIT License (MIT)

Copyright (c) 2017 SMFSW (Sebastien Bizien)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions Release Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# HARMcksL (release notes)

The MIT License (MIT)

Copyright (c) 2017 SMFSW (Sebastien Bizien)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


## v1.0

* PWM: Added function init_PWM_Chan (calls setFreq & starts PWM channel output)
* PWM: Added inline to Start/Stop PWM channel output
* PWM: added precomp define (from sarmfsw) to define channel 5 & 6 only for F3 (may be needed on some other families)
* FctERR: enum is now signed and precomp defined(lwip) in enum discards duplicates with lwip (while keeping common values)

## v0.7 and below

* initial commit and beta versions
1 change: 0 additions & 1 deletion exceptions.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file exceptions.c
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Debug tool helpers functions
Expand Down
1 change: 0 additions & 1 deletion exceptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file exceptions.h
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Debug tool and helpers declaration
Expand Down
1 change: 0 additions & 1 deletion stdream_rdir.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file stdream_rdir.c
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Stream redirection
Expand Down
1 change: 0 additions & 1 deletion stdream_rdir.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*!\file stdream_rdir.h
** \author SMFSW
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Stream redirection header
Expand Down

0 comments on commit 91702f6

Please sign in to comment.