-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5da4be
commit 2bfdf00
Showing
11 changed files
with
485 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from swo_parser import swo_parser_main | ||
import subprocess | ||
from os import path, __file__ | ||
import time | ||
import sys | ||
Import("env") | ||
|
||
def swo_viewer_task(*args, **kwargs): | ||
print("Entrypoint") | ||
board = env.BoardConfig() | ||
platform = env.PioPlatform() | ||
debug = board.manifest.get("debug", {}) | ||
openocd_path = path.join(platform.get_package_dir("tool-openocd"), "bin", "openocd") | ||
upload_protocol = env.subst("$UPLOAD_PROTOCOL") | ||
#connect_to_openocd_tcl() | ||
server_args = [ | ||
"-s", | ||
path.join(platform.get_package_dir("tool-openocd"), "scripts") | ||
] | ||
if debug.get("openocd_board"): | ||
server_args.extend([ | ||
"-f", "board/%s.cfg" % debug.get("openocd_board") | ||
]) | ||
else: | ||
assert debug.get("openocd_target"), ( | ||
"Missed target configuration for %s" % board.id) | ||
server_args.extend([ | ||
"-f", "interface/%s.cfg" % link, | ||
"-c", "transport select %s" % ( | ||
"hla_swd" if upload_protocol == "stlink" else "swd"), | ||
"-f", "target/%s.cfg" % debug.get("openocd_target") | ||
]) | ||
# per https://openocd.org/doc-release/pdf/openocd.pdf | ||
# TRACECLKIN_freq: this should be specified to match target's current TRACECLKIN frequency (usually the same as HCLK). | ||
# trace_freq: trace port frequency. Can be omitted in internal mode to let the adapter driver select the maximum supported rate automatically. | ||
swo_trace_clkin_freq = str(env.GetProjectOption("swo_trace_clkin_freq", env.subst("$BOARD_F_CPU")[:-1])) | ||
swo_trace_freq = str(env.GetProjectOption("swo_trace_freq", "115200")) | ||
server_args.extend([ | ||
"-c", "init; tpiu config internal - uart false %s %s; itm ports on" % (swo_trace_clkin_freq, swo_trace_freq), | ||
#"-c", "reset run" | ||
# SWO parser.py was extended to make target run | ||
]) | ||
server_args.insert(0, openocd_path) | ||
print("Starting OpenOCD with SWO Trace clock-in frequency %s, SWO trace frequency %s. Invocation:" % (swo_trace_clkin_freq, swo_trace_freq)) | ||
print(server_args) | ||
# start client process in parallel | ||
subprocess.Popen([env.subst("$PYTHONEXE"), path.join(env.subst("$PROJECT_DIR"), "swo_parser.py")]) | ||
# start openocd process parallel but wait in-line | ||
openocd_process = subprocess.Popen(server_args) | ||
openocd_process.communicate() | ||
print("Exited from TCL client") | ||
sys.exc_clear() | ||
|
||
env.AddCustomTarget( | ||
"swo_viewer", | ||
None, | ||
swo_viewer_task, | ||
title="SWO Viewer", | ||
description="Starts viewing the SWO output", | ||
always_build=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
This directory is intended for project header files. | ||
|
||
A header file is a file containing C declarations and macro definitions | ||
to be shared between several project source files. You request the use of a | ||
header file in your project source file (C, C++, etc) located in `src` folder | ||
by including it, with the C preprocessing directive `#include'. | ||
|
||
```src/main.c | ||
|
||
#include "header.h" | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
``` | ||
|
||
Including a header file produces the same results as copying the header file | ||
into each source file that needs it. Such copying would be time-consuming | ||
and error-prone. With a header file, the related declarations appear | ||
in only one place. If they need to be changed, they can be changed in one | ||
place, and programs that include the header file will automatically use the | ||
new version when next recompiled. The header file eliminates the labor of | ||
finding and changing all the copies as well as the risk that a failure to | ||
find one copy will result in inconsistencies within a program. | ||
|
||
In C, the usual convention is to give header files names that end with `.h'. | ||
It is most portable to use only letters, digits, dashes, and underscores in | ||
header file names, and at most one dot. | ||
|
||
Read more about using header files in official GCC documentation: | ||
|
||
* Include Syntax | ||
* Include Operation | ||
* Once-Only Headers | ||
* Computed Includes | ||
|
||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
This directory is intended for project specific (private) libraries. | ||
PlatformIO will compile them to static libraries and link into executable file. | ||
|
||
The source code of each library should be placed in a an own separate directory | ||
("lib/your_library_name/[here are source files]"). | ||
|
||
For example, see a structure of the following two libraries `Foo` and `Bar`: | ||
|
||
|--lib | ||
| | | ||
| |--Bar | ||
| | |--docs | ||
| | |--examples | ||
| | |--src | ||
| | |- Bar.c | ||
| | |- Bar.h | ||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html | ||
| | | ||
| |--Foo | ||
| | |- Foo.c | ||
| | |- Foo.h | ||
| | | ||
| |- README --> THIS FILE | ||
| | ||
|- platformio.ini | ||
|--src | ||
|- main.c | ||
|
||
and a contents of `src/main.c`: | ||
``` | ||
#include <Foo.h> | ||
#include <Bar.h> | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
|
||
``` | ||
|
||
PlatformIO Library Dependency Finder will find automatically dependent | ||
libraries scanning project source files. | ||
|
||
More information about PlatformIO Library Dependency Finder | ||
- https://docs.platformio.org/page/librarymanager/ldf.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[env:nucleo_f103rb] | ||
platform = ststm32 | ||
board = nucleo_f103rb | ||
framework = stm32cube | ||
; add "Custom" -> "SWO Viewer" project task | ||
extra_scripts = pre:add_swo_viewer.py | ||
; set SWO trace clock in frequency to configured HCLK frequency | ||
; in this example, board is clocked via HSI to 64MHz. | ||
; if this number is wrong, there will be no output. | ||
swo_trace_clkin_freq = 64000000 | ||
; if you want to see SWO outputs during debugging, a custom | ||
; debug server invocation must be used. | ||
; adapt interface and target accordingly. | ||
; this is used when starting debugging, not in the SWO Viewer task. | ||
; after debugging starts, one must manually start the swo_viewer.py with | ||
; python swo_parser.py --dont-run | ||
debug_server = $PLATFORMIO_CORE_DIR/packages/tool-openocd/bin/openocd | ||
-f $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/interface/stlink.cfg | ||
-f $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/target/stm32f1x.cfg | ||
-c "tpiu config internal - uart off 64000000" | ||
-c "itm ports on" | ||
-c "tcl_port 6666" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "stm32f1xx_hal.h" | ||
#include <errno.h> | ||
#include <sys/unistd.h> // STDOUT_FILENO, STDERR_FILENO | ||
#include <stdio.h> | ||
|
||
#define LED_PIN GPIO_PIN_5 | ||
#define LED_GPIO_PORT GPIOA | ||
#define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | ||
|
||
void SystemClock_Config(void); | ||
|
||
int main(void) | ||
{ | ||
HAL_Init(); | ||
SystemClock_Config(); | ||
SystemCoreClockUpdate(); | ||
|
||
LED_GPIO_CLK_ENABLE(); | ||
|
||
GPIO_InitTypeDef GPIO_InitStruct; | ||
|
||
GPIO_InitStruct.Pin = LED_PIN; | ||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||
GPIO_InitStruct.Pull = GPIO_PULLUP; | ||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; | ||
HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct); | ||
|
||
printf("SWO test firmware start!\n"); | ||
while (1) | ||
{ | ||
static int i=0; | ||
printf("Blinky number %d!\n", i++); | ||
HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN); | ||
HAL_Delay(1000); | ||
} | ||
} | ||
|
||
void SysTick_Handler(void) | ||
{ | ||
HAL_IncTick(); | ||
} | ||
|
||
//overwrite printf() output to send via ITM (SWO) | ||
int _write(int file, char *data, int len) | ||
{ | ||
if ((file != STDOUT_FILENO) && (file != STDERR_FILENO)) | ||
{ | ||
errno = EBADF; | ||
return -1; | ||
} | ||
|
||
for (int i = 0; i < len; i++) | ||
{ | ||
ITM_SendChar(data[i]); | ||
} | ||
|
||
// return # of bytes written - as best we can tell | ||
return len; | ||
} | ||
|
||
/* bring up internal clocks to 64 MHz via HSI -- otherwise we are still at 8MHz default */ | ||
void SystemClock_Config(void) | ||
{ | ||
RCC_OscInitTypeDef RCC_OscInitStruct = {}; | ||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {}; | ||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {}; | ||
|
||
/* Initializes the CPU, AHB and APB busses clocks */ | ||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | ||
RCC_OscInitStruct.HSIState = RCC_HSI_ON; | ||
RCC_OscInitStruct.HSICalibrationValue = 16; | ||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | ||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; | ||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; | ||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) | ||
{ | ||
//Error_Handler(); | ||
} | ||
|
||
/* Initializes the CPU, AHB and APB busses clocks */ | ||
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_DIV2; | ||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | ||
|
||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) | ||
{ | ||
//Error_Handler(); | ||
} | ||
|
||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; | ||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; | ||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) | ||
{ | ||
//Error_Handler(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.