Skip to content

Instantly share code, notes, and snippets.


Rikka0_0小六花 rikka0w0

View GitHub Profile
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 / 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 /
Created Mar 16, 2021
Change the linkerscript to allocate some space for storing non-volatile user data

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 / 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
@="explorer /same,shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}"
rikka0w0 /
Last active Jan 31, 2021
Gdb+OpenOCD remote STM32 debugging
This file has been truncated, but you can view the full file.
rikka0w0 /
Created Jan 24, 2021
Install a Debian 10 i386 proot enviroment in Termux
## --- 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:
pkg install proot -y
if [ -d "$folder" ]; then
echo "skipping downloading"
rikka0w0 /
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


  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.


Core dump:

Guru Meditation Error: Core  0 panic'ed (LoadStoreAlignment). Exception was unhandled.
Core 0 register dump:
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
rikka0w0 /
Last active Sep 12, 2020
Fix the IPv6 ULA(LAN) address

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 / 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.