Skip to content

Commit

Permalink
Add, fix, and improve some stuff
Browse files Browse the repository at this point in the history
- Enable all BSP code generation options in CubeMX
- Configure FreeRTOS runtime stats in CubeMX
- Fix and improve fix_MX_codegen.py
- Add commented CubeCLT toolchain path in c_cpp_properties.json
- Add RTOS Views to recommended extensions
- Fix and improve README.md
  • Loading branch information
KhalilOuali committed Feb 23, 2024
1 parent cac037d commit 7e05e4c
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 94 deletions.
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"cStandard": "c17",
"cppStandard": "c++17",
"compilerPath": "C:\\Program Files (x86)\\Arm GNU Toolchain arm-none-eabi\\13.2 Rel1\\bin\\arm-none-eabi-gcc.exe"
// "compilerPath": "C:\\ST\\STM32CubeCLT\\GNU-tools-for-STM32\\bin\\arm-none-eabi-gcc.exe"
}
],
"version": 4
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"ms-vscode.vscode-serial-monitor",
"ms-vscode.vscode-embedded-tools",
"github.vscode-github-actions",
"mcu-debug.rtos-views",
]
}
13 changes: 13 additions & 0 deletions Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#if defined(__ICCARM__) || defined(__ARMCC_VERSION) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
/* USER CODE BEGIN 0 */
extern void configureTimerForRunTimeStats(void);
extern unsigned long getRunTimeCounterValue(void);
/* USER CODE END 0 */
#endif
#ifndef CMSIS_device_header
#define CMSIS_device_header "stm32c0xx.h"
Expand All @@ -71,14 +75,17 @@ extern uint32_t SystemCoreClock;
#define configTOTAL_HEAP_SIZE ((size_t)4096)
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
#define configMAX_TASK_NAME_LEN ( 16 )
#define configGENERATE_RUN_TIME_STATS 1
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TASK_NOTIFICATIONS 1
#define configRECORD_STACK_HIGH_ADDRESS 1
#define configHEAP_CLEAR_MEMORY_ON_FREE 0
#define configUSE_MINI_LIST_ITEM 1
#define configUSE_SB_COMPLETED_CALLBACK 0
Expand Down Expand Up @@ -140,6 +147,12 @@ standard names. */

#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0

/* USER CODE BEGIN 2 */
/* Definitions needed when configGENERATE_RUN_TIME_STATS is on */
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS configureTimerForRunTimeStats
#define portGET_RUN_TIME_COUNTER_VALUE getRunTimeCounterValue
/* USER CODE END 2 */

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/stm32c0xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void EXTI4_15_IRQHandler(void);
void TIM1_BRK_UP_TRG_COM_IRQHandler(void);
/* USER CODE BEGIN EFP */

Expand Down
17 changes: 17 additions & 0 deletions Core/Src/app_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ void StartDefaultTask(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/* Hook prototypes */
void configureTimerForRunTimeStats(void);
unsigned long getRunTimeCounterValue(void);

/* USER CODE BEGIN 1 */
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
__weak void configureTimerForRunTimeStats(void)
{

}

__weak unsigned long getRunTimeCounterValue(void)
{
return 0;
}
/* USER CODE END 1 */

/**
* @brief FreeRTOS initialization
* @param None
Expand Down
25 changes: 25 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ int main(void)
/* Initialize leds */
BSP_LED_Init(LED_GREEN);

/* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

/* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */
BspCOMInit.BaudRate = 115200;
BspCOMInit.WordLength = COM_WORDLENGTH_8B;
Expand Down Expand Up @@ -183,6 +186,24 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

/*Configure GPIO pins : PA2 PA3 */
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/*Configure GPIO pin : PA5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/*Configure GPIO pins : PB8 PB9 */
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
Expand All @@ -191,6 +212,10 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Alternate = GPIO_AF6_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
Expand Down
14 changes: 14 additions & 0 deletions Core/Src/stm32c0xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ void HardFault_Handler(void)
/* please refer to the startup file (startup_stm32c0xx.s). */
/******************************************************************************/

/**
* @brief This function handles EXTI line 4 to 15 interrupts.
*/
void EXTI4_15_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_15_IRQn 0 */

/* USER CODE END EXTI4_15_IRQn 0 */
HAL_EXTI_IRQHandler(&H_EXTI_13);
/* USER CODE BEGIN EXTI4_15_IRQn 1 */

/* USER CODE END EXTI4_15_IRQn 1 */
}

/**
* @brief This function handles TIM1 break, update, trigger and commutation interrupts.
*/
Expand Down
13 changes: 6 additions & 7 deletions Drivers/BSP/STM32C0xx_Nucleo/stm32c0xx_nucleo.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init)
}
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0) */

if (MX_USART2_Init(&hcom_uart[COM], COM_Init) != HAL_OK) // fix_MX_codegen.py
if (MX_USART2_Init(&hcom_uart[COM], COM_Init) != HAL_OK) // fix_MX_codegen.py
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ int32_t BSP_COM_DeInit(COM_TypeDef COM)
* configuration information for the specified USART peripheral.
* @retval HAL error code
*/
__weak HAL_StatusTypeDef MX_USART2_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init) // fix_MX_codegen.py
__weak HAL_StatusTypeDef MX_USART2_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init) // fix_MX_codegen.py
{
/* USART configuration */
huart->Instance = COM_USART[COM1];
Expand Down Expand Up @@ -674,16 +674,15 @@ static void COM1_MspDeInit(UART_HandleTypeDef *huart)
* @}
*/


// fix_MX_codegen.py

#ifdef __GNUC__
/**
* @brief Redirect printf output to COM
*/
* @brief Redirect printf output to COM
*/
int _write(int file, char *ptr, int len)
{
HAL_UART_Transmit(&hcom_uart, (uint8_t *) ptr, len, HAL_MAX_DELAY);
return len;
HAL_UART_Transmit(&hcom_uart [COM_ActiveLogPort], (uint8_t *) ptr, len, HAL_MAX_DELAY);
return len;
}
#endif /* __GNUC__ */
34 changes: 17 additions & 17 deletions Drivers/BSP/STM32C0xx_Nucleo/stm32c0xx_nucleo.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,22 @@ typedef struct
* @brief Definition for COM port1, connected to UART1
*/
#if (USE_BSP_COM_FEATURE > 0)
#define COM1_UART USART2 // fix_MX_codegen.py
#define COM1_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE() // fix_MX_codegen.py
#define COM1_CLK_DISABLE() __HAL_RCC_USART2_CLK_DISABLE() // fix_MX_codegen.py

#define COM1_TX_PIN GPIO_PIN_2 // fix_MX_codegen.py
#define COM1_TX_GPIO_PORT GPIOA // fix_MX_codegen.py
#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() // fix_MX_codegen.py
#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() // fix_MX_codegen.py
#define COM1_TX_AF GPIO_AF1_USART2 // fix_MX_codegen.py

#define COM1_RX_PIN GPIO_PIN_3 // fix_MX_codegen.py
#define COM1_RX_GPIO_PORT GPIOA // fix_MX_codegen.py
#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() // fix_MX_codegen.py
#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() // fix_MX_codegen.py
#define COM1_RX_AF GPIO_AF1_USART2 // fix_MX_codegen.py
#define COM_POLL_TIMEOUT HAL_MAX_DELAY // fix_MX_codegen.py
#define COM1_UART USART2 // fix_MX_codegen.py
#define COM1_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE() // fix_MX_codegen.py
#define COM1_CLK_DISABLE() __HAL_RCC_USART2_CLK_DISABLE() // fix_MX_codegen.py

#define COM1_TX_PIN GPIO_PIN_2 // fix_MX_codegen.py
#define COM1_TX_GPIO_PORT GPIOA // fix_MX_codegen.py
#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() // fix_MX_codegen.py
#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() // fix_MX_codegen.py
#define COM1_TX_AF GPIO_AF1_USART2 // fix_MX_codegen.py

#define COM1_RX_PIN GPIO_PIN_3 // fix_MX_codegen.py
#define COM1_RX_GPIO_PORT GPIOA // fix_MX_codegen.py
#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() // fix_MX_codegen.py
#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() // fix_MX_codegen.py
#define COM1_RX_AF GPIO_AF1_USART2 // fix_MX_codegen.py
#define COM_POLL_TIMEOUT HAL_MAX_DELAY // fix_MX_codegen.py
#endif /* USE_BSP_COM_FEATURE */

/**
Expand Down Expand Up @@ -269,7 +269,7 @@ int32_t BSP_COM_SelectLogPort(COM_TypeDef COM);
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM);
int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM, BSP_COM_Cb_t *Callback);
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
HAL_StatusTypeDef MX_USART2_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init); // fix_MX_codegen.py
HAL_StatusTypeDef MX_USART2_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init); // fix_MX_codegen.py
#endif /* USE_BSP_COM_FEATURE */

/**
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Thu Feb 22 10:19:46 GMT+01:00 2024]
# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Sat Feb 24 00:06:37 WAT 2024]
##########################################################################################################################

# ------------------------------------------------
Expand Down Expand Up @@ -70,7 +70,7 @@ Middlewares/Third_Party/FreeRTOS/Source/timers.c \
Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0/port.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \
Drivers/BSP/STM32C0xx_Nucleo/stm32c0xx_nucleo.c # fix_MX_codegen.py
Drivers/BSP/STM32C0xx_Nucleo/stm32c0xx_nucleo.c # fix_MX_codegen.py

# ASM sources
ASM_SOURCES = \
Expand Down
25 changes: 16 additions & 9 deletions Nucleo-C031C6-FreeRTOS.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ Mcu.CPN=STM32C031C6T3
Mcu.Family=STM32C0
Mcu.IP0=CORTEX_M0+
Mcu.IP1=NUCLEO-C031C6
Mcu.IP2=NVIC
Mcu.IP3=RCC
Mcu.IP4=SYS
Mcu.IPNb=6
Mcu.IP2=NUCLEO-C031C6
Mcu.IP3=NVIC
Mcu.IP4=RCC
Mcu.IP5=SYS
Mcu.IPNb=7
Mcu.Name=STM32C031C(4-6)Tx
Mcu.Package=LQFP48
Mcu.Pin0=PC13
Mcu.Pin1=PC14-OSCX_IN (PC14)
Mcu.Pin10=PB8
Mcu.Pin11=PB9
Mcu.Pin12=VP_SYS_VS_tim1
Mcu.Pin13=VP_NUCLEO-C031C6_VS_BSP_COMMON
Mcu.Pin14=VP_STMicroelectronics.X-CUBE-FREERTOS_VS_CMSISJjRTOS2_10.5.1_1.1.0
Mcu.Pin13=VP_STMicroelectronics.X-CUBE-FREERTOS_VS_CMSISJjRTOS2_10.5.1_1.1.0
Mcu.Pin14=VP_NUCLEO-C031C6_VS_BSP_COMMON
Mcu.Pin2=PC15-OSCX_OUT (PC15)
Mcu.Pin3=PF0-OSC_IN (PF0)
Mcu.Pin4=PF1-OSC_OUT (PF1)
Expand All @@ -38,10 +39,11 @@ Mcu.UserConstants=
Mcu.UserName=STM32C031C6Tx
MxCube.Version=6.10.0
MxDb.Version=DB.6.0.100
NUCLEO-C031C6.BUTTON=0
NUCLEO-C031C6.BUTTON=1
NUCLEO-C031C6.IPParameters=BUTTON,VCP,LD4
NUCLEO-C031C6.LD4=true
NUCLEO-C031C6.VCP=true
NVIC.EXTI4_15_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
Expand Down Expand Up @@ -124,8 +126,10 @@ RCC.HSISYSCLKDivider=RCC_HSI_DIV1
RCC.HSI_VALUE=48000000
RCC.I2C1Freq_Value=48000000
RCC.I2S1Freq_Value=48000000
RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APBFreq_Value,APBTimFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSISYSCLKDivider,HSI_VALUE,I2C1Freq_Value,I2S1Freq_Value,LSCOPinFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PWRFreq_Value,SYSCLKFreq_VALUE,USART1Freq_Value
RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APBFreq_Value,APBTimFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSISYSCLKDivider,HSI_VALUE,I2C1Freq_Value,I2S1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,PWRFreq_Value,SYSCLKFreq_VALUE,USART1Freq_Value
RCC.LSCOPinFreq_Value=32000
RCC.LSE_VALUE=32768
RCC.LSI_VALUE=32000
RCC.MCO1PinFreq_Value=48000000
RCC.MCO2PinFreq_Value=48000000
RCC.PWRFreq_Value=48000000
Expand All @@ -134,10 +138,13 @@ RCC.USART1Freq_Value=48000000
SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.CMSISJjRTOS2_Checked=true
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.IPParameters=RTOS2CcCMSISJjRTOS2JjHeap,RTOS2CcCMSISJjRTOS2JjCore,configUSE_PREEMPTION
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.IPParameters=configUSE_PREEMPTION,RTOS2CcCMSISJjRTOS2JjCore,RTOS2CcCMSISJjRTOS2JjHeap,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configRECORD_STACK_HIGH_ADDRESS
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.RTOS2CcCMSISJjRTOS2JjCore=TZIiNonIiSupported
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.RTOS2CcCMSISJjRTOS2JjHeap=HeapIi4
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.configGENERATE_RUN_TIME_STATS=1
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.configRECORD_STACK_HIGH_ADDRESS=1
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.configUSE_PREEMPTION=1
STMicroelectronics.X-CUBE-FREERTOS.1.1.0.configUSE_STATS_FORMATTING_FUNCTIONS=1
STMicroelectronics.X-CUBE-FREERTOS.1.1.0_SwParameter=RTOS2CcCMSISJjRTOS2JjHeap\:HeapIi4;RTOS2CcCMSISJjRTOS2JjCore\:TZIiNonIiSupported;
VP_NUCLEO-C031C6_VS_BSP_COMMON.Mode=COMMON
VP_NUCLEO-C031C6_VS_BSP_COMMON.Signal=NUCLEO-C031C6_VS_BSP_COMMON
Expand Down
Loading

0 comments on commit 7e05e4c

Please sign in to comment.