User manual

Contents UM0036
8/385 Doc ID 7705 Rev 11
12 STM8 C tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
12.1 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
12.1.1 Install the toolset and configure the STVD . . . . . . . . . . . . . . . . . . . . . 333
12.1.2 Create a workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
12.1.3 Create a project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
12.1.4 Add the source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
12.1.5 Create a folder to organize files in the project . . . . . . . . . . . . . . . . . . . 338
12.2 Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
12.2.1 Specify the target STM8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
12.2.2 Customize the C compiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
12.2.3 Change build settings for a specific file . . . . . . . . . . . . . . . . . . . . . . . . 342
12.2.4 Build the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
12.3 Start debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
12.3.1 Start the debugging session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
12.3.2 Run and stop the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
12.3.3 Step through the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
12.4 Instruction breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
12.4.1 Set an instruction breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
12.4.2 Set a counter on an instruction breakpoint . . . . . . . . . . . . . . . . . . . . . 349
12.4.3 Set a condition on an instruction breakpoint . . . . . . . . . . . . . . . . . . . . 350
12.5 View execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
12.5.1 View calls to the stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
12.5.2 View and change local variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
12.5.3 View variables using the Watch, QuickWatch and Memory windows . 352
12.6 Perform memory mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
12.7 Advanced emulator features for EMU3 (ST7) and STice (STM8) . . . . . 356
12.7.1 View program execution history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
12.7.2 Use read/write on-the-fly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
12.7.3 Set an advanced breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
12.7.4 Run a coverage and profiling session . . . . . . . . . . . . . . . . . . . . . . . . . 363
12.7.5 Run a performance analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
13 ST Assembler/Linker build tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
13.1 Create a new workspace with the New Workspace wizard . . . . . . . . . . 366
13.2 Create a project using Add New Project to Workspace command . . . . . 367
13.3 Inserting files in your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368