cancel
Showing results for 
Search instead for 
Did you mean: 

What is assert_param and searching for normal C code int set-up?

robertwood9
Associate III
Posted on August 26, 2009 at 10:58

What is assert_param and searching for normal C code int set-up?

3 REPLIES 3
paulsmitton9
Associate II
Posted on May 17, 2011 at 13:21

Hi Rob!

assert_param is used to check that a parameter that is passed to a firmware library function is in the valid range of values. Each call to assert_param uses another macro that checks the parameter is in that range. If it is in range, then assert_param does nothing. If it is a bad value, then assert_failed is called with the filename and line number. assert_failed may be your own function to print the filename and line number out via a serial port for debugging.

e.g.

void TurnOnPort(int port) {

assert_param(IsAPort(Port))

Port = On;

}

would have:

#define IsAPort ((Port == Port1) || (Port == Port2))

About the NVIC, I tend to do it the lazy way and use the libraries, which i suspect is probably fine with literals (the compiler should optimize) and probably quite inneficient if called with anything that could change.

So, not sure I can help much, but I call NVIC_SetVectorTable, NVIC_PriorityGroupConfig and then NVIC_Init for each interrupt.

The registers are detailed in the CortexM3 manual from Arm.

Paul 🙂

robertwood9
Associate III
Posted on May 17, 2011 at 13:21

Folks,

Am trying to write some software for the STM32 for the first time. I'm trying to work out how to set-up interrupts. There is this assert_param macro seems to be called, but I just don't understand what it does.

Also, does anyone know of some C code for setting up this NVIC that doesn't use this style of using these supplied structures and lots of levels of macros? I've managed to set-up PWM, GPIOs etc without using the example code, but I just can't work out the interrupts at all.

I think what I want in more basic C code is this:

------------

/* Standard STM example stuff */

NVIC_InitTypeDef NVIC_InitStructure;

/* Configure one bit for preemption priority */

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

------------

In other words, for example, to set-up the PWM it was this style of code:

-------------

// Timer1 control register Bits 9/8 = clock dvisiion for dead-time and sampling clock

// Bit 7 = auto-reload preload enable

// Bit 6/5 = centre aligned selection mode for PWM. 11 = counts up and counts down and output changes on up and down count

// Bit 4 is up or down counter which is not important as we're doing up/down here

// Bit 3 one pulse mode. Set to zero so counter continually runs

// Bit 2 what updates can cause an update request

// Bit 1 update enable disable - disable = 1, set as this for the now

// Bit 0 Counter enable, well, let's enable it!

// 0b00 1110 0011

TIM1_CR1 = 0x0E3;

---

So, I am writing directly to registers like TIM1_CR1 rather than this big abstraction of setting up structures. I'd like to do this for the NVIC, but I can't make it out yet, hence trying to follow the example code which I find hard to follow.

Many thanks,

Rob

[ This message was edited by: robert.wood on 25-08-2009 22:21 ]

robertwood9
Associate III
Posted on May 17, 2011 at 13:21

Hi Paul,

Didn't know you were on here! :D

I sussed it, it's actually quite simple; all you need to do is set bit 27 in Irq_0_to_31_Set_Enable register. Goodness knows why it has to be done in such an arcane fashion as on the ST libraries!

I only stumbled across it by looking in the Cortex manual on the ARM website and then searching for the address of the relevant register in the header file.

Note to ST if you're interested: your datasheets are muddled and hard to follow. Why on earth you can't just have a complete datasheet for each derivative with all the information in like Atmel do, I don't understand. It's not like they're printed out and it's costing you lost of money!

Cheers,

Rob