unify the "systems" functionality. Also, make the embeddedlinux tool more versatile.
This commit is contained in:
parent
f1a75267fb
commit
ca4c90b1a8
7 changed files with 224 additions and 75 deletions
|
@ -1,8 +1,15 @@
|
|||
#include <stdint.h>
|
||||
#include "systems.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifdef STM32F30X
|
||||
#include <stm32f30x.h>
|
||||
#include <stm32f30x_rcc.h>
|
||||
#include <stm32f30x_gpio.h>
|
||||
#elif defined( STM32F40_41xxx )
|
||||
#include <stm32f4xx.h>
|
||||
#include <stm32f4xx_rcc.h>
|
||||
#include <stm32f4xx_gpio.h>
|
||||
#endif
|
||||
#include <core_cm4.h>
|
||||
#include <core_cmFunc.h>
|
||||
|
||||
|
@ -32,13 +39,13 @@ void send_text( const char * text )
|
|||
send_openocd_command(0x05, m);
|
||||
}
|
||||
|
||||
int _write (int fd, const void *buf, size_t count)
|
||||
int __attribute__((used)) _write (int fd, const void *buf, size_t count)
|
||||
{
|
||||
uint32_t m[] = { 2, (uint32_t)buf, count };
|
||||
send_openocd_command(0x05, m);
|
||||
}
|
||||
|
||||
void * _sbrk(int incr) {
|
||||
void __attribute__((used)) * _sbrk(int incr) {
|
||||
extern char _ebss; // Defined by the linker
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
@ -71,32 +78,97 @@ void _delay_us(uint32_t us) {
|
|||
|
||||
void ConfigureLED()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
/* Enable the GPIO_LED Clock */
|
||||
ConfigureGPIO( LEDPIN, INOUT_OUT );
|
||||
}
|
||||
|
||||
#ifdef STM32F30X
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||||
uint8_t GetGPIOFromString( const char * str )
|
||||
{
|
||||
int mode = 0;
|
||||
int port = -1;
|
||||
int pin = -1;
|
||||
const char * st = str;
|
||||
for( ; *st; st++ )
|
||||
{
|
||||
char c = *st;
|
||||
if( mode == 0 )
|
||||
{
|
||||
if( c >= 'A' && c <= 'F' )
|
||||
{
|
||||
port = c - 'A';
|
||||
mode = 2;
|
||||
}
|
||||
else if( c >= 'a' && c <= 'f' )
|
||||
{
|
||||
port = c - 'a';
|
||||
mode = 2;
|
||||
}
|
||||
}
|
||||
else if( mode == 2 )
|
||||
{
|
||||
if( c >= '0' && c <= '9' )
|
||||
{
|
||||
pin = 0;
|
||||
mode = 3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure the GPIO_LED pin */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //| GPIO_Pin_15 (15 = CTS)
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
#elif defined( STM32F40_41xxx )
|
||||
|
||||
RCC_AHB1PeriphClockCmd( LED_AHB_PORT, ENABLE);
|
||||
|
||||
/* Configure the GPIO_LED pin */
|
||||
GPIO_InitStructure.GPIO_Pin = (1<<LEDPIN);
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(LEDPORT, &GPIO_InitStructure);
|
||||
#endif
|
||||
if( mode == 3 )
|
||||
{
|
||||
if( c >= '0' && c <= '9' )
|
||||
{
|
||||
pin = pin * 10;
|
||||
pin+= c - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( port > 0 && pin > 0 && port <= 6 && pin <= 15)
|
||||
{
|
||||
return (port<<4)|pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfigureGPIO( uint8_t gpio, int parameters )
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* Enable the GPIO_LED Clock */
|
||||
#ifdef STM32F30X
|
||||
RCC_AHBPeriphClockCmd( 1<<(17+(gpio>>4)), ENABLE);
|
||||
#elif defined( STM32F40_41xxx )
|
||||
RCC_AHB1PeriphClockCmd( 1<<((gpio>>4)), ENABLE);
|
||||
#endif
|
||||
|
||||
if( parameters & DEFAULT_VALUE_FLAG )
|
||||
{
|
||||
GPIOOn( gpio );
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOOff( gpio );
|
||||
}
|
||||
|
||||
/* Configure the GPIO_LED pin */
|
||||
GPIO_InitStructure.GPIO_Pin = 1<<(gpio&0xf);
|
||||
GPIO_InitStructure.GPIO_Mode = (parameters&INOUT_FLAG)?GPIO_Mode_OUT:GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = (parameters&PUPD_FLAG)?( (parameters&PUPD_UP)?GPIO_PuPd_UP:GPIO_PuPd_DOWN ):GPIO_PuPd_NOPULL;
|
||||
|
||||
#ifdef STM32F30X
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
#elif defined( STM32F40_41xxx )
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
#endif
|
||||
|
||||
GPIO_Init(GPIOOf(gpio), &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,53 +1,63 @@
|
|||
#ifndef _SYSTEMS_H
|
||||
#define _SYSTEMS_H
|
||||
|
||||
|
||||
#ifdef STM32F30X
|
||||
#include <stm32f30x.h>
|
||||
#include <stm32f30x_rcc.h>
|
||||
#include <stm32f30x_gpio.h>
|
||||
|
||||
#define LEDPORT GPIOB
|
||||
#define LEDPIN 8
|
||||
|
||||
#elif defined( STM32F40_41xxx )
|
||||
|
||||
#include <stm32f4xx.h>
|
||||
#include <stm32f4xx_rcc.h>
|
||||
#include <stm32f4xx_gpio.h>
|
||||
|
||||
#define LED_AHB_PORT RCC_AHB1Periph_GPIOD
|
||||
#define LEDPORT GPIOD
|
||||
#define LEDPIN 15
|
||||
#else
|
||||
|
||||
#error Unsupported device.
|
||||
|
||||
#endif
|
||||
|
||||
void send_openocd_command(int command, void *message);
|
||||
void send_text( const char * text );
|
||||
void _delay_us(uint32_t us);
|
||||
|
||||
void ConfigureLED();
|
||||
|
||||
typedef uint8_t gpio;
|
||||
|
||||
gpio GetGPIOFromString( const char * str );
|
||||
|
||||
|
||||
#define LED_TOGGLE {LEDPORT->ODR ^= (1<<LEDPIN);}
|
||||
#define DEFAULT_VALUE_FLAG 0x00000001
|
||||
#define DEFAULT_ON 0x00000001
|
||||
#define DEFAULT_OFF 0x00000000
|
||||
|
||||
#ifdef STM32F30X
|
||||
#define INOUT_FLAG 0x00000002
|
||||
#define INOUT_OUT 0x00000002
|
||||
#define INOUT_IN 0x00000000
|
||||
|
||||
#define LED_ON {LEDPORT->BSRR = (1<<LEDPIN);}
|
||||
#define LED_OFF {LEDPORT->BRR = (1<<LEDPIN);}
|
||||
#define PUPD_FLAG 0x0000000C
|
||||
#define PUPD_NONE 0x00000000
|
||||
#define PUPD_UP 0x00000004
|
||||
#define PUPD_DOWN 0x00000008
|
||||
|
||||
void ConfigureGPIO( gpio gpio, int parameters );
|
||||
|
||||
|
||||
|
||||
#ifdef STM32F30X
|
||||
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB2PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
|
||||
#elif defined( STM32F40_41xxx )
|
||||
#define GPIOOf(x) ((GPIO_TypeDef *) ((((x)>>4)<=6)?(AHB1PERIPH_BASE+0x400*((x)>>4)):0x60000000) )
|
||||
#endif
|
||||
|
||||
#define LED_ON {LEDPORT->BSRRL = (1<<LEDPIN);}
|
||||
#define LED_OFF {LEDPORT->BSRRH = (1<<LEDPIN);}
|
||||
#define GPIOPin(x) ((1<<((x)&0x0f)))
|
||||
#define GPIOLatch(x) GPIOOf(x)->ODR
|
||||
|
||||
#ifdef STM32F30X
|
||||
#define GPIOOn(x) GPIOOf(x)->BSRR = (1<<((x)&0x0f));
|
||||
#define GPIOOff(x) GPIOOf(x)->BRR = (1<<((x)&0x0f));
|
||||
#elif defined( STM32F40_41xxx )
|
||||
#define GPIOOn(x) GPIOOf(x)->BSRRH = (1<<((x)&0x0f));
|
||||
#define GPIOOff(x) GPIOOf(x)->BSRRL = (1<<((x)&0x0f));
|
||||
#endif
|
||||
|
||||
|
||||
//General notes:
|
||||
|
||||
#ifdef STM32F30X
|
||||
#define LEDPIN 0x18
|
||||
#elif defined( STM32F40_41xxx )
|
||||
#define LEDPIN 0x3f
|
||||
#endif
|
||||
|
||||
void ConfigureLED();
|
||||
#define LED_TOGGLE {GPIOOf(LEDPIN)->ODR^=(1<<((LEDPIN)&0x0f));}
|
||||
#define LED_ON GPIOOn(LEDPIN)
|
||||
#define LED_OFF GPIOOff(LEDPIN)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue