CooCox IDE tutorials for beginners by Mark and Dave

CooCox – ARM Development Environment For the Beginner - Mark Stevens

http://blog.mark-stevens.co.uk/?p=862

... 

Debugging

An IDE is really nothing without a reasonable debugger. I remember from the work I did setting up Eclipse (see Setting up GCC for the STM32F4 Discovery Board) that Eclipse needed the OpenOCD library in order to be able to debug an application using ST-Link. There is no mention of OpenOCD when using CooCox. The only additional software required for debugging appears to be the ST-Link USB driver. Again, I already have this installed but you may need to visit ST’s web site for the latest version.

In order to debug we need some code so let’s borrow the code from the Simple GPIO example:

01. #include "stm32f4xx_rcc.h"
02. #include "stm32f4xx_gpio.h"
03.  
04. int main()
05. {
06. //
07. //  Initialise the peripheral clock.
08. //
09. RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;

10. //
11. //  Initialise the GPIO port.
12. //
13. GPIOD->MODER |= GPIO_Mode_OUT;
14. GPIOD->OSPEEDR |= GPIO_Speed_25MHz;
15. GPIOD->OTYPER |= GPIO_OType_PP;
16. GPIOD->PUPDR |= GPIO_PuPd_NOPULL;

17. //
18. //  Toggle Port D, pin 0 indefinitely.
19. //
20. while (1)
21. {
22. GPIOD->BSRRL = GPIO_Pin_0;
23. GPIOD->BSRRH = GPIO_Pin_0;
24. }
25. }

Pressing F5 runs the applicaiton to the next breakpoint. As I have not set any breakpoints this should run the application indefinitely and indeed it does. Hooking up the scope to pin 0 of port D shows the following output:

...

.END




Hello World tutorial for STM32 Discovery boards using CooCox CoIDE and GCC ARM - TechWithDave

http://techwithdave.blogspot.hk/2013/04/hello-world-tutorial-for-stm-discovery.html 

... 

Creating your first project.

...

#include <stdio.h>
#include <stm32f10x_gpio.h>
#include <stm32f10x_rcc.h>

int main(void)
{
 GPIO_InitTypeDef gpio;
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

 GPIO_StructInit(&gpio);
 gpio.GPIO_Pin = GPIO_Pin_9; // Green LED
 gpio.GPIO_Mode = GPIO_Mode_Out_PP;
 gpio.GPIO_Speed = GPIO_Speed_2MHz;
 GPIO_Init(GPIOC, &gpio);

 gpio.GPIO_Pin = GPIO_Pin_8; // Blue LED
 GPIO_Init(GPIOC, &gpio);

 printf("Hello World!\r\n");

 while(1)
 {
  static int count=0;
  static int i;
  static int led_state=0;

  for (i=0; i<1000000; ++i);

  GPIO_WriteBit(GPIOC, GPIO_Pin_9, led_state ? Bit_SET : Bit_RESET);
  led_state = !led_state;
  GPIO_WriteBit(GPIOC, GPIO_Pin_8, led_state ? Bit_SET : Bit_RESET);

  printf("%d\r\n", ++count);
 }
}

...

.END

No comments:

Post a Comment