Monthly Archives: February 2019

ChibiOS STM32 with HAL

Datasheet

STM32F072RB, 128 Kbytes Flash, 48 MHz CPU, USB, CAN and CEC functions
STM32F072CB, 128 Kbytes Flash, 48 MHz CPU, USB, CAN and CEC functions
NUCLEO-F072RB

Tutorials

ChibiOS and STM32
From 0 to STM32
Dealing with push-buttons using an STM32
Dealing with LEDs using an STM32
Using STM32 GPIO with ChibiOS PAL Driver
Using STM32 USART with ChibiOS Serial Driver
PWM in hardware with STM32 Timer and ChibiOS
Using STM32 SPI with ChibiOS

Product

ChibiOS/HAL
The OSAL
HAL Features

  • SDC, abstraction of an SDIO interface to SD/MMC cards. Implements a block interface
  • MMC/SD over SPI, MMC and SD cards handling on top of the SPI driver. Implements a block interface.

Articles

Articles Start
ChibiOS/HAL Integration Guide

Documentation

Documentation

HAL 6.1.0

ChibiOS/HAL Introduction
Abstract I/O Block Device
Generic SD Card Driver, sdcStart()
Serial Driver, sdStart()

RT 5.1.0

ChibiOS/RT Introduction

Forum

SD-Card Insert/Remove Handlers
TM-Subsystem / SD-Card / STM32F0 / unknown type name ‘halrtc
eMMC not working with STM32F4
micro SD slots with no card detect signal
The FatFS topic
difference between UART and Serial driver

github

github.com/jed-frey/ARMCM4-STM32F407-STF4BB-FATFS, ChibiOS FatFS example for DM-STF4BB with STM32F4Discovery
github.com/ChibiOS/ChibiOS/tree/master/demos/STM32/RT-STM32F103-OLIMEX_STM32_P103-FATFS
github.com/ChibiOS/ChibiOS/blob/master/os/rt/include/ch.h
github.com/ChibiOS/ChibiOS/tree/master/os/various/fatfs_bindings

Compilation

arm-atollic-eabi-gcc
-c ..\src\chibi\platform\gpt_lld.c
-mthumb
-mcpu=cortex-m0
-std=gnu11
-DCRT1_AREAS_NUMBER=1
-DARM_MATH_CM0
-DSTM32F072B_DISCO
-DSTM32F072RBTx
-DSTM32F0
-DSTM32
-DDEBUG
-DHAL_USE_USB=TRUE
-DHAL_USE_SPI=TRUE
-DHAL_USE_SERIAL=TRUE
-DHAL_USE_ADC=TRUE
-DHAL_USE_UART=FALSE
-DHAL_USE_GPT=TRUE
-DSTM32_GPT_USE_TIM14=TRUE
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\board
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\hal
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\osal
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\platform
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\startup\CMSIS
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\startup\ST
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\startup
-IC:\msys64\home\bachman0\Fluoedema\Firmware\src
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\various
-IC:\msys64\home\bachman0\Fluoedema\Firmware\inc\chibi\lib
-Og
-ffunction-sections
-g3
-fstack-usage
-Wall
-fmessage-length=0
-specs=nano.specs
-o src\chibi\platform\gpt_lld.o 
arm-atollic-eabi-gcc
-o chibi_hal_debug.elf
src\cdc.o
src\cfg.o
src\chibi\board\board.o
src\chibi\hal\adc.o
src\chibi\hal\can.o
src\chibi\hal\dac.o
src\chibi\hal\ext.o
src\chibi\hal\gpt.o
src\chibi\hal\hal.o
src\chibi\hal\hal_buffers.o
src\chibi\hal\hal_mmcsd.o
src\chibi\hal\hal_queues.o
src\chibi\hal\i2c.o
src\chibi\hal\i2s.o
src\chibi\hal\icu.o
src\chibi\hal\mac.o
src\chibi\hal\mmc_spi.o
src\chibi\hal\pal.o
src\chibi\hal\pwm.o
src\chibi\hal\rtc.o
src\chibi\hal\sdc.o
src\chibi\hal\serial.o
src\chibi\hal\serial_usb.o
src\chibi\hal\spi.o
src\chibi\hal\st.o
src\chibi\hal\uart.o
src\chibi\hal\usb.o
src\chibi\hal\wdg.o
src\chibi\lib\chprintf.o
src\chibi\lib\memstreams.o
src\chibi\lib\nullstreams.o
src\chibi\osal\osal.o
src\chibi\platform\adc_lld.o
src\chibi\platform\can_lld.o
src\chibi\platform\dac_lld.o
src\chibi\platform\ext_lld.o
src\chibi\platform\ext_lld_isr.o
src\chibi\platform\gpt_lld.o
src\chibi\platform\hal_lld.o
src\chibi\platform\i2c_lld.o
src\chibi\platform\i2s_lld.o
src\chibi\platform\icu_lld.o
src\chibi\platform\nvic.o
src\chibi\platform\pal_lld.o
src\chibi\platform\pwm_lld.o
src\chibi\platform\rtc_lld.o
src\chibi\platform\serial_lld.o
src\chibi\platform\spi_lld.o
src\chibi\platform\st_lld.o
src\chibi\platform\stm32_dma.o
src\chibi\platform\uart_lld.o
src\chibi\platform\usb_lld.o
src\chibi\platform\wdg_lld.o
src\chibi\startup\crt1.o
src\chibi\startup\vectors.o
src\cmd.o
src\debug.o
src\eeprom\eeprom.o
src\eeprom\stm32f0xx_flash.o
src\iad.o
src\ifc.o
src\lym.o
src\main.o
src\que.o
src\ssd\cmds.o
src\ssd\com.o
src\ssd\ssd.o
src\ssd\util.o
src\ugui\ugui.o
src\usbcfg.o
src\vis.o
startup\crt0_v6m.o
startup\sysmem.o
-larm_cortexM0l_math
-lm
-mthumb
-mcpu=cortex-m0
-TC:\msys64\home\bachman0\Fluoedema\Firmware\LinkerScript.ld
-specs=nosys.specs
-static
-LC:\msys64\home\bachman0\Fluoedema\Firmware\bin
-Wl,--defsym=__process_stack_size__=0x000,--defsym=__main_stack_size__=0x800
-u _printf_float
-Wl,-Map=chibi_hal_debug.map
-Wl,--gc-sections
-Wl,--defsym=malloc_getpagesize_P=0x80
-Wl,--start-group -lc -lm -Wl,--end-group
-specs=nano.specs 

STM32F072: Linking in SES and Atollic IDE

STM32F072CB, Mainstream ARM Cortex-M0 USB line MCU with 128 Kbytes Flash, 48 MHz CPU, USB, CAN and CEC functions

Specs

HOWTO Use the GCC specs file
How to set gcc 4.3 default specs file?
Frequently Asked Questions

Studio

Using External GCC
Building with a SEGGER Embedded Studio project file

Wiki

How to use an external toolchain with Embedded Studio

Website

Tool chain and Compiler
Project Management
Performance
SEGGER Linker

Blog

The SEGGER Linker – Replacing the GNU linker
Killer features of the SEGGER linker, or what’s wrong with the GNU linker?

A C Library for embedded applications

Most GCC based projects use Newlib or its smaller version Newlib nano as the standard C Library. Newlib has been created for full-featured computers with lots of memory. Even Newlib nano might require a lot of stack and even heap for functions, such as printf.

Embedded Studio comes with its own standard C Library. The library has been created from scratch, tailored and optimized for embedded applications, to be used on even the smallest micros.

cd C:\msys64\home\bachman0\Fluoedema\Firmware
"C:\Program Files\SEGGER\SEGGER Embedded Studio for ARM 4.12\bin\emBuild.exe" -echo -config "Debug" Fluoedema.emProject
"C:\Program Files\SEGGER\SEGGER Embedded Studio for ARM 4.12\bin\emBuild.exe" -echo -clean -config "Debug" Fluoedema.emProject
4>C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.12/gcc/arm-none-eabi/bin/cc1
-fmessage-length=0
-fno-diagnostics-show-caret
-mcpu=cortex-m0
-mlittle-endian
-mfloat-abi=soft
-mthumb
-mtp=soft
-mno-unaligned-access
-nostdinc
-isystemC:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.12/include
-isystemC:/Users/bachman0/AppData/Local/SEGGER/SEGGER Embedded Studio/v3/packages/include
-IC:/msys64/home/bachman0/Fluoedema/Firmware/src
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/board
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/hal
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/osal
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/platform
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/startup/CMSIS
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/startup/ST
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/startup
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/various
-IC:/msys64/home/bachman0/Fluoedema/Firmware/inc/chibi/lib
-D__SIZEOF_WCHAR_T=4
-D__ARM_ARCH_6M__
-D__SES_ARM
-D__SES_VERSION=41200
-DDEBUG -DCRT1_AREAS_NUMBER=1
-DSTM32F072B_DISCO
-DSTM32F072RBTx
-DSTM32F0
-DSTM32
-DDEBUG
-DHAL_USE_USB=TRUE
-DHAL_USE_SPI=TRUE
-DHAL_USE_SERIAL=TRUE
-DHAL_USE_ADC=TRUE
-DHAL_USE_UART=FALSE
-DHAL_USE_GPT=TRUE
-DSTM32_GPT_USE_TIM14=TRUE
-DHAL_USE_WDG=TRUE
-DSTM32_WDG_USE_IWDG=TRUE
-MD C:/msys64/home/bachman0/Fluoedema/Firmware/Debug/sen.d
-MQ Debug/sen.o
-quiet
-std=gnu99
-g3
-gpubnames
-Og
-fomit-frame-pointer
-fno-dwarf2-cfi-asm
-fno-builtin
-ffunction-sections
-fdata-sections
-fshort-enums
-fno-common
C:\msys64\home\bachman0\Fluoedema\Firmware\src\sen.c
-o C:/msys64/home/bachman0/Fluoedema/Firmware/Debug/sen.asm

4>C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.12/gcc/arm-none-eabi/bin/as
--traditional-format
-mcpu=cortex-m0
-mlittle-endian
-mfloat-abi=soft
-mthumb
C:/msys64/home/bachman0/Fluoedema/Firmware/Debug/sen.asm
-o Debug/sen.o
undefined reference to __aeabi_read_tp
C:\msys64\home\bachman0\Fluoedema\Firmware>
"C:\Program Files\SEGGER\SEGGER Embedded Studio for ARM 4.12\bin\emBuild.exe" -echo -config "Debug" Fluoedema.emProject

1>C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.12/gcc/arm-none-eabi/bin/ld
-X
--omagic
-eReset_Handler
--defsym=__vfprintf=__vfprintf_int_nwp
--defsym=__vfscanf=__vfscanf_int
-EL
--gc-sections
-TC:/msys64/home/bachman0/Fluoedema/Firmware/LinkerScript.ld
-Map Output/Debug/Exe/Firmware.map
--defsym=__main_stack_size__=0x600
--defsym=__process_stack_size__=0x000
-u_vectors
-o Output/Debug/Exe/Firmware.elf
--emit-relocs
--start-group
@C:/msys64/home/bachman0/Fluoedema/Firmware/Output/Firmware Debug/Obj/Firmware.ind
--end-group

C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.12/lib/libc_v6m_t_le_eabi.a(libc2.o):
In function `__aeabi_errno_addr':
libc2.c:(.text.libc.__aeabi_errno_addr+0x2): undefined reference to `__aeabi_read_tp'
There were 1 build errors

cc1

Relationship between cc1 and gcc?
GNU C Compiler Internals/GNU C Compiler Architecture

cc1 -o test.s test.c
from C to ASM!

EABI

github.com/m-labs/uclibc-lm32/blob/master/libc/sysdeps/linux/arm/aeabi_errno_addr.c

_AEABI_PORTABILITY_LEVEL=1

How to use errno in multithread environment?
__aeabi_errno_addr()
caddr_t

syscalls

syscalls.c compilation errors
IMPLEMENTING SYSCALLS FOR LIBC
How to include syscalls.c from a separate library file?

newlib

Getting NewLib and printf to work with the STM32 and Code Sourcery Lite eabi
Using Newlib in ARM bare metal programs
Issue with compling ARM assembly code

arm-none-eabi-as p1.s -o p1.o
arm-none-eabi-gcc -specs=rdimon.specs p1.o -o p1
arm-none-eabi-gcc: error: rdimon.specs: No such file or directory

Linking issues

  GROUP (
"libcr_semihost_nf.a"
"libcr_c.a"
"libcr_eabihelpers.a"
)

-specs=rdimon.specs

Link problem with rdimon.specs
Linker error on a C project using Eclipse

Semihosting

What is semihosting?
What is semihosting?
What is Semihosting?
Semihosting für ARM verwenden

Specs to Linker?

How to pass specs to gcc linker?

ld or gcc

gcc -Wl,linker-option
Options for Linking

ARM Simulator

(gdb) target sim
Undefined target command: "sim".  Try "help target".

./configure --enable-sim

arm-none-eabi-gdb: Undefined target command: “sim”
Guide to using GDB in simulation mode
Does arm-none-eabi-gdb support simulator

STM32 FatFs / SPIFFS

FatFs

FatFs – Generic FAT Filesystem Module
FAT filesystem on SD card
STM32 and SD card (FATFS and SPI)

STM32F10x

STSW-STM32054 – STM32F10x standard peripheral library
STM32F10x_StdPeriph_Lib_V3.4.0 » Utilities » STM32_EVAL » Common » stm32_eval_sdio_sd.h
SD_CardInfo Struct Reference
SD Card Interface with STM32F0

STM32Cube_FW_F0_V1.9.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

SPIFFS

github.com/pellepl/stm32_spiffs, STM32 target playground for spiffs
github.com/pellepl/spiffs, Wear-leveled SPI flash file system for embedded devices
github.com/jrsharp/spiffs, Wear-leveled SPI flash file system for embedded devices

nRF5 SDK: UART

Understand UART, UARTE and getting it to work with PPI

UART — Universal asynchronous receiver/transmitter
UARTE — Universal asynchronous receiver/transmitter with EasyDMA
Peripheral drivers – UART
Peripheral drivers – UARTE
UART Driver
UART module
Serial port library

nrfx_err_t nrfx_uart_init(nrfx_uart_t const *        p_instance,
                          nrfx_uart_config_t const * p_config,
                          nrfx_uart_event_handler_t  event_handler)
{
    [...]
    apply_config(p_instance, p_config);
    [...]
}

static void apply_config(nrfx_uart_t        const * p_instance,
                         nrfx_uart_config_t const * p_config)
{
    [...]
    /* TXD */
    nrf_gpio_pin_set(p_config->pseltxd);
    nrf_gpio_cfg_output(p_config->pseltxd);
    
    /* RXD */
    nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);

    nrf_uart_baudrate_set(p_instance->p_reg, p_config->baudrate);
    nrf_uart_configure(p_instance->p_reg, p_config->parity, p_config->hwfc);
    nrf_uart_txrx_pins_set(p_instance->p_reg, p_config->pseltxd, p_config->pselrxd);
    [...]
}
void nrf_uart_txrx_pins_set(
    NRF_UART_Type  *p_reg,
    uint32_t        pseltxd,
    uint32_t        pselrxd
) {
    p_reg->PSELRXD = pselrxd;
    p_reg->PSELTXD = pseltxd;
}