Skip to main content

Posts

Showing posts with the label stm32

FreeRTOS + newlib (gcc toolchain) on the STM32F103 (Cortex-M3)

Here are some of the steps to get FreeRTOS and newlib (gcc) to work correctly on the STM32F10x, a Cortex-M3 ARM processor. Configure the priority bits Per  the FreeRTOS page about the Cortex M3 and M4 , the priority bits should be assigned to be preempt priority by calling NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );  If you or any start up related code you are using isn't doing this you may end up with odd behavior or bus faults. Map FreeRTOS tasking functions to CMSIS vector handlers Per this post  you'll want to map the FreeRTOS handlers for vPortSVCHandler, xPortPendSVHandler and xPortSysTickHandler to the CMSIS handlers. A readelf of the elf file of my example application was showing the default interrupt handler was being used for those interrupts, which meant FreeRTOS wasn't handling the interrupts it needed to function correctly. The CMSIS default handlers are weakly bound so having other definitions with the same names will override these, causing th...

STMicro STM32F10x CMSIS-SVD files appear to be missing lots of important registers

CMSIS-SVD is "Cortex Microcontroller Software Interface Standard" "System View Description". This is an ARM standard format for describing the registers and their bitfields for the Cortex-M series of ARM processors. If you have an account on the Arm website you can visit the STMicro cmsis page  where you can download the svd files for various STMicro processors. The STM32F10x svd files however appear to be missing important things like the system control block . This is an issue because I've been using the Eclipse plugin EmbSysRegView  to browse cpu registers during debug. The system control block is important because it contains various status registers that report fault status. These registers can help to locate issues in code or configuration. I posted a support question with ST and on their forums to see why their CMSIS-SVD doesn't appear to include all of the processors registers but I'll probably end up modifying the other EmbSysRegView proc...

Cortex-M3 exceptions with ARM code

A test application using FreeRTOS and an arm cross compiler was landing in the default exception handler during the start up code in main(). Because several of the exception handlers are still using the default exception handler the debugger indicates WWDG_IRQHandler. Some googling turned up this post  but while mapping the FreeRTOS handlers with #defines did correct something I had missed it wasn't the cause of the exceptions. Single stepping through the code narrowed the issue down to a call to malloc(), in at a label called _malloc_from_thumb(). The particular instruction was "bx pc". When the 'bx pc' was executed the processor jumped directly to the watchdog isr handler. Next I ran 'objdump -d -S -l' on the elf file and started looking at the code and assembly. main() looks like: _malloc_from_thumb(): looks like: You can see that this function has a couple of 16 bit thumb instructions and then a 32 bit arm instruction. Its purpose, a...

Watch out for an out-of-date STM32 Standard Peripheral library

ST has newer versions of the STM32 standard peripheral library that aren't being released. If you search on the website you'll find v3.5.0, dated as released 11-March-2011. But, if you download the STM32 USB-FS_Device driver package you can see that this includes a much newer STM32 standard peripheral library, v3.6.1 dated 05-March-2012. There are some quite important fixes between v3.5.0 and v3.6.1: V3.6.1 / 05-March-2012 Main Changes All source files: license disclaimer text update and add link to the License file on ST Internet. V3.6.0 / 27-January-2012 Main Changes All source files: update disclaimer to add reference to the new license agreement stm32f10x_sdio.c SDIO_SetPowerState() function: fix POWER register configuration, only one access (for read or write) is allowed stm32f10x_usart.h/.c Update procedure to check on overrun error interrupt pending bit, defines for the following flag are added: USART_IT_ORE_RX: this flag is set if overrun err...

Building an ARM toolchain on Kubuntu 13.04

I've been a big fan of crosstool-ng ever since I found out that Dan Kegal's crosstool scripts  idea was being continued. I picked up one of these boards, an Olimex STM32-H103 , because I'm putting together a custom PCB with an STM32F103 on it and didn't want to be bringing up the toolchain at the same time as debugging the hardware. Starting with this board means starting with a known working STM32F103 board. Steps - Install 'gcc-multilib' package. If you don't have this you'll get some odd errors when building the toolchain such as: [INFO ] ================================================================= [INFO ] Installing binutils for host [INFO ] Installing binutils for host: done in 142.17s (at 11:46) [INFO ] ================================================================= [INFO ] Installing pass-1 core C compiler [ERROR] checking dynamic linker characteristics... checking whether getchar_unlocked is declared... configure: er...