2024-11-19 11:04 AM - last edited on 2024-11-19 11:46 AM by Andrew Neil
Hello,
Firstly I'd like to say I have googled for examples and worked independently by reading ST docs and looked at the suggested topics before posting. I did begin to hijack another thread but I'll start one instead.
What a long and painful tradition printing with ST dev boards is!
My latest attempt is to follow this SWV tutorial for another board.
Apologies if it's something ridiculous, I'm new!
Having just tested the code before posting tonight, even with non blink related code commented out it has stopped blinking but still some help please :D
https://www.youtube.com/watch?v=sPzQ5CniWtw
Here is the code I am running.
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h" //The printf function is here
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
ETH_HandleTypeDef heth;
UART_HandleTypeDef huart3;
PCD_HandleTypeDef hpcd_USB_OTG_FS;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ETH_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_USB_OTG_FS_PCD_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int _write(int file, char *ptr, int len)
{
/* Implement your write code here, this is used by puts and printf for example */
int i=0;
for(i=0 ; i<len ; i++)
ITM_SendChar((*ptr++));
return len;
}
uint8_t count = 0; //rigtht data type?
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ETH_Init();
MX_USART3_UART_Init();
MX_USB_OTG_FS_PCD_Init(); //not helping?
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOB, LD1_Pin); //Toggle the LED
count++; //Increment the count var
printf ("HELLO WORLD count = %d \n", count); // print the count var
HAL_Delay(250);
}
/* USER CODE END 3 */
}
Which involves rewriting the write() function. I also tried this write function
int _write(int file, char *ptr, int len) { int DataIdx; for(DataIdx=0; DataIdx<len; DataIdx++) { ITM_SendChar(*ptr++); } return len; }
My debugger is shutting down (RGB lights out) and sometimes has to be power cycled.
I have tried various core clock settings in the debug config tab.
here are photos of the clock page, debug config and RCC options.
Thank you TeslaDelorian for trying to help in the previously hijacked thread. Here is my clock info.
Thanks
Solved! Go to Solution.
2024-11-19 01:05 PM - edited 2024-11-19 01:08 PM
If the task looks hard (for beginners everything is hard) - divide it to steps. So, step 1: make low-level ITM_SendChar work. Something like:
void test()
{
for (char *p = "\nHello ITM\n"; *p; p++) {
ITM_SendChar(*p);
}
}
Make sure the test string ends with \n.
Until you see this string printing do not move further, to _write, printf etc.
The HSI as PLL source, when HSE is available, is strange... but well let's try.
2024-11-19 11:17 AM - edited 2024-11-19 11:18 AM
Looks good. Now, to begin seeing SWO output in CubeIDE: after you start the program and it hits the first breakpoint in the debugger: click the red button in the SWO output. First time, the ITM setup dialog will open. Check the checkbox for port 0 (it is used for the prints). Do not change other fields for now. OK out of the dialogs and run.
2024-11-19 11:44 AM
Hello,
Refer to this article, you can inspire from it:https://community.st.com/t5/stm32-mcus/using-the-itm-console-for-printf-redirects-and-lwip-debug/ta-p/723472
2024-11-19 11:57 AM
Hi,
Thanks for the reply.
I started the program (debug button) and hit the red/record button in various SWV outputs before continuing. Not SWO as I have set u for SWV through the ITM.
No blink and no data.
Sorry I do realise that I could have added more context. SWO does not work. All of this is because SWO does not seem to work.
Is this correct? I am using a Nucleo-F207ZG
I just want to print if you know a simple way to print using SWO please explain. It sounds like more complex code is needed (simple printf commands do not work).
Thanks
2024-11-19 01:05 PM - edited 2024-11-19 01:08 PM
If the task looks hard (for beginners everything is hard) - divide it to steps. So, step 1: make low-level ITM_SendChar work. Something like:
void test()
{
for (char *p = "\nHello ITM\n"; *p; p++) {
ITM_SendChar(*p);
}
}
Make sure the test string ends with \n.
Until you see this string printing do not move further, to _write, printf etc.
The HSI as PLL source, when HSE is available, is strange... but well let's try.
2024-11-19 01:25 PM
That's awesome, thanks. I'll have a go tomorrow evening hopefully.