C language

When it comes to Embedded Electronics just ask Agent Smith about C ...

_images/matrix-plague-scene-sml.jpg

One of the big advantages touted for C is “Information hiding”, claimed to be a powerful programming technique because it reduces complexity.

Unfortunately this means C code examples are all but useless for a Forth programmer, because we need all the information.

  • Even STM use The C Language To explain how their hardware works !!

Note

I’m only a C hater on Embedded, I like C and use it on my PC.

example

https://community.st.com/s/question/0D50X00009XkgyKSAR/stm32f0-sleep-mode “My following program blinks the LED using systick timer,while after ten times blink the LED the MCU should goes to sleep mode”

Sleep mode is trivial, but I’m mystified where the WFI command is hiding in this C code.

#include 'stm32f0xx.h'
#include 'stm32f0xx_tim.h'
#include <stm32f0xx_rcc.h>
volatile uint32_t msTicks;

void gpio_init(){

 GPIO_InitTypeDef GPIO_InitStructure;
 RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOA,ENABLE);
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8 ;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOC, &GPIO_InitStructure);

}

void blink_LED(){
 if (msTicks == 1000){GPIOC->ODR ^= GPIO_Pin_8; msTicks = 0;}

}

void SysTick_Handler (void) {
 msTicks++; // Increment counter
}
int main(){
 SysTick_Config (SystemCoreClock/1000); // Configure the SYSTICK
 gpio_init();
 while(1){blink_LED();}


}

As a Forth user living in a C World, even the title of the example annoys me. It’s not a program it’s a C program.

To learn about STM32F0 Low Power Modes from this ‘example C program’ I need all the source, which is not provided or linked, for the files listed below :-

  • stm32f0xx.h
  • stm32f0xx_tim.h
  • the full details of various _InitStructure

These kind of issues mean it’s rarely worth my time decoding a C “example”, tracking down the header details etc. It’s faster to go directly to the STM datasheets and programming reference manuals and just experiment in real time on the hardware itself.

Note

As an aside, I often observe that online C “examples” are just copy and paste of someone elses example code, complete with the same errors. I believe that the C Programming Language is so popular in Embedded because thousands of free libraries promise to do what the programmer wants whilst alleviating the need to actually understand the process.

</rant>

Table Of Contents

Previous topic

Bugs

Next topic

Charles (Chuck) Moore the inventor of Forth

This Page