suikan4github / murasaki

STM32 HAL class library
MIT License
17 stars 3 forks source link

Build failure for the CORTEX-M0 #73

Closed suikan4github closed 4 years ago

suikan4github commented 4 years ago

Describe the bug The murasaki fails to buid for CORTEX-M0.

The root cause is InitCycleCount() in murasaki_defs.hpp. This function uses DWT->CCNT. But CORTEX-M0 series of STM32 processor doesn't have it. ST is suggesting to use SYSTICK alternatively.

To Reproduce Create a Nucleo F091 project with Murasaki. Then, build.

suikan4github commented 4 years ago

CM0 code must not use DWT->CCCNT but SysTick->VAL. See thedefinition of systick in the core_cm0.h

/**
  \ingroup  CMSIS_core_register
  \defgroup CMSIS_SysTick     System Tick Timer (SysTick)
  \brief    Type definitions for the System Timer Registers.
  @{
 */

/**
  \brief  Structure type to access the System Timer (SysTick).
 */
typedef struct
{
  __IOM uint32_t CTRL;                   /*!< Offset: 0x000 (R/W)  SysTick Control and Status Register */
  __IOM uint32_t LOAD;                   /*!< Offset: 0x004 (R/W)  SysTick Reload Value Register */
  __IOM uint32_t VAL;                    /*!< Offset: 0x008 (R/W)  SysTick Current Value Register */
  __IM  uint32_t CALIB;                  /*!< Offset: 0x00C (R/ )  SysTick Calibration Register */
} SysTick_Type;

I have checked its functionality. According to the test on the Nucleo F722(CM7), SYSTICK is running in the RTOS mode, while the system tick is configured as TIM14.

So, SYSTICK must be OK to use the cycle counter. Need to test with CM0 again.

suikan4github commented 4 years ago

The above investigation was wrong. The SYSTICK was occupied by FreeRTOS.

Thus, we fixed this problem by returning 0 when core is CM0 or CM0+. Note that this funciton is weakly bound. The application programmer can override these functions.