ST Micro in C Code

Thread Starter

beatsal

Joined Jan 21, 2018
425
Presumably, I can only guess, you are looking at code generated by a code wizard for a RTOS.

If you are now learning how to program in C, this would not be my recommended line of approach.
Begin by programming simple constructs using a generic C platform.
There are C compilers that will run and execute directly on your PC.
I am torn between Keil and Cube that you are using. I had learnt a little about Keil so not sure if I should change. Of course, Keil costs and Cube is free. Any thoughts?
 

Thread Starter

beatsal

Joined Jan 21, 2018
425
Trying to use Keil for compiling my C program. As a start, I tried compiling the Blinky.c program done by Keil - no luck, although I didn't change anything, got 114 errors, tried another ex, same. So, something I am missing (as always!)
 

Thread Starter

beatsal

Joined Jan 21, 2018
425
Thanks. Not sure where they are. This was a canned program by Keil which I just opened and ran. Any help appreciated.
 

Thread Starter

beatsal

Joined Jan 21, 2018
425
C:
include <stdio.h>
#include "main.h"
#include "Board_LED.h" /* ::Board Support:LED */
#include "Board_Buttons.h" /* ::Board Support:Buttons */
#include "Board_ADC.h"                  /* ::Board Support:A/D Converter */
#include "RTE_Components.h"             /* Component selection */
#include "stm32g4xx_hal.h"              /* Keil::Device:STM32Cube HAL:Common */
// Main stack size must be multiple of 8 Bytes
#define APP_MAIN_STK_SZ (1024U)
uint64_t app_main_stk[APP_MAIN_STK_SZ / 8];
const osThreadAttr_t app_main_attr = {
.stack_mem = &app_main_stk[0],
.stack_size = sizeof(app_main_stk)
};
static volatile uint32_t delay_val = 500U;
static osThreadId_t tid_thrLED;                /* Thread id of thread: LED */
static osThreadId_t tid_thrBUT;                /* Thread id of thread: BUT */
/*----------------------------------------------------------------------------
thrLED: blink LED
*----------------------------------------------------------------------------*/
__NO_RETURN static void thrLED(void *argument) {
uint32_t led_max = LED_GetCount();
  uint32_t led_num    = 0U;
  (void)argument;
  for (;;) {
osThreadFlagsWait(0x0001U, osFlagsWaitAny ,osWaitForever);
LED_On(led_num); /* Turn specified LED on */
osThreadFlagsWait(0x0001U, osFlagsWaitAny ,osWaitForever);
    LED_Off(led_num);                                          /* Turn specified LED off */
    led_num++;                                                 /* Change LED number */
if (led_num >= led_max) {
led_num = 0U; /* Restart with first LED */
}
  }
}
/*----------------------------------------------------------------------------
thrBUT: check button state
*----------------------------------------------------------------------------*/
__NO_RETURN static void thrBUT(void *argument) {
  uint32_t button_msk = (1U << Buttons_GetCount()) - 1U;
  (void)argument;
  for (;;) {
osDelay(delay_val); /* Wait */
while (Buttons_GetState() & (button_msk)); /* Wait while holding USER button */
osThreadFlagsSet(tid_thrLED, 0x0001U);
  }
}
/*----------------------------------------------------------------------------
* Application main thread
*---------------------------------------------------------------------------*/
__NO_RETURN void app_main (void *argument) {
  (void)argument;
  LED_Initialize();                                         /* initalize LEDs */
  Buttons_Initialize();                                     /* initalize Buttons */
  tid_thrBUT = osThreadNew (thrBUT, NULL, NULL);            /* create BUT thread */
  if (tid_thrBUT == NULL) { /* add error handling */ }
  tid_thrLED = osThreadNew (thrLED, NULL, NULL);            /* create LED thread */
  if (tid_thrLED == NULL) { /* add error handling */ }
  for (;;) {}
Errors:

- Selected tool variant: mdk_pro
- Checkout feature: LIC0=TA...-.....-.....
- Feature version: 5.0201709
- Keil error code: 1
Product: MDK Professional 5.29
Component: ARM Compiler 5.06 update 6 (build 750)
Tool: ArmCC [4d3637]
".\Objects\Blinky.axf" - 114 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:21
}
 

MrChips

Joined Oct 2, 2009
34,817
I don't know if it is error in cut and paste into the AAC forum page, but first line is missing #.

#include <stdio.h>

Also possible inconsistent use of { }.

Indent your code so that you can easily recognize the control structures.
 
Top