Skip to content

Commit

Permalink
Almost there...
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKK committed Apr 14, 2014
1 parent 7eb2ffe commit cdf4be4
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 50 deletions.
66 changes: 59 additions & 7 deletions CORTEX_M4F_STM32F407ZG-SK/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @{
*/

/*extern uint32_t iii;*/
EXTI_InitTypeDef EXTI_InitStructure;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
Expand All @@ -44,15 +45,18 @@ EXTI_InitTypeDef EXTI_InitStructure;

void Init()
{
STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_GPIO );
/*STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_GPIO );*/
RCC_ClocksTypeDef RCC_Clocks;
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

/* Initialize LEDs mounted on EVAL board */
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);

/* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */
EXTILine0_Config();
/*USARTConfig();*/
}

void EXTILine0_Config(void)
Expand Down Expand Up @@ -84,17 +88,65 @@ void EXTILine0_Config(void)

/* Enable and set EXTI Line0 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0xFF;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0xFF;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

static void Task1( void* pvParameters )
void USART(void)
{
/* USART1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // USART1_TX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // USART1_RX

USART_InitTypeDef USART_InitStructure;

/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
* * - BaudRate = 9600 baud
* * - Word Length = 8 Bits
* * - One Stop Bit
* * - No parity
* * - Hardware flow control disabled (RTS and CTS signals)
* * - Receive and transmit enabled
* */
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);

}

void Task1( void* pvParameters )
{
uint32_t iii = 0;

while( 1 ){
STM_EVAL_LEDToggle( LED3 );
vTaskDelay( 500 );
while( STM_EVAL_PBGetState( BUTTON_USER ) ){
iii++;
itoa( iii, 10 );
}
itoa( 321, 10 );
}
}

Expand Down
3 changes: 3 additions & 0 deletions CORTEX_M4F_STM32F407ZG-SK/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
#include "FreeRTOS.h"
#include "task.h"

//uint32_t iii;
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */


#endif /* __MAIN_H */

Expand Down
120 changes: 77 additions & 43 deletions CORTEX_M4F_STM32F407ZG-SK/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,105 +51,139 @@
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/*void NMI_Handler(void)*/
/*{*/
/*}*/

/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/*void HardFault_Handler(void)*/
/*{*/
/*[> Go to infinite loop when Hard Fault exception occurs <]*/
/*while (1)*/
/*{*/
/*}*/
/*}*/

/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/*void MemManage_Handler(void)*/
/*{*/
/*[> Go to infinite loop when Memory Manage exception occurs <]*/
/*while (1)*/
/*{*/
/*}*/
/*}*/

/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/*void BusFault_Handler(void)*/
/*{*/
/*[> Go to infinite loop when Bus Fault exception occurs <]*/
/*while (1)*/
/*{*/
/*}*/
/*}*/

/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/*void UsageFault_Handler(void)*/
/*{*/
/*[> Go to infinite loop when Usage Fault exception occurs <]*/
/*while (1)*/
/*{*/
/*}*/
/*}*/

/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
void SVC_Handler(void)
{
}
/*void SVC_Handler(void)*/
/*{*/
/*}*/

/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/*void DebugMon_Handler(void)*/
/*{*/
/*}*/

/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
/*void PendSV_Handler(void)*/
/*{*/
/*}*/

/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
/*void SysTick_Handler(void)*/
/*{*/
/*STM_EVAL_LEDOn( LED4 );*/
/*}*/
/*extern uint32_t iii;*/

void USART1_puts(char* s)
{
while(*s) {
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, *s);
s++;
}
}

void itoa(uint32_t n, uint32_t base) {
volatile portCHAR buf[33] = {0};
volatile portCHAR *p = &buf[32];

if (n == 0)
*--p = '0';
else {
portCHAR *q;
volatile uint32_t num = n;

*--p = '\r';
*--p = '\n';

for (; num; num/=base)
*--p = "0123456789ABCDEF" [num % base];
}

USART1_puts( p );
}

void EXTI0_IRQHandler(void)
{
if( EXTI_GetITStatus( EXTI_Line0 ) != RESET ){

STM_EVAL_LEDToggl( LED4 );
while( 1 ){
STM_EVAL_LEDToggle( LED4 );
vTaskDelay( 500 );
itoa( 123, 10 );
}
}

EXTI_ClearITPendingBit( EXTI_Line0 );
}
/******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ OBJS += \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.o \
$(PWD)/Utilities/STM32F429I-Discovery/stm32f429i_discovery.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/stm32f4xx_it.o

CFLAGS += -DUSE_STDPERIPH_DRIVER
CFLAGS += -I $(PWD)/CORTEX_M4F_STM32F407ZG-SK \
Expand Down

0 comments on commit cdf4be4

Please sign in to comment.