diff --git a/content/posts/001-ros2-localhost.md b/content/posts/001-ros2-localhost.md index 1246e78..0bf5abe 100644 --- a/content/posts/001-ros2-localhost.md +++ b/content/posts/001-ros2-localhost.md @@ -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: [] diff --git a/content/posts/002-stm32begin-001-setup-and-scaffold.md b/content/posts/002-stm32begin-001-setup-and-scaffold.md new file mode 100644 index 0000000..71841bd --- /dev/null +++ b/content/posts/002-stm32begin-001-setup-and-scaffold.md @@ -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 // 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 diff --git a/content/posts/my-first-post.md b/content/posts/my-first-post.md deleted file mode 100644 index 1c8a961..0000000 --- a/content/posts/my-first-post.md +++ /dev/null @@ -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; -} - -``` diff --git a/content/posts/second-post.md b/content/posts/second-post.md deleted file mode 100644 index 324d7bc..0000000 --- a/content/posts/second-post.md +++ /dev/null @@ -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. diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html new file mode 100644 index 0000000..a7e289a --- /dev/null +++ b/layouts/shortcodes/figure.html @@ -0,0 +1,29 @@ + + +{{- if not ($.Page.Scratch.Get "figurecount") }}{{ end }} +{{- $.Page.Scratch.Add "figurecount" 1 -}} + +{{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }} +
+
+
+ +
+ {{ with .Get "link" | default (.Get "src") }}{{ end }} + {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} +
+ {{- with .Get "title" }}

{{.}}

{{ end }} + {{- if or (.Get "caption") (.Get "attr")}} +

+ {{- .Get "caption" -}} + {{- with .Get "attrlink"}}{{ .Get "attr" }}{{ else }}{{ .Get "attr"}}{{ end -}} +

+ {{- end }} +
+ {{- end }} +
+
diff --git a/layouts/shortcodes/video.html b/layouts/shortcodes/video.html new file mode 100644 index 0000000..3487b5b --- /dev/null +++ b/layouts/shortcodes/video.html @@ -0,0 +1,23 @@ + + +
+ +
+ {{- if or (.Get "caption") (.Get "attr")}} +

+ {{- .Get "caption" -}} +

+ {{- end}} +
+
\ No newline at end of file