cancel
Showing results for 
Search instead for 
Did you mean: 

Keil µVision5 - STM32F334R8 - Miising the appropriate header files

antoine
Associate II
Posted on June 17, 2016 at 17:13

Hi,

I'm starting to use Keil for my STM32 F334R8, and I recently downloaded the standard libraries package which provides examples, which is nice.

The only more or less good tutorial I could find on starting developing on Keil using std lib was

http://www.emcu.it/STM32/Usare_le_librerie_310.pdf

(in italian, that I don't speak). Following it (despite many differences between what I had and what I should have according to it), I managed to compile and run the GPIO example on my board. I mean, I didn't get any error, but in the end I don't have anything showing on the oscillo.

There is also this one: 

https://www.keil.com/product/brochures/uv4.pdf

But I find it absolutely useless for my purpose.

I tried to do the same with the DAC example, since this what I want, but here the example uses specific/basic/standard (whatever the name) libraries of the MCU, like 

stm32303c_eval.h

I'm losing my mind on this. I don't think I'm asking too much, but.... I'm completely stuck.

I just want something like

stm32f334.h

, you get the idea.

I can't read anything from my output, i can't even blink a LED (I probably suck for this one, I know that).

My original objective was to output a sinewave from the DAC, but at this point, I'll take anything.

Please help me, I'm going crazy.
5 REPLIES 5
Posted on June 17, 2016 at 19:12

The relevant Standard Library is at https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32108.license=1466182509783.html , scroll to very bottom, click at ''download'' in blue rectangle. You may be required to accept a lengthy disclaimer and log in, the login/password you have here works.

The ''main'' header is [STM32F30x_DSP_StdPeriph_Lib]\Libraries\CMSIS\Device\ST\STM32F30x\Include\stm32f30x.h

JW

Posted on June 17, 2016 at 19:12

Ok, so what board is this? I'm guessing it is a NUCLEO-F334R8, but it helps to be specific, as the pins and the functionality tend to be board specific.

The F3 DSP library should be fine for the F334 part, you'd include ''stm32f30x.h'' and set the compiler's command line defines, in the project options, to set STM32F334x8

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32108.html#

You have code that compiles, and downloads, so show the code as it is, explain which pins it is using, and what you expect it to do, and we can look at that as a starting point.

Consider also if what you are looking for is education/training, and what local schools/colleges, or microprocessor training, opportunities are available.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 17, 2016 at 19:17

You can have fun with LED blinking without writing a single line of program, too, if you have a debugger which can manipulate the registers (Keil should be able to, I don't use it, neither I use an 'F3 but this should be the sam). Enable the relevant GPIO clock in RCC_AHBENR, set the appropriate pin to output in GPIOx_MODER and then toggle the appropriate bit in GPIOx_ODR.

JW

antoine
Associate II
Posted on June 20, 2016 at 13:10

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6kF&d=%2Fa%2F0X0000000buS%2F7QqUWsP60pYxeRimyLem6hddGiyidaItwgycJrbx6Mc&asPdf=false
antoine
Associate II
Posted on June 20, 2016 at 18:40

Ok so, I cleaned the code as much as I could, and I modified it as it shouldwork in my opinion (a manner to say I'm not completely lost anymore, just almost completely lost).

Here is the whole main.c I used [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/sawtooth&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=97]this example about a sawtooth signal to compare and improve the code.


#include ''main.h''


/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

#define DAC_DHR12R1_ADDRESS 0x40007414 //DAC_DHR12R2_ADDRESS originally



/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

DAC_InitTypeDef DAC_InitStructure;

DMA_InitTypeDef DMA_InitStructure;

const
uint16_t Sine12bit[32] = {

2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056,

3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, 

599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 

1263, 1647}; 


uint8_t Idx = 0; 
// Not sure what is it



/* Private function prototypes -----------------------------------------------*/

static
void
DAC_Config(
void
);

static
void
TIM_Config(
void
);

/* Private functions ---------------------------------------------------------*/



int
main(
void
)

{


/* Preconfiguration before using DAC----------------------------------------*/

DAC_Config();


/* TIM6 configuration to trigger DAC */

TIM_Config();



/* Infinite loop */

while
(1)

{

/* Sine Wave generator ---------------------------------------------*/


/* DAC channel1 Configuration */

DAC_DeInit(DAC1); 

DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;

DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Disable;


/* DAC Channel1 Init */

DAC_Init(DAC1, DAC_Channel_1, &DAC_InitStructure);


/* Enable DAC Channel1 */

DAC_Cmd(DAC1, DAC_Channel_1, ENABLE);


/*DAC_SetChannel1Data(DAC1, DAC_Align_12b_R, 0x7FF0); */
//This line is a test, taken from later in the main(), for triangle signal


/* DMA1 channel3 configuration */

DMA_DeInit(DMA1_Channel3);

DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_ADDRESS;

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sine12bit;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

DMA_InitStructure.DMA_BufferSize = 32;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; 
// _HalfWord in the original code

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; 
// _HalfWord in the original code

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel3, &DMA_InitStructure);


/* Enable DMA1 Channel3 */

DMA_Cmd(DMA1_Channel3, ENABLE);


/* Enable DMA for DAC Channel1 */

DAC_DMACmd(DAC1, DAC_Channel_1, ENABLE);

}

}


/**

* @brief TIM6 configuration to trigger DAC conversion 

*/

static
void
TIM_Config(
void
)

{

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

int
Period;


Period = ((SystemCoreClock / 2) / 200000); 
// 200 KHz timebase, 6.25 KHz Sine


/* TIM6 Periph clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);


/* Time base configuration */

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); 

TIM_TimeBaseStructure.TIM_Period = Period - 1; 
//0xFF; 

TIM_TimeBaseStructure.TIM_Prescaler = 0x0; 

TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; 

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 

TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);


/* TIM6 TRGO selection */

TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);


/* TIM6 enable counter */

TIM_Cmd(TIM6, ENABLE);

}


/**

* @brief DAC channels configurations (PA4 and PA5 in analog,

* enable DAC clock, enable DMA1 clock)

*/

static
void
DAC_Config(
void
)

{

GPIO_InitTypeDef GPIO_InitStructure;


/* DMA1 clock enable (to be used with DAC) */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);


/* DAC Periph clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);


/* GPIOA clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);


/* Configure PA.04 (DAC_OUT1) as analog */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

The other files (headers and .c) remain untouched. Hope this can clarify things for you. Thank you for your help.