Skip to content

Instantly share code, notes, and snippets.

Avatar

Rikka0_0小六花 rikka0w0

View GitHub Profile
@rikka0w0
rikka0w0 / config.c
Last active Mar 17, 2021
Reliable config data storage on the built-in flash of STM32. Tolerate to power loss and flash damage.
View config.c
/**
* Resource used:
* Flash, CRC
*/
/**
* A utility which reliably stores config data on the built-in flash of the MCU.
* Data integrity is guaranteed by CRC32. If a power loss happens during a flash
* write operation, upon next start-up, the last valid configuration will be used.
*/
@rikka0w0
rikka0w0 / crc.c
Created Mar 17, 2021
STM32F0 CRC32, supports unaligend memory as input.
View crc.c
/*
* Resource used:
* CRC32 peripheral
*/
#include "crc.h"
#include "stm32f0xx_ll_bus.h"
void crc32_init(void) {
@rikka0w0
rikka0w0 / STM32_Flash_User_Data.md
Created Mar 16, 2021
Change the linkerscript to allocate some space for storing non-volatile user data
View STM32_Flash_User_Data.md

Solution 1: User Data at the end of flash

Define constants before MEMORY section:

/* EEPROM emulator */
_Flash_Page_Size = 0x400;	/* Page size of the flash in bytes, see MCU datasheet */
_User_Config_Size = 0x400;	/* Size of the emulated EEPROM in bytes, must be multiples of _Flash_Page_Size */

Define the section for non-volatile user data:

  /* Flash reserved for the EEPROM emulation at the end of the Flash*/
@rikka0w0
rikka0w0 / Add_System_to_ThisPC_Win10_20H2.reg
Created Mar 15, 2021
Add an menu item for the legacy "System" control panel page in the context menu of ThisPC, run as TrustedInstaller, use NSudo
View Add_System_to_ThisPC_Win10_20H2.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\System]
"Icon"="imageres.dll,143"
[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\System\command]
@="explorer /same,shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}"
[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Manage]
"Icon"="imageres.dll,313"
@rikka0w0
rikka0w0 / openocd_stm32.zip
Last active Jan 31, 2021
Gdb+OpenOCD remote STM32 debugging
View openocd_stm32.zip
This file has been truncated, but you can view the full file.
@rikka0w0
rikka0w0 / debian-i386.sh
Created Jan 24, 2021
Install a Debian 10 i386 proot enviroment in Termux
View debian-i386.sh
#!/data/data/com.termux/files/usr/bin/bash
## --- README ---
## Download and run this script and wait....
## The key is to have qemu-i386-static in /data/data/com.termux/files/usr/bin/
## Reference: https://github.com/AllPlatform/Termux-UbuntuX86_64/blob/master/Ubuntu-i386.sh
pkg install proot -y
folder=debian-fs
if [ -d "$folder" ]; then
first=1
echo "skipping downloading"
@rikka0w0
rikka0w0 / intro.md
Last active Jan 17, 2021
A linux bash script which helps the developer to convert the address from core dump to meaningful filenames and line numbers
View intro.md

Usage

  1. Download xtensa-lx106-elf-backtrace and place it anywhere that is in the $PATH variable.
  2. cd to your project/build
  3. Run xtensa-lx106-elf-backtrace "xxxxxxx", xxxxxxx is the list of addresses shown in a core dump.

Example

Core dump:

Guru Meditation Error: Core  0 panic'ed (LoadStoreAlignment). Exception was unhandled.
Core 0 register dump:
@rikka0w0
rikka0w0 / revert.reg
Last active Dec 8, 2020
Add WSL root to Network folder in Win10
View revert.reg
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\CLSID\{90818ab5-0f00-487c-8570-a16feb94cd61}]
[-HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{90818ab5-0f00-487c-8570-a16feb94cd61}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\NetworkNeighborhood\NameSpace\{90818ab5-0f00-487c-8570-a16feb94cd61}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\NetworkNeighborhood\NameSpace\{90818ab5-0f00-487c-8570-a16feb94cd61}]
@rikka0w0
rikka0w0 / ipv6_fix_lan.md
Last active Sep 12, 2020
Fix the IPv6 ULA(LAN) address
View ipv6_fix_lan.md

Enable IPv6 DHCP client

  1. Edit /etc/network/interfaces, change or append: iface ??? inet6 dhcp where ??? is your interface name, e.g. eth0 or enp12s0, and then reboot.

Find your current DUID

The DUID is used by the router to assign ULA(LAN) ipv6 addresses to clients, similar to how ipv4 DHCP server assign ipv4 addresses based on MAC. To find out your current DUID, follow these steps:

  1. Run cat /var/lib/dhcp/dhclient6.???.leases | grep default-duid, replace ??? with the name of your network interface, e.g. eth0 or enp12s0.
  2. Copy the output from the previous command, remove the default-duid prefix and the tailing ;. Use the remaining string for the next command.
  3. Run printf "???" | hexdump -e '14/1 "%02x " "\n"' | sed 's/ /:/g', the output is your current DUID in human-readable form.

Set your DUID to a fixed or known value

@rikka0w0
rikka0w0 / stm32f030f4_config_store.c
Last active Aug 3, 2020
This snippet demonstrates how to change the initail value of a global variable in STM32
View stm32f030f4_config_store.c
#define FLASH_START_ADDR 0x08000000
#define FLASH_PAGE_SIZE 0x400 // stm32f0xx_hal_flash_ex.h may have defined this.
// Warning: Other stm32 device might have difference page size!!!
#define FLASH_PAGE_BUFCNT (FLASH_PAGE_SIZE / sizeof(uint32_t)) // Number of 32bit ints within the buffer
static uint32_t flash_page_buff[FLASH_PAGE_BUFCNT];
// config_addr is a pointer to a 32bit GLOBAL variable, val is the new initial value.
// This function does not change the current value of the variable.
// The initial value will be loaded to the target variable upon next reset.