stm32_part1 More progress on first draft, admonition fixes

This commit is contained in:
Bastian de Byl
2020-02-12 23:07:44 -05:00
parent 4f3d51cb51
commit eb50ed1e5e
7 changed files with 125 additions and 26 deletions

View File

@@ -24,10 +24,9 @@ you are on a mobile device, and my full public key:
`70A4 AA02 555D BD55 9189 B4E0 F32B E05E ADAA 54FC`[^2] `70A4 AA02 555D BD55 9189 B4E0 F32B E05E ADAA 54FC`[^2]
</center> </center>
{{% admonition info "Public Key" true %}} {{< admonition info "Public Key" true >}}
``` ```
-----BEGIN PGP PUBLIC KEY BLOCK----- -----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFoTpoMBEADDIjRewOTvJBQF4ZxK/LS7yBL0TuU7VbZzEH3s5YKj63P/Rmvx mQINBFoTpoMBEADDIjRewOTvJBQF4ZxK/LS7yBL0TuU7VbZzEH3s5YKj63P/Rmvx
8/jMm0iop+uiPNo+0imIGYsdfW77bt95I9+kBm27eVf8mDMldMiS/LBCCmnuQ19u 8/jMm0iop+uiPNo+0imIGYsdfW77bt95I9+kBm27eVf8mDMldMiS/LBCCmnuQ19u
uCq1Fd1O9JQyqxOegianl73NqtvG1UHXmnjdskDJ0N1hP0I7//g61TQkj+Qih8oI uCq1Fd1O9JQyqxOegianl73NqtvG1UHXmnjdskDJ0N1hP0I7//g61TQkj+Qih8oI
@@ -146,7 +145,7 @@ KpNnEkXDMtMCsNkEMzM+3/BkuxLO52zYpDe5tV7Igx0=
-----END PGP PUBLIC KEY BLOCK----- -----END PGP PUBLIC KEY BLOCK-----
``` ```
{{% /admonition %}} {{< /admonition >}}
# Resume # Resume
I do not currently keep an up-to-date version of my resume. In the past, I have I do not currently keep an up-to-date version of my resume. In the past, I have

View File

@@ -95,13 +95,13 @@ For an STM32F0 project, the context of the `.clang_complete` file would be:
<sub>The above assumes that `libopencm3` is also places within the project <sub>The above assumes that `libopencm3` is also places within the project
directory</sub> directory</sub>
{{% admonition warning Note %}} {{< admonition warning Note >}}
There is a strange issue that is encountered with non-working completion for new There is a strange issue that is encountered with non-working completion for new
header include statements. The workaround for this includes running `M-x irony-server-kill`after new header header include statements. The workaround for this includes running `M-x irony-server-kill`after new header
additions to your current working file. Irony's server is clever enough to additions to your current working file. Irony's server is clever enough to
restart itself after a completion request is triggered via `TAB` so this is a restart itself after a completion request is triggered via `TAB` so this is a
fairly uninvolved workaround. fairly uninvolved workaround.
{{% /admonition %}} {{< /admonition >}}
## Example ## Example
{{< img src="/static/img/emacs-clang-libopencm3/completion.png" {{< img src="/static/img/emacs-clang-libopencm3/completion.png"

View File

@@ -84,37 +84,37 @@ this via:
+ **Debian/Ubuntu, RHEL:** `sudo update-ca-certificates` + **Debian/Ubuntu, RHEL:** `sudo update-ca-certificates`
{{% admonition tip "CA Path" %}} {{< admonition tip "CA Path" >}}
On my system the full path to the CA certs is: On my system the full path to the CA certs is:
- `/etc/ca-certificates/extracted/cadir/sks-keyservers.net_CA.pem` - `/etc/ca-certificates/extracted/cadir/sks-keyservers.net_CA.pem`
{{% /admonition %}} {{< /admonition >}}
Two following parameters should be added to your `~/.gnupg` configuration files: Two following parameters should be added to your `~/.gnupg` configuration files:
### GnuPG Versions >2.1 ### GnuPG Versions >2.1
{{% admonition note "gpg.conf" %}} {{< admonition note "gpg.conf" >}}
``` ```
keyserver hkps://hkps.pool.sks-keyservers.net keyserver hkps://hkps.pool.sks-keyservers.net
``` ```
{{% /admonition %}} {{< /admonition >}}
{{% admonition note "dirmngr.conf" %}} {{< admonition note "dirmngr.conf" >}}
``` ```
hkp-cacert /etc/ca-certificates/path/to/CA.pem hkp-cacert /etc/ca-certificates/path/to/CA.pem
``` ```
{{% /admonition %}} {{< /admonition >}}
### GnuPG Versions <2.1 ### GnuPG Versions <2.1
{{% admonition note "gpg.conf" %}} {{< admonition note "gpg.conf" >}}
``` ```
keyserver hkps://hkps.pool.sks-keyservers.net keyserver hkps://hkps.pool.sks-keyservers.net
keyserver-options ca-cert-file=/path/to/CA/sks-keyservers.netCA.pem keyserver-options ca-cert-file=/path/to/CA/sks-keyservers.netCA.pem
``` ```
{{% /admonition %}} {{< /admonition >}}
## *Optional* - Ensure keys refreshed through keyserver ## *Optional* - Ensure keys refreshed through keyserver
To ensure no keys are pulled from insecure sources, or that an attacked would To ensure no keys are pulled from insecure sources, or that an attacked would

View File

@@ -13,11 +13,11 @@ from WordPress)
<!--more--> <!--more-->
# Disclaimer # Disclaimer
{{% admonition warning "Out of Date" %}} {{< admonition warning "Out of Date" >}}
The information in this article is **out-of-date**. I am, and have been, using my The information in this article is **out-of-date**. I am, and have been, using my
own fork of the [hugo-even-theme](https://gitlab.com/bdebyl/hugo-theme-even) on own fork of the [hugo-even-theme](https://gitlab.com/bdebyl/hugo-theme-even) on
my [GitLab](https://gitlab.com/bdebyl) profile. my [GitLab](https://gitlab.com/bdebyl) profile.
{{% /admonition %}} {{< /admonition >}}
--- ---

View File

@@ -62,10 +62,10 @@ It may be worth mentioning, to folks less familiar with `awk`, that the
being piped into `sha1sum`. I discovered incorrect `sha1sum` outputs **without** being piped into `sha1sum`. I discovered incorrect `sha1sum` outputs **without**
`FNR==1` resulting in a useless password check! `FNR==1` resulting in a useless password check!
{{% admonition note Note %}} {{< admonition note Note >}}
`IFS=` would not have fixed the above newline issue, as the problem stems `IFS=` would not have fixed the above newline issue, as the problem stems
from the output of `pass "$p"` and **not** the filenames. from the output of `pass "$p"` and **not** the filenames.
{{% /admonition %}} {{< /admonition >}}
That takes care of gathering our passwords, but we'll revisit this again in the That takes care of gathering our passwords, but we'll revisit this again in the
next part. next part.
@@ -108,10 +108,10 @@ it's weak (_i.e. "Exists in attack dictionary", "Too short", etc._) was to use
well-documented or fully-fledged application to fully determine password well-documented or fully-fledged application to fully determine password
strength though for my purposes it will be good enough (_I don't care to write strength though for my purposes it will be good enough (_I don't care to write
my own version of this, yet.._). my own version of this, yet.._).
{{% admonition note Note %}} {{< admonition note Note >}}
I made this part of the script **optional**, as not every user would want to I made this part of the script **optional**, as not every user would want to
install `cracklib` on their system. install `cracklib` on their system.
{{% /admonition %}} {{< /admonition >}}
This addition was made in the following order: This addition was made in the following order:

View File

@@ -14,17 +14,20 @@ series: turn on the lights!
<!--more--> <!--more-->
{{% admonition warning "Windows Users" %}} {{< admonition warning "Windows Users" >}}
This series of write-ups assumes the reader is on a Linux operating This series of write-ups assumes the reader is on a Linux operating
system. Windows users _can_ utilize the [**Windows Subsystems for system. Windows users _can_ utilize the [**Windows Subsystems for
Linux**](https://docs.microsoft.com/en-us/windows/wsl/install-win10) though your Linux**](https://docs.microsoft.com/en-us/windows/wsl/install-win10) though your
mileage may vary! mileage may vary!
{{% /admonition %}}
{{< /admonition >}}
# Straight to the Chase # Straight to the Chase
For those that want to cut to the chase and save time, here is the full source For those that want to cut to the chase and save time, here is the full source
code with friendly names to get you started: code with friendly names to get you started:
{{< admonition note "Source Code" true >}}
```C ```C
#include <libopencm3/stm32/gpio.h> #include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h> #include <libopencm3/stm32/rcc.h>
@@ -41,8 +44,8 @@ int main(void) {
while (1); while (1);
} }
``` ```
{{< /admonition >}}
# Getting Started with libopencm3 # Getting Started with libopencm3
[libopencm3](https://github.com/libopencm3/libopencm3) is a very powerful, [libopencm3](https://github.com/libopencm3/libopencm3) is a very powerful,
@@ -114,11 +117,11 @@ Makefile's variables of things you may want to change:
# Explanation # Explanation
{{% admonition info "Naming Convention" %}} {{< admonition info "Naming Convention" >}}
As a note to the reader: below I will not refer to the GPIO port or pins using As a note to the reader: below I will not refer to the GPIO port or pins using
the `#define` friendly names from above. This is purely for the sake the `#define` friendly names from above. This is purely for the sake
of clarity in hopes of avoiding confusion. of clarity in hopes of avoiding confusion.
{{% /admonition %}} {{< /admonition >}}
Although the source code is fairly simple, lets dive into it at least Although the source code is fairly simple, lets dive into it at least
_somewhat_. _somewhat_.

View File

@@ -1,5 +1,5 @@
--- ---
title: "STM32 with libopencm3 - Part 1: Simple Timer" title: "STM32F0 with libopencm3 - Part 1: Simple Timer"
date: 2020-02-12 date: 2020-02-12
lastmod: 2020-02-12 lastmod: 2020-02-12
draft: true draft: true
@@ -8,7 +8,7 @@ categories: ["Tutorial"]
contentCopyright: false contentCopyright: false
hideHeaderAndFooter: false hideHeaderAndFooter: false
--- ---
After having reviewed [part 0](/post/stm32-part0) of this series, we can now After having reviewed [**Part 0**](/post/stm32-part0) of this series, we can now
explore controlling GPIO with the hardware timers! Other tutorials have used the explore controlling GPIO with the hardware timers! Other tutorials have used the
Systick timer as a good introduction to adding a delay for blinking an Systick timer as a good introduction to adding a delay for blinking an
LED. However, it is my belief that this leads to confusion for beginners and LED. However, it is my belief that this leads to confusion for beginners and
@@ -16,3 +16,100 @@ only opens the door to misunderstandings. That being said, we will be using
timers and their associated GPIO ports with Alternate Function modes. timers and their associated GPIO ports with Alternate Function modes.
<!--more--> <!--more-->
# Straight to the Chase
For those that want to cut to the chase and save time, here is the full source
code with friendly names to get you started:
{{< admonition note "Source Code" true >}}
```C
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/timer.h>
#define LED_PORT GPIOC
#define LED_PIN_BLU GPIO8
#define LED_PIN_GRN GPIO9
#define TIM_PSC_DIV 48000
#define SECONDS 1
volatile unsigned int i;
int main(void) {
rcc_clock_setup_in_hsi_out_48mhz();
rcc_periph_clock_enable(RCC_GPIOC);
rcc_periph_clock_enable(RCC_TIM3);
gpio_mode_setup(LED_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, LED_PIN_BLU | LED_PIN_GRN);
gpio_set_output_options(LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_HIGH, LED_PIN_BLU | LED_PIN_GRN);
gpio_set_af(LED_PORT, GPIO_AF0, LED_PIN_BLU | LED_PIN_GRN);
timer_set_mode(TIM3, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1, TIM_CR1_DIR_UP);
// The math for seconds isn't quite right here
timer_set_prescaler(TIM3, (rcc_apb1_frequency/TIM_PSC_DIV)/2*SECONDS);
timer_disable_preload(TIM3);
timer_continuous_mode(TIM3);
timer_set_period(TIM3, TIM_PSC_DIV);
timer_set_oc_mode(TIM3, TIM_OC3, TIM_OCM_PWM1);
timer_set_oc_mode(TIM3, TIM_OC4, TIM_OCM_PWM2);
int tim_oc_ids[2] = { TIM_OC3, TIM_OC4 };
for (i = 0; i < (sizeof(tim_oc_ids)/sizeof(tim_oc_ids[0])); ++i) {
timer_set_oc_value(TIM3, tim_oc_ids[i], (TIM_PSC_DIV/2));
}
timer_enable_oc_output(TIM3, TIM_OC3);
timer_enable_oc_output(TIM3, TIM_OC4);
timer_enable_counter(TIM3);
while (1) {
;
}
return 0;
}
```
{{< /admonition >}}
# Set up the GPIO
Assuming the reader is either familiar with GPIO setup for the STM32F0, or has
reviewed [**Part 0**](/post/stm32-part0) of this series we will set up the GPIO
pins tied to the LEDs (_port C, pins 8 and 9_) in the Alternate Function mode.
## Alternate Functions
The STM32 microcontroller's GPIO has a hardware feature allowing you to tie
certain port's pins to a different register as part of the output or input
control:
{{< img src="/static/img/stm32-examples/part1/stm32-af-diagram.png"
sub="GPIO Alternate Function Diagram" >}}
For accomplishing this, a few things need to happen:
1. The desired GPIO pins need to be set to `GPIO_MODE_AF` in `gpio_mode_setup()`
1. The alternate function mode number `GPIO_AFx` has to be set for the pins using `gpio_set_af()`
{{< admonition warning "Note for Different STM32Fx Microcontrollers" >}}
Review the datasheet for the specific **STM32Fx** microcontroller being
programmed, as the Alternate Function mappings may be *significantly* different!
{{< /admonition >}}
## GPIO Alternate Function Setup
For the STM32F0 we are using in this series, the Alternate Function selection
number desired is `GPIO_AF0` for use with `TIM3_CH3` (_timer 3, channel 3_) and
`TIM3_CH4` (_timer 3, channel 4_):
{{< img src="/static/img/stm32-examples/part1/stm32-af-gpiomap.png"
sub="STM32F051 Alternate Function Mapping" >}}
Ultimately, the code with `libopencm3` becomes the following for our use case:
```C
gpio_mode_setup(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO8 | GPIO9);
gpio_set_output_options(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_HIGH, GPIO8 | GPIO9);
gpio_set_af(GPIOC, GPIO_AF0, GPIO8 | GPIO9);
```