[fixme] blink_flash example working. more initialization needed, use libstm32_discovery.

pull/20/head
Fabien Le Mentec 2011-10-23 08:23:38 -05:00
rodzic 81e4e8d157
commit d762080c1b
5 zmienionych plików z 168 dodań i 16 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1)
else ifeq ($(CONFIG_STM32F4_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m4 -DCONFIG_STM32F4_DISCOVERY=1
endif
CFLAGS+=-ffreestanding -nostdlib -nostdinc
CFLAGS+=-ffreestanding -nostdlib -nostdinc
# to run from SRAM
CFLAGS+=-Wl,-Ttext,0x20000000 -Wl,-e,0x20000000

Wyświetl plik

@ -4,9 +4,7 @@ BIN_IMAGE=blink.bin
CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
CFLAGS=-O2 -mlittle-endian -mthumb
CFLAGS=-g -O2 -mlittle-endian -mthumb
CFLAGS=-O3 -mlittle-endian -mthumb
ifeq ($(CONFIG_STM32L_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY=1
else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1)
@ -16,18 +14,24 @@ else ifeq ($(CONFIG_STM32F4_DISCOVERY), 1)
else
$(error "must specify CONFIG_ for board!")
endif
CFLAGS+=-ffreestanding -nostdlib -nostdinc
CFLAGS+=-ffreestanding -nostdlib -nostdinc
# to run from FLASH
CFLAGS+=-Wl,-T,stm32_flash.ld
# stm32l_discovery lib
CFLAGS+=-I../libstm32l_discovery/inc
CFLAGS+=-I../libstm32l_discovery/inc/base
CFLAGS+=-I../libstm32l_discovery/inc/core_support
CFLAGS+=-I../libstm32l_discovery/inc/device_support
all: $(BIN_IMAGE)
$(BIN_IMAGE): $(EXECUTABLE)
$(OBJCOPY) -O binary $^ $@
$(EXECUTABLE): main.c startup_stm32l1xx_md.s
$(CC) $(CFLAGS) $^ -o $@
$(EXECUTABLE): main.c system_stm32l1xx.c startup_stm32l1xx_md.s
$(CC) $(CFLAGS) $^ -o $@ -L../libstm32l_discovery/build -lstm32l_discovery
clean:
rm -rf $(EXECUTABLE)

Wyświetl plik

@ -0,0 +1,61 @@
/**
******************************************************************************
* @file discover_board.h
* @author Microcontroller Division
* @version V1.0.2
* @date September-2011
* @brief Input/Output defines
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DISCOVER_BOARD_H
#define __DISCOVER_BOARD_H
/* Includes ------------------------------------------------------------------*/
/* #include "stm32l1xx.h" */
#define bool _Bool
#define FALSE 0
#define TRUE !FALSE
/* MACROs for SET, RESET or TOGGLE Output port */
#define GPIO_HIGH(a,b) a->BSRRL = b
#define GPIO_LOW(a,b) a->BSRRH = b
#define GPIO_TOGGLE(a,b) a->ODR ^= b
#define USERBUTTON_GPIO_PORT GPIOA
#define USERBUTTON_GPIO_PIN GPIO_Pin_0
#define USERBUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
#define LD_GPIO_PORT GPIOB
#define LD_GREEN_GPIO_PIN GPIO_Pin_7
#define LD_BLUE_GPIO_PIN GPIO_Pin_6
#define LD_GPIO_PORT_CLK RCC_AHBPeriph_GPIOB
#define CTN_GPIO_PORT GPIOC
#define CTN_CNTEN_GPIO_PIN GPIO_Pin_13
#define CTN_GPIO_CLK RCC_AHBPeriph_GPIOC
#define WAKEUP_GPIO_PORT GPIOA
#define IDD_MEASURE_PORT GPIOA
#define IDD_MEASURE GPIO_Pin_4
#endif
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

Wyświetl plik

@ -1,6 +1,20 @@
/* missing type */
/* base headers */
#include "stdint.h"
typedef unsigned int uint32_t;
/* libstm32l_discovery headers */
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_adc.h"
#include "stm32l1xx_lcd.h"
#include "stm32l1xx_rcc.h"
#include "stm32l1xx_rtc.h"
#include "stm32l1xx_exti.h"
#include "stm32l1xx_pwr.h"
#include "stm32l1xx_flash.h"
#include "stm32l1xx_syscfg.h"
#include "stm32l1xx_dbgmcu.h"
/* board specific macros */
#include "discover_board.h"
/* hardware configuration */
@ -31,7 +45,6 @@ static inline void switch_leds_off(void)
#elif CONFIG_STM32L_DISCOVERY
# define GPIOB 0x40020400 /* port B */
# define GPIOB_MODER (GPIOB + 0x00) /* port mode register */
# define GPIOB_ODR (GPIOB + 0x14) /* port output data register */
@ -46,12 +59,14 @@ static inline void setup_leds(void)
static inline void switch_leds_on(void)
{
*(volatile uint32_t*)GPIOB_ODR = LED_BLUE | LED_GREEN;
GPIO_HIGH(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
GPIO_HIGH(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
}
static inline void switch_leds_off(void)
{
*(volatile uint32_t*)GPIOB_ODR = 0;
GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
}
#endif /* otherwise, error */
@ -59,14 +74,87 @@ static inline void switch_leds_off(void)
#define delay() \
do { \
register unsigned int i; \
volatile unsigned int i; \
for (i = 0; i < 1000000; ++i) \
__asm__ __volatile__ ("nop\n\t":::"memory"); \
} while (0)
static void RCC_Configuration(void)
{
/* Enable HSI Clock */
RCC_HSICmd(ENABLE);
/*!< Wait till HSI is ready */
while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
{}
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
RCC_MSIRangeConfig(RCC_MSIRange_6);
RCC_HSEConfig(RCC_HSE_OFF);
if(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET )
{
while(1);
}
}
static void RTC_Configuration(void)
{
/* Allow access to the RTC */
PWR_RTCAccessCmd(ENABLE);
/* Reset Backup Domain */
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
/* LSE Enable */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
RCC_RTCCLKCmd(ENABLE);
/* LCD Clock Source Selection */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
}
void main(void)
{
setup_leds();
static RCC_ClocksTypeDef RCC_Clocks;
static GPIO_InitTypeDef GPIO_InitStructure;
/* Configure Clocks for Application need */
RCC_Configuration();
/* Configure RTC Clocks */
RTC_Configuration();
/* Set internal voltage regulator to 1.8V */
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
/* Wait Until the Voltage Regulator is ready */
while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
/* configure gpios */
/* Enable GPIOs clock */
RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK, ENABLE);
/* Configure the GPIO_LED pins LD3 & LD4*/
GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure);
GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
while (1)
{

Wyświetl plik

@ -62,7 +62,6 @@ defined in linker script */
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
@ -92,7 +91,7 @@ LoopFillZerobss:
bcc FillZerobss
/* Call the clock system intitialization function.*/
/* let main do the system initialization */
/* bl SystemInit */
bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr