Skip to content

Instantly share code, notes, and snippets.

View nebelgrau77's full-sized avatar
👾

Michal Lasak nebelgrau77

👾
View GitHub Profile
#![no_main]
#![no_std]

extern crate panic_halt;

use cortex_m_rt::entry;
use stm32l0::stm32l0x1;
use stm32l0xx_hal::{
    pac,
@nebelgrau77
nebelgrau77 / inventory.md
Last active May 24, 2020 16:31
Rust - struct with a str field - lifetime problem.
use std::io;
#[derive(Copy, Clone, Debug)]
struct Record<'a> {
    id: u16,
    name: &'a str,
    quantity: u16,
    price: f32,
}
@nebelgrau77
nebelgrau77 / MicroPython on STM32F4xx.md
Last active March 12, 2024 16:11
how to install MicroPython on cheap STM32F4xx boards ("black pill", "black F407")

Installing MicroPython on inexpensive STM32F4xx boards

This tutorial will explain step by step how to build and deploy MicroPython on STM32F407xx and STM32F411CEU boards, using both DFU mode over USB, as well as SWD with ST-Link and OpenOCD in case you can't get the board into DFU mode (happened to me with the "black pill").

It should be applicable to other boards, such as the other "black pill" STM32F401, Nucleo boards etc., provided you can find an appropriate board definition to build.

1. clone the MicroPython repo:

@nebelgrau77
nebelgrau77 / UART_driver_problematic.md
Last active May 9, 2020 14:01
UART driver that bricked the boards while trying to debug with CubeIDE

main.c

#include "uart.h"

int main(void)
{
	USART2_Init();
	test_setup();
@nebelgrau77
nebelgrau77 / gist:33f080d7302b8ff0cef4db21468487d3
Last active April 10, 2020 21:03
magic 8-ball - getting the random values
As the code is intended for an STM32F0xx board, which requires the peripherals to be defined within the CS,
the idea was to have them globally accessible, wrapped in Mutex - RefCell containers.
This does not work for the Random Number Generator. Code:
static GRNG: Mutex<RefCell<Option<rand::rngs::small::SmallRng>>> = Mutex::new(RefCell::new(None));
gives an error "module 'small' is private".
Ideas go go around this and solve the whole problem: three separate timer interrups.
# this won't work, either:
# in flask_app:
from counter import counter_update, counter_display
@app.route('/counter/')
def counter():