Skip to content

Instantly share code, notes, and snippets.

View glegrain's full-sized avatar

Guillaume Legrain glegrain

View GitHub Profile
@glegrain
glegrain / mpu.c
Created November 6, 2020 07:59
STM32H7 MPU Configuration
/**
* @brief Configure the MPU attributes as Write Through for External SDRAM.
* @note The Base Address is 0xD0000000 .
* The Configured Region Size is 32MB because same as SDRAM size.
* @param None
* @retval None
*/
void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct;
@glegrain
glegrain / np_to_c.py
Created October 1, 2020 16:11
Numpy array to C file
import numpy as np
import subprocess
my_data = np.array([0, 0.1, 0.2, 0.3], dtype=np.float32)
np.array(my_data).tofile('my_data.bin')
subprocess.run(["xxd", "-i", "my_data.bin", "my_data.h"], capture_output=True)
@glegrain
glegrain / Makefile
Last active August 11, 2022 18:37
STM32 Makefile boilerplate
######################################
# target
######################################
TARGET = Project
######################################
# building variables
######################################
# debug build?
DEBUG = 1
@glegrain
glegrain / pfc_dma2d.c
Created August 4, 2020 09:20
DMA2D Pixel format conversion
/* Private variables -------------------------------------------------------- */
DMA2D_HandleTypeDef hdma2d;
/* Private function prototypes ---------------------------------------------- */
static void DMA2D_Init(void);
static void DMA2D_Convert(void);
void DMA2D_Init(void)
{
HAL_StatusTypeDef status;
@glegrain
glegrain / LogMelSpectrogram.py
Created April 19, 2019 14:03
Python LogMel feature extraction code
#!/usr/bin/env python
# coding: utf-8
# This software component is licensed by ST under BSD 3-Clause license,
# the "License"; You may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
# https://opensource.org/licenses/BSD-3-Clause
"""LogMel Feature Extraction example."""
@glegrain
glegrain / tutacousticscenes2016.py
Last active April 23, 2019 16:50
Python code to load the TUT Acoustic scenes 2016 dataset.
"""TUT Acoustic scenes 2016 dataset.
"""
import os
import sys
import numpy as np
import zipfile
import librosa
from tqdm import tqdm
from keras.utils.data_utils import get_file
@glegrain
glegrain / counter.c
Last active April 13, 2023 14:58
Cortex-M Cycle Counter counter
uint32_t cycles;
cycles = 0;
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
#ifdef STM32F7
DWT->LAR = 0xC5ACCE55;
#endif
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_4);
/**
* @brief Select the clock source to output on MCO pin(PA8).
* @note PA8 should be configured in alternate function mode.
* @param RCC_MCOx specifies the output direction for the clock source.
* For STM32L4xx family this parameter can have only one value:
* @arg @ref RCC_MCO1 Clock source to output on MCO1 pin(PA8).
* @param RCC_MCOSource specifies the clock source to output.
* This parameter can be one of the following values:
/*
* Jump to System Memory from User code
* NOTE: Code tested on STM32F107
*/
#define SYSTEM_MEMORY_ADDRESS 0x1FFFB000
uint32_t JumpAddress;
/* Disable all peripheral clocks */
RCC->APB1ENR = 0x0;
@glegrain
glegrain / uart.c
Last active March 26, 2024 23:29
STM32 printf retarget to UART
/*# 1- Identify the UART interface, GPIO pins and Alternate Function #########*/
/* For example:
* B-L475E-IOT01A:
* PB6 ------> USART1_TX
* PB7 ------> USART1_RX
*
* NUCLEO-L476RG:
* PA2 ------> USART2_TX
* PA3 ------> USART2_RX
*