Re: Enable traces on Serial Wire Output #debugging


David K
 

Hi there,

Thanks for the feedback and sorry for the delay. Here is my function that initializes the clock, it is called right after HAL_Init():

    // Configure the main internal regulator output voltage
    __IO uint32_t tmpreg;
    SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);

    // Delay after an RCC peripheral clock enabling
    tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);
    tmpreg = tmpreg;

    MODIFY_REG(PWR->CR1, PWR_CR1_VOS, (PWR_REGULATOR_VOLTAGE_SCALE3));

    // Delay after an RCC peripheral clock enabling
    tmpreg = READ_BIT(PWR->CR1, PWR_CR1_VOS);
    tmpreg = tmpreg;

    // Initializes the CPU, AHB and APB busses clocks
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_OscInitStruct.OscillatorType      = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState            = RCC_HSE_ON;
    RCC_OscInitStruct.HSIState            = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = 16;
    RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM            = 8;
    RCC_OscInitStruct.PLL.PLLN            = 144;
    RCC_OscInitStruct.PLL.PLLP            = RCC_PLLP_DIV2;
    RCC_OscInitStruct.PLL.PLLQ            = 6;
    HAL_StatusTypeDef hal_ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
    if (hal_ret != HAL_OK)
    {
        return -ENOTSUP;
    }

    // Initializes the CPU, AHB and APB busses clocks
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    RCC_ClkInitStruct.ClockType      = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource   = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider  = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
    // HAL_RCC_ClockConfig() ultimately calls HAL_InitTick()
    hal_ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
    if (hal_ret != HAL_OK)
    {
        return -ENOTSUP;
    }

    // Initializes the peripherals clocks
    RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_CLK48;
    PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_HSI;
    PeriphClkInitStruct.Clk48ClockSelection  = RCC_CLK48SOURCE_PLL;
    PeriphClkInitStruct.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_CLK48;
    hal_ret = HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
    if (hal_ret != HAL_OK)
    {
        return -ENOTSUP;
    }

    // Configure the Systick IRQ for FreeRTOS timebase
    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
    // Configure the Systick
    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

    // SysTick_IRQn interrupt configuration done in HAL_MspInit()

    SCB_EnableICache();
    SCB_EnableDCache();

    return 0;

Also, not sure if it is related but I have 2 Time bases:

  • STM32 uses timers (TIM6) to generate interruptions for HAL
  • FreeRTOS uses SysTick for OS functions

Thanks for your help, in parallel I will look into RTT alternative.

Join users@lists.zephyrproject.org to automatically receive all group messages.