Preparing for the first post
All checks were successful
Build and push latest / publish (push) Successful in 49s
All checks were successful
Build and push latest / publish (push) Successful in 49s
This commit is contained in:
parent
7717483821
commit
9f0e6fe37f
@ -1,7 +1,7 @@
|
||||
---
|
||||
title: "Running ROS2 with localhost only."
|
||||
date: 2024-05-22T21:36:00+03:00
|
||||
draft: false
|
||||
draft: true
|
||||
summary: "Ever had ROS2 DoS your router accidentally? Want to learn how to stop that from happening? Well, here you are."
|
||||
author: "Rusted Skull"
|
||||
series: []
|
||||
|
||||
108
content/posts/002-stm32begin-001-setup-and-scaffold.md
Normal file
108
content/posts/002-stm32begin-001-setup-and-scaffold.md
Normal file
@ -0,0 +1,108 @@
|
||||
---
|
||||
title: "STM32 For Beginners: setup and scaffolding."
|
||||
date: 2024-09-26T00:36:00+03:00
|
||||
draft: false
|
||||
summary: "..."
|
||||
author: "Rusted Skull"
|
||||
series: ["STM32 For Beginners"]
|
||||
tags: ["Embedded", "STM32"]
|
||||
---
|
||||
|
||||
{{< video src="/test.webm" typ="video/webm" preload="auto" caption="two" >}}
|
||||
|
||||
{{< figure src="/test2.png" caption="More memes." >}}
|
||||
|
||||
# Code
|
||||
|
||||
STM32Cube will now generate code for you. This is all the code that's necessary for initialization of the microcontroller hardware (clocks, interrupts, etc.) and peripherals (GPIOs, UART, etc.) This allows us to skip a bunch of menial code writing ourselves.
|
||||
|
||||
The code itself is structured in a bit of a weird way, if you're faced with something like this for the first time. Namely, it has a bunch of commented sections which say "USER CODE BEGIN/END". There's a few rules regarding this code structure:
|
||||
|
||||
1. Generated files get written over and adjusted if you regenerate the code again.
|
||||
2. Write code **between** a set of BEGIN/END comments, and your code will be fine.
|
||||
3. Do not delete or move these comments.
|
||||
4. Any files you create yourself are unaffected by the generator.
|
||||
|
||||
## Structure
|
||||
|
||||
For the purpose of this guide, we'll be interested in the `main.c`file, located in the `Core\Src\` folder.
|
||||
|
||||
In there, locate the `int main(void)` function and make note of the following sections before and after the line:
|
||||
```cpp
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
```
|
||||
and
|
||||
```cpp
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
```
|
||||
|
||||
# Printouts and "Hello World"
|
||||
|
||||
Our first goal will be writing doing a simple printout. A classical "hello world". Well, given our restrictions, this is going to take a bit of doing.
|
||||
|
||||
Typically, in C, we'd accomplish this by using `printf()`. However, with a microcontroller, printf goes nowhere by default. So our first goal is to redirect that printf command into something we can pick up with our PCs. We're going to use UART for this.
|
||||
|
||||
We've already enabled UART in our cube with the VCP.
|
||||
|
||||
## Writing into UART
|
||||
|
||||
For writing into UART, we'd use the `HAL_UART_Transmit` function. The function requires the following arguments:
|
||||
* `huart`, which is a pointer to the UART hardware instance we're going to use,
|
||||
* `pData`, the pointer to the data we wish to write over UART,
|
||||
* `Size`, indicates how many bytes from `pData` are to be transmitted,
|
||||
* `Timeout`, the time in milliseconds to wait for the function to complete, before returning an error.
|
||||
|
||||
In order to invoke this, we need to do a few steps first.
|
||||
|
||||
First, we must define the string to write. Declaring a char array and initializing it with a predefined string. We can do this by writing `const char* my_str = "Hello world";`
|
||||
|
||||
Next up, we need the length of the the string. We could count it ourselves, and save it to a variable; or we could use the `strlen` function from the C standard library. For illustration purposes, we'll do the latter: `int length = strlen(my_str);`
|
||||
|
||||
Finally, we need to dispatch the entire thing into the transmit function. `pData` will be our string variable (it's already a pointer), `Size` will be the length of the string, and for the `huart` argument, we'll use `&huart2`. This can be checked from the STM32CubeMX configurator, look at which of the UART interface is being used for the VCP pins.
|
||||
|
||||
In completeness, it looks like this:
|
||||
```cpp
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
#include <string.h> // This include is necessary for the strlen function.
|
||||
/* USER CODE END 0 */
|
||||
```
|
||||
and
|
||||
```cpp
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
const char* my_str = "Hello world";
|
||||
int length = strlen(my_str);
|
||||
HAL_UART_Transmit(&huart2, my_Str, length, 100);
|
||||
|
||||
HAL_Delay(1000); // This is necessary to stop the UART from continously writing and spamming.
|
||||
// HAL_Delay(n) will make the microcontroller wait for n milliseconds.
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
```
|
||||
|
||||
This code
|
||||
@ -1,25 +0,0 @@
|
||||
---
|
||||
title: "My First Post"
|
||||
date: 2023-07-16T13:39:31+03:00
|
||||
draft: false
|
||||
summary: "This is safsdfan test."
|
||||
author: "Rusted Skull"
|
||||
series: ["Tutorial"]
|
||||
tags: ["Generic", "Memes"]
|
||||
---
|
||||
|
||||
welcome to test.
|
||||
|
||||
## Introduction
|
||||
|
||||
This is **bold** text, and this is *emphasized* text.
|
||||
|
||||
Visit the [Hugo](https://gohugo.io) website!
|
||||
|
||||
```cpp
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
@ -1,11 +0,0 @@
|
||||
---
|
||||
title: "Second post"
|
||||
date: 2024-05-22T21:36:00+03:00
|
||||
draft: false
|
||||
summary: "This is the second test. Woopie!"
|
||||
author: "Rusted Skull"
|
||||
series: ["Tutorial"]
|
||||
tags: ["Generic", "Memes"]
|
||||
---
|
||||
|
||||
And here we go.
|
||||
29
layouts/shortcodes/figure.html
Normal file
29
layouts/shortcodes/figure.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!--
|
||||
Put this file in /layouts/shortcodes/figure.html
|
||||
NB this overrides Hugo's built-in "figure" shortcode but is backwards compatible
|
||||
Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
|
||||
-->
|
||||
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
|
||||
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="{{ "css/hugo-easy-gallery.css" | absURL}}" />{{ end }}
|
||||
{{- $.Page.Scratch.Add "figurecount" 1 -}}
|
||||
<!-- use either src or link-thumb for thumbnail image -->
|
||||
{{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
|
||||
<div class="box{{ with .Get "caption-position" }} fancy-figure caption-position-{{.}}{{end}}{{ with .Get "caption-effect" }} caption-effect-{{.}}{{end}}" {{ with .Get "width" }}style="max-width:{{.}}"{{end}}>
|
||||
<figure {{ with .Get "class" }}class="{{.}}"{{ end }} itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
|
||||
<div class="img"{{ if .Parent }} style="background-image: url('{{ print .Site.BaseURL $thumb }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
|
||||
<img itemprop="thumbnail" src="{{ $thumb }}" {{ with .Get "alt" | default (.Get "caption") | default $thumb }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
|
||||
</div>
|
||||
{{ with .Get "link" | default (.Get "src") }}<a href="{{.}}" itemprop="contentUrl"></a>{{ end }}
|
||||
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
|
||||
<figcaption>
|
||||
{{- with .Get "title" }}<h4>{{.}}</h4>{{ end }}
|
||||
{{- if or (.Get "caption") (.Get "attr")}}
|
||||
<p class="caption">
|
||||
{{- .Get "caption" -}}
|
||||
{{- with .Get "attrlink"}}<a href="{{.}}">{{ .Get "attr" }}</a>{{ else }}{{ .Get "attr"}}{{ end -}}
|
||||
</p>
|
||||
{{- end }}
|
||||
</figcaption>
|
||||
{{- end }}
|
||||
</figure>
|
||||
</div>
|
||||
23
layouts/shortcodes/video.html
Normal file
23
layouts/shortcodes/video.html
Normal file
@ -0,0 +1,23 @@
|
||||
<style>
|
||||
.video-shortcode {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin: auto;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
|
||||
<figure>
|
||||
<video class="video-shortcode" preload="{{ .Get "preload" }}" controls>
|
||||
<source src="{{ .Get "src" }}" type="{{ .Get "type" }}">
|
||||
There should have been a video here but your browser does not seem
|
||||
to support it.
|
||||
</video>
|
||||
<figcaption>
|
||||
{{- if or (.Get "caption") (.Get "attr")}}
|
||||
<p class="caption">
|
||||
{{- .Get "caption" -}}
|
||||
</p>
|
||||
{{- end}}
|
||||
</figcaption>
|
||||
</figure>
|
||||
Loading…
x
Reference in New Issue
Block a user