Labs code to be added (v1.0): ----------------------------- - STM32C0 MOOC Lab 1: Blinky in main.c: HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); HAL_Delay(100); - STM32C0 MOOC Lab 2: PWM in main.c: HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); - STM32C0 MOOC Lab 3: EXTI in main.c uint8_t PC13_flag = 0; ////////////////////// void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin) { PC13_flag++; if ( ( PC13_flag & 0x01 ) == 0x01 ) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); } } - STM32C0 MOOC Lab 4: Printf debugging using UART in main.c: /* USER CODE BEGIN PFP */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) /* USER CODE END PFP */ //////////////////////////// while (1) { printf("** Hello World ** \n\r"); HAL_Delay(1000); /* USER CODE END WHILE */ ///////////////////////////// /* USER CODE BEGIN 4 */ PUTCHAR_PROTOTYPE { HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF); return ch; } /* USER CODE END 4 */ - STM32C0 MOOC Lab 5: LL Drivers in main.c: LL_GPIO_TogglePin(GPIOA, LL_GPIO_PIN_5); // Delay 100 ms LL_mDelay(100); - STM32C0 MOOC Lab 6: ADC + DMA + TIM in main.c: /* USER CODE BEGIN PV */ uint8_t buffer[8]; ... /* USER CODE BEGIN 2 */ HAL_ADCEx_Calibration_Start(&hadc1); HAL_ADC_Start_DMA(&hadc1, (uint32_t *)buffer, 8); HAL_TIM_Base_Start(&htim3); - STM32C0 MOOC Lab 7: RAM in main.c: /* USER CODE BEGIN 2 */ LL_USART_EnableIT_RXNE(USART2); LL_USART_EnableIT_ERROR(USART2); ... /* USER CODE BEGIN 4 */ void USART_CharReception_Callback(void) { uint8_t received_char; received_char = LL_USART_ReceiveData8(USART2); if ((received_char == 'E') || (received_char == 'e')) { LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); } LL_USART_TransmitData8(USART2, received_char); } in main.h: /* USER CODE BEGIN EFP */ void USART_CharReception_Callback(void); /* USER CODE END EFP */ in stm32c0xx_it.c: /* USER CODE BEGIN USART2_IRQn 0 */ USART_CharReception_Callback(); /* USER CODE END USART2_IRQn 0 */ in STM32C031C6TX_FLASH.ld: */Drivers/*(.text*) *main.o(.text.MX_GPIO_Init) *main.o(.text.MX_USART2_UART_Init) *main.o(.text.USART_CharReception_Callback) - STM32C0 MOOC Lab 8: RTOS in main.c ... /* USER CODE BEGIN 0 */ void __io_putchar(char ch) { // Code to write character 'ch' on the UART HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 10); } /* USER CODE END 0 */ ... in app_threadx.c ... /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include #include "main.h" /* USER CODE END Includes */ ... /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ #define BTN_STATUS_STACK_SIZE 512 #define LED_ACTION_STACK_SIZE 512 #define LED_STATUS_STACK_SIZE 512 #define QUEUE_STACK_SIZE 16 /* USER CODE END PD */ ... /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ uint8_t btn_status_stack[BTN_STATUS_STACK_SIZE]; uint8_t led_action_stack[LED_ACTION_STACK_SIZE]; uint8_t led_status_stack[LED_STATUS_STACK_SIZE]; uint8_t queue0_stack[QUEUE_STACK_SIZE]; uint8_t queue1_stack[QUEUE_STACK_SIZE]; TX_THREAD btn_status_ptr; TX_THREAD led_action_ptr; TX_THREAD led_status_ptr; TX_QUEUE queue0_ptr; TX_QUEUE queue1_ptr; /* USER CODE END PV */ ... /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ VOID btn_status(ULONG initial_input); VOID led_action(ULONG initial_input); VOID led_status(ULONG initial_input); /* USER CODE END PFP */ ... /* USER CODE BEGIN App_ThreadX_Init */ tx_queue_create(&queue0_ptr, "message_btn_status", TX_1_ULONG ,queue0_stack,QUEUE_STACK_SIZE); tx_queue_create(&queue1_ptr, "message_led_status", TX_1_ULONG ,queue1_stack,QUEUE_STACK_SIZE); tx_thread_create(&btn_status_ptr,"btn_status",btn_status,0,btn_status_stack, BTN_STATUS_STACK_SIZE,15,15,1,TX_AUTO_START); tx_thread_create(&led_action_ptr,"led_action",led_action,0,led_action_stack, LED_ACTION_STACK_SIZE,15,15,1,TX_AUTO_START); tx_thread_create(&led_status_ptr,"led_status",led_status,0,led_status_stack, LED_STATUS_STACK_SIZE,15,15,1,TX_AUTO_START); /* USER CODE END App_ThreadX_Init */ ... /* USER CODE BEGIN 1 */ VOID btn_status (ULONG initial_input) { ULONG message_pin_status = DISABLE; ULONG message_pin_status_new = DISABLE; while(1) { tx_thread_sleep(10); if(!HAL_GPIO_ReadPin(User_Button_GPIO_Port, User_Button_Pin)) { message_pin_status_new = ENABLE; } else { message_pin_status_new = DISABLE; } if (message_pin_status != message_pin_status_new) { message_pin_status = message_pin_status_new; tx_queue_send(&queue0_ptr,&message_pin_status,TX_NO_WAIT); } } } VOID led_action(ULONG initial_input) { ULONG message_status; while(1) { tx_queue_receive(&queue0_ptr,&message_status,TX_WAIT_FOREVER); if(message_status) { HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin,GPIO_PIN_SET); } else { HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin,GPIO_PIN_RESET); } tx_queue_send(&queue1_ptr,&message_status,TX_NO_WAIT); } } VOID led_status(ULONG initial_input) { ULONG message_status = DISABLE; while(1) { tx_queue_receive(&queue1_ptr,&message_status,TX_WAIT_FOREVER); if(message_status) printf("The LED is ON\r\n"); else printf("The LED is OFF\r\n"); } } - STM32C0 MOOC Lab 9: Low Power in main.c ... /* USER CODE BEGIN 2 */ // RUN mode HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); HAL_Delay(5000); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); // enter STOP mode HAL_SuspendTick(); HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); HAL_ResumeTick(); /* USER CODE END 2 */ ... /* USER CODE BEGIN WHILE */ while (1) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(1000); /* USER CODE END WHILE */