Improvements:

- HAL re-organized
- FreeRTOS running stable
- UART finished
- SPI1 & SPI3 finished and functional
- Display driver added (functional)


git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@172 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-09-20 06:51:53 +00:00
parent f5dd9e0f09
commit c9562e8bfd
313 changed files with 8279 additions and 50216 deletions

View File

@@ -17,17 +17,21 @@
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.debug.808293012" name="Debug" parent="cdt.managedbuild.config.gnu.cross.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.808293012." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.debug.1318348185" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.debug">
<option id="cdt.managedbuild.option.gnu.cross.prefix.507777304" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-none-eabi-" valueType="string"/>
<option id="cdt.managedbuild.option.gnu.cross.prefix.507777304" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-none-eabi-" valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1783053684" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder buildPath="${workspace_loc:/HAL}/Debug" id="cdt.managedbuild.builder.gnu.cross.1896643983" managedBuildOn="true" name="Gnu Make Builder.Debug" superClass="cdt.managedbuild.builder.gnu.cross"/>
<builder buildPath="${workspace_loc:/HAL}/Debug" id="cdt.managedbuild.builder.gnu.cross.1896643983" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1995230970" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1239482633" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.1951365338" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1239482633" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.1951365338" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.35161744" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1588900239" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1635882225" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
<option id="gnu.cpp.compiler.option.optimization.level.1603876771" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.debugging.level.2081581981" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.optimization.level.1603876771" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.debugging.level.2081581981" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1003659599" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.893207872" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
@@ -62,17 +66,17 @@
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.2018673829" name="Release" parent="cdt.managedbuild.config.gnu.cross.exe.release">
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.2018673829." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1626704719" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release">
<option id="cdt.managedbuild.option.gnu.cross.prefix.2097604595" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-none-eabi-" valueType="string"/>
<option id="cdt.managedbuild.option.gnu.cross.prefix.2097604595" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-none-eabi-" valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.687061273" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder buildPath="${workspace_loc:/HAL}/Release" id="cdt.managedbuild.builder.gnu.cross.885711161" managedBuildOn="true" name="Gnu Make Builder.Release" superClass="cdt.managedbuild.builder.gnu.cross"/>
<builder buildPath="${workspace_loc:/HAL}/Release" id="cdt.managedbuild.builder.gnu.cross.885711161" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.719739142" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.228216520" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.829828996" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.228216520" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.829828996" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1364474382" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.69898473" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
<option id="gnu.cpp.compiler.option.optimization.level.510159278" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.debugging.level.1226783592" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.optimization.level.510159278" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.debugging.level.1226783592" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1056791212" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1964834827" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
@@ -105,4 +109,17 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/HAL"/>
</configuration>
<configuration configurationName="Release">
<resource resourceType="PROJECT" workspacePath="/HAL"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
<doc-comment-owner id="org.eclipse.cdt.ui.doxygen">
<path value=""/>
</doc-comment-owner>
</storageModule>
</cproject>

View File

@@ -0,0 +1,48 @@
CROSS_COMPILE = arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OBJDIR = obj
SRCDIR = src/
ROOTDIR = ../../
LIBRARY_NAME = ../libDisplay.a
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb \
-Iinc \
-I../Platform/inc \
-I../Misc/inc \
-I$(ROOTDIR)/hsb-mrts/inc \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc \
-I$(ROOTDIR)/FreeRTOS/Source/include \
-I$(ROOTDIR)/FreeRTOS/Source/portable/GCC/ARM_CM3 \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
ARFLAGS = rs
OBJECTS = \
nhd0420.o \
vpath %.o $(OBJDIR)
vpath %.c $(SRCDIR)
all: $(LIBRARY_NAME)
$(LIBRARY_NAME): $(OBJDIR) $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(addprefix $(OBJDIR)/, $(OBJECTS))
%.o: %.c
$(CC) $(CCFLAGS) $< -o $(OBJDIR)/$@
$(OBJDIR):
mkdir -p $@
clean:
rm -rf $(OBJDIR) $(LIBRARY_NAME)
.PHONY: all clean

View File

@@ -0,0 +1,242 @@
// -----------------------------------------------------------------------------
/// @file nhd0420.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file nhd0420.h
/// @ingroup {group_name}
#ifndef DISPLAY_INC_NHD0420_H_
#define DISPLAY_INC_NHD0420_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define NHD0420_NUMBER_OF_ROWS (4)
#define NHD0420_NUMBER_OF_COLUMNS (20)
#define NHD0420_CONTRAST_MIN (1)
#define NHD0420_CONTRAST_MAX (50)
#define NHD0420_BRIGHTNESS_MIN (1)
#define NHD0420_BRIGHTNESS_MAX (8)
#define NHD0420_BAUDRATE_MIN (1)
#define NHD0420_BAUDRATE_MAX (8)
#define NHD0420_CMD_LENGTH (2)
#define NHD0420_CMD_PREFIX (0xFE)
#define NHD0420_CMD_DISPLAY_ON (0x41)
#define NHD0420_CMD_DISPLAY_OFF (0x42)
#define NHD0420_CMD_CURSOR_SET (0x45)
#define NHD0420_CMD_CURSOR_HOME (0x46)
#define NHD0420_CMD_CURSOR_UL_ON (0x47)
#define NHD0420_CMD_CURSOR_UL_OFF (0x48)
#define NHD0420_CMD_CURSOR_MV_LEFT (0x49)
#define NHD0420_CMD_CURSOR_MV_RIGHT (0x4A)
#define NHD0420_CMD_CURSOR_BLK_ON (0x4B)
#define NHD0420_CMD_CURSOR_BLK_OFF (0x4C)
#define NHD0420_CMD_CURSOR_BACKSPACE (0x4E)
#define NHD0420_CMD_CLR_SCREEN (0x51)
#define NHD0420_CMD_SET_CONTRAST (0x52)
#define NHD0420_CMD_SET_BRIGHTNESS (0x53)
#define NHD0420_CMD_LOAD_CSTM_CHAR (0x54)
#define NHD0420_CMD_MV_DISPLAY_LEFT (0x55)
#define NHD0420_CMD_MV_DISPLAY_RIGHT (0x56)
#define NHD0420_CMD_CHANGE_RS232_BR (0x61)
#define NHD0420_CMD_CHANGE_I2C_ADDRSS (0x62)
#define NHD0420_CMD_SHOW_VERSION (0x70)
#define NHD0420_CMD_SHOW_RS232_BR (0x71)
#define NHD0420_CMD_SHOW_I2C_ADDRSS (0x72)
#define NHD0420_turnOnDisplay() NHD0420_sendCommand(NHD0420_CMD_DISPLAY_ON)
#define NHD0420_turnOffDisplay() NHD0420_sendCommand(NHD0420_CMD_DISPLAY_OFF)
#define NHD0420_setCursorToHome() NHD0420_sendCommand(NHD0420_CMD_CURSOR_HOME)
#define NHD0420_setUnderlineCursorOn() NHD0420_sendCommand(NHD0420_CMD_CURSOR_UL_ON)
#define NHD0420_setUnderlineCursorOff() NHD0420_sendCommand(NHD0420_CMD_CURSOR_UL_OFF)
#define NHD0420_moveCursorToLeft() NHD0420_sendCommand(NHD0420_CMD_CURSOR_MV_LEFT)
#define NHD0420_moveCursorToRight() NHD0420_sendCommand(NHD0420_CMD_CURSOR_MV_RIGHT)
#define NHD0420_turnOnBlinkingCursor() NHD0420_sendCommand(NHD0420_CMD_CURSOR_BLK_ON)
#define NHD0420_turnOffBlinkingCursor() NHD0420_sendCommand(NHD0420_CMD_CURSOR_BLK_OFF)
#define NHD0420_useBackspace() NHD0420_sendCommand(NHD0420_CMD_CURSOR_BACKSPACE)
#define NHD0420_clearScreen() NHD0420_sendCommand(NHD0420_CMD_CLR_SCREEN)
#define NHD0420_moveDisplayToLeft() NHD0420_sendCommand(NHD0420_CMD_MV_DISPLAY_LEFT)
#define NHD0420_moveDisplayToRight() NHD0420_sendCommand(NHD0420_CMD_MV_DISPLAY_RIGHT)
#define NHD0420_showFirmwareVersion() NHD0420_sendCommand(NHD0420_CMD_SHOW_VERSION)
#define NHD0420_showRS232Baudrate() NHD0420_sendCommand(NHD0420_CMD_SHOW_RS232_BR)
#define NHD0420_showI2CAddress() NHD0420_sendCommand(NHD0420_CMD_SHOW_I2C_ADDRSS)
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* NHD0420_Init
* Initialises the NewHeaven Display 0420
*
* @param interface The interface to use
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_construct(void* interface);
/** ----------------------------------------------------------------------------
* NHD0420_setCursorToPosition
* Sets the cursor of the display to the specified row and column
*
* @param row The Row to set - between 1 and 4
* @param column The column to set - between 1 and 20
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column);
/** ----------------------------------------------------------------------------
* NHD0420_setContrast
* Sets the contrast of the display
*
* @param contrast The contrast to set - between 1 and 50.
* If passed value is outside the boundaries
* this function will return ERROR
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_setContrast(uint8_t contrast);
/** ----------------------------------------------------------------------------
* NHD0420_setBacklightBrightness
* Sets the backlight brightness of the display
*
* @param brightness The contrast to set - between 1 and 8
* If passed value is outside the boundaries
* this function will return ERROR
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness);
/** ----------------------------------------------------------------------------
* NHD0420_setRS232Baudrate
* Sets the baudrate of the display
*
* @param baudrate The baudrate to set - between 1 and 8
* 1 = 300 baud
* 2 = 1200 baud
* 3 = 2400 baud
* 4 = 9600 baud
* 5 = 14400 baud
* 6 = 19200 baud
* 7 = 57600 baud
* 8 = 115200 baud
* If passed value is outside the boundaries
* this function will return ERROR
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate);
/** ----------------------------------------------------------------------------
* NHD0420_setI2CAddress
* Sets the I2C address of the display
*
* @param address The address to set
* This command sets the I2C address. The
* address must be an even number (LSB = 0)
* and must not be 0xFF.
* The address change requires 20 us to
* take effect; therefore, the subsequent
* input must have an appropriate delay.
* The default I2C address can be
* restored if SPI or RS-232 is selected as
* the communication mode.
* Default: 0x50
*
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_setI2CAddress(uint8_t address);
/** ----------------------------------------------------------------------------
* NHD0420_SendCommand
* Send a command to the display
*
* @param command
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus NHD0420_sendCommand(uint8_t command);
extern ErrorStatus NHD0420_sendData(const uint8_t* buffer, size_t length);
#endif /* DISPLAY_INC_NHD0420_H_ */

View File

@@ -0,0 +1,241 @@
// -----------------------------------------------------------------------------
/// @file nhd0420.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file nhd0420.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdio.h>
#include "stm32f10x.h"
#include "nhd0420.h"
#include "spi.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define NHD0420_CURSOR_OFFSET_ROW1 (0x00)
#define NHD0420_CURSOR_OFFSET_ROW2 (0x40)
#define NHD0420_CURSOR_OFFSET_ROW3 (0x14)
#define NHD0420_CURSOR_OFFSET_ROW4 (0x54)
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
{
NHD0420_CURSOR_OFFSET_ROW1,
NHD0420_CURSOR_OFFSET_ROW2,
NHD0420_CURSOR_OFFSET_ROW3,
NHD0420_CURSOR_OFFSET_ROW4
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
static struct SpiDevice* nhd0420Interface;
ErrorStatus NHD0420_construct(void* interface)
{
ErrorStatus returnValue = SUCCESS;
nhd0420Interface = (struct SpiDevice*)interface;
return returnValue;
}
ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column)
{
ErrorStatus returnValue = SUCCESS;
// Setting cursor requires sending a command sequence with an additional
// address parameter representing the line/column
// Each line has a dedicated offset, the column is simply added to that offset
// Make sure to keep within boundaries to avoid glitches
row = row -1;
column = column - 1;
// Check the coordinates to avoid glitches
if ((row >= NHD0420_NUMBER_OF_ROWS) && (column >= NHD0420_NUMBER_OF_COLUMNS))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
uint8_t address = nhd0420_cursorRowOffset[row] + column;
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setContrast(uint8_t contrast)
{
ErrorStatus returnValue = SUCCESS;
// Setting contrast requires sending a command sequence with an additional
// parameter representing the contrast
// Contrast values must be between NHD0420_CONTRAST_MIN and
// NHD0420_CONTRAST_MAX. If boundaries are exceeded, this function will be
// left with an ERROR
if ((contrast < NHD0420_CONTRAST_MIN) || (contrast > NHD0420_CONTRAST_MAX))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness)
{
ErrorStatus returnValue = SUCCESS;
// Setting backlight brightness requires sending a command sequence with an
// additional parameter representing the brightness
// Brightness values must be between NHD0420_BRIGHTNESS_MIN and
// NHD0420_BRIGHTNESS_MAX. If boundaries are exceeded, this function will be
// left with an ERROR
if ((brightness < NHD0420_BRIGHTNESS_MIN) || (brightness > NHD0420_BRIGHTNESS_MAX))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate)
{
ErrorStatus returnValue = SUCCESS;
// Setting baudrate requires sending a command sequence with an
// additional parameter representing the baudrate
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
// NHD0420_BAUDRATE_MAX. If boundaries are exceeded, this function will be
// left with an ERROR
if ((baudrate < NHD0420_BAUDRATE_MIN) || (baudrate > NHD0420_BAUDRATE_MAX))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_RS232_BR, baudrate};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setI2CAddress(uint8_t address)
{
ErrorStatus returnValue = SUCCESS;
// Setting I2C requires sending a command sequence with an
// additional parameter representing the address
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
// NHD0420_BAUDRATE_MAX. If boundaries are exeeded, this function will be
// left with an ERROR
if ((address | 0xFE) != 0xFE)
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_I2C_ADDRSS, address};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
/** ----------------------------------------------------------------------------
* NHD0420_SendCommand
* Send a command to the display
*
* @param command
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
ErrorStatus NHD0420_sendCommand(uint8_t command)
{
ErrorStatus returnValue = SUCCESS;
uint8_t buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
returnValue = SPI_write(nhd0420Interface, buffer, NHD0420_CMD_LENGTH);
return returnValue;
}
ErrorStatus NHD0420_sendData(const uint8_t* buffer, size_t length)
{
ErrorStatus returnValue = SUCCESS;
returnValue = SPI_write(nhd0420Interface, buffer, length);
return returnValue;
}

View File

@@ -0,0 +1,15 @@
all:
# $(MAKE) -C Keypad
$(MAKE) -C Display
$(MAKE) -C Misc
$(MAKE) -C Platform
clean:
# $(MAKE) -C Keypad clean
$(MAKE) -C Display clean
$(MAKE) -C Misc clean
$(MAKE) -C Platform clean
.PHONY: all clean

View File

@@ -0,0 +1,52 @@
CROSS_COMPILE = arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OBJDIR = obj
SRCDIR = src/
ROOTDIR = ../../
LIBRARY_NAME = ../libMisc.a
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb \
-Iinc \
-I../Platform/inc \
-I$(ROOTDIR)/hsb-mrts/inc \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc \
-I$(ROOTDIR)/FreeRTOS/Source/include \
-I$(ROOTDIR)/FreeRTOS/Source/portable/GCC/ARM_CM3 \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
ARFLAGS = rs
OBJECTS = \
stm32f10x_it.o \
led.o \
spi.o \
uart.o \
vpath %.o $(OBJDIR)
vpath %.c \
$(SRCDIR) \
$(ROOTDIR)/hsb-mrts/src
all: $(LIBRARY_NAME)
$(LIBRARY_NAME): $(OBJDIR) $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(addprefix $(OBJDIR)/, $(OBJECTS))
%.o: %.c
$(CC) $(CCFLAGS) $< -o $(OBJDIR)/$@
$(OBJDIR):
mkdir -p $@
clean:
rm -rf $(OBJDIR) $(LIBRARY_NAME)
.PHONY: all clean

View File

@@ -0,0 +1,87 @@
// -----------------------------------------------------------------------------
/// @file led.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file led.h
/// @ingroup {group_name}
#ifndef LED_INC_LED_H_
#define LED_INC_LED_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "platform.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct Led
{
T_PL_GPIO ledGpio;
bool status;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* LED_turnOn
* Turns on the LED identified with the ID
*
* @param ledID Unique identifier of the LED
*
* @return ErrorStatus SUCCESS if init was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus LED_turnOn(struct Led* const led);
/** ----------------------------------------------------------------------------
* LED_turnOff
* Turns off the LED identified with the ID
*
* @param ledID Unique identifier of the LED
*
* @return ErrorStatus SUCCESS if init was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus LED_turnOff(struct Led* const led);
#endif /* LED_INC_LED_H_ */

View File

@@ -0,0 +1,136 @@
// -----------------------------------------------------------------------------
/// @file spi.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file spi.h
/// @ingroup {group_name}
#ifndef MISC_INC_SPI_H_
#define MISC_INC_SPI_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "FreeRTOS.h"
#include "semphr.h"
#include "platform.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct spiQueueItem
{
char byte;
};
struct Spi
{
SPI_TypeDef* SPI_TypeDef;
SPI_InitTypeDef SPI_InitStruct;
T_PL_GPIO SPI_CLK;
T_PL_GPIO* SPI_CE;
T_PL_GPIO SPI_MOSI;
T_PL_GPIO SPI_MISO;
SemaphoreHandle_t spiClaimed; //! Semaphore to protect SPI bus
//! against multiple use
SemaphoreHandle_t txSemaphore; //! Semaphore for transmit handler
//! to allow wait state while
//! transmission is active
xQueueHandle txQueue; //! SPI Transfer queue identifier
xQueueHandle rxQueue; //! SPI Receive queue identifier
bool initialized;
};
struct SpiDevice
{
struct Spi* spi;
T_PL_GPIO SPI_CE;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* Spi_construct
* Description of function
*
* @param self The UART object to initialize
* @param baudrate Baudrate to use
* @param wordlength Wordlength for the UART
* @param stopbits Number of stopbits to use
* @param parity Parity of the UART
* @param mode Mode (TX, RX, Both)
* @param hwFlowControl Control of hardware flow control
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus SPI_construct(struct Spi* self, uint16_t SPI_Direction, uint16_t SPI_Mode, uint16_t SPI_DataSize, uint16_t SPI_CPOL, uint16_t SPI_CPHA, uint16_t SPI_NSS, uint16_t SPI_BaudRatePrescaler, uint16_t SPI_FirstBit, uint16_t SPI_CRCPolynomial, UBaseType_t txQueueSize, UBaseType_t rxQueueSize);
/** ----------------------------------------------------------------------------
* SPI_destruct
* Destructor for SPI interface in argument "self"
*
* @param self SPI to destruct
*
* @return ErrorStatus SUCCESS if destruct was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus SPI_destruct(struct Spi* self);
/** ----------------------------------------------------------------------------
* Spi_Write
* Write the data in buffer to the SPI in argument self
*
* @param self The UART class object
* @param buffer Message string to send
* @parm length Message length
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length);
#endif /* MISC_INC_SPI_H_ */

View File

@@ -0,0 +1,117 @@
// -----------------------------------------------------------------------------
/// @file uart.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file uart.h
/// @ingroup {group_name}
#ifndef MISC_INC_UART_H_
#define MISC_INC_UART_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "FreeRTOS.h"
#include "semphr.h"
#include "platform.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct usartQueueItem
{
char byte;
};
struct UartParameters
{
int baudrate;
};
struct Uart
{
USART_TypeDef* USART_TypeDef;
USART_InitTypeDef USART_InitStruct;
USART_ClockInitTypeDef* USART_ClockInitStruct;
T_PL_GPIO USART_RX;
T_PL_GPIO USART_TX;
T_PL_GPIO USART_CTS;
T_PL_GPIO USART_RTS;
SemaphoreHandle_t txSemaphore; //! Semaphore for transmit handler
xQueueHandle txQueue; //! USART Transfer queue identifier
xQueueHandle rxQueue; //! USART Receive queue identifier
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* Uart_Init
* Description of function
*
* @param _self The UART object to initialize
* @param baudrate Baudrate to use
* @param wordlength Wordlength for the UART
* @param stopbits Number of stopbits to use
* @param parity Parity of the UART
* @param mode Mode (TX, RX, Both)
* @param hwFlowControl Control of hardware flow control
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wordlength, uint16_t stopbits, uint16_t parity, uint16_t mode, uint16_t hwFlowControl, UBaseType_t txQueueSize, UBaseType_t rxQueueSize);
/** ----------------------------------------------------------------------------
* Uart_Write
* Description of function
*
* @param _self The UART class object
* @param buffer Message string to send
* @parm length Message length
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length);
#endif /* MISC_INC_UART_H_ */

View File

@@ -0,0 +1,79 @@
// -----------------------------------------------------------------------------
/// @file led.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file led.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "led.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus LED_turnOn(struct Led* const led)
{
ErrorStatus returnValue = SUCCESS;
GPIO_SetBits(led->ledGpio.GPIO_Typedef, led->ledGpio.GPIO_InitStruct.GPIO_Pin);
led->status = true;
return returnValue;
}
ErrorStatus LED_turnOff(struct Led* const led)
{
ErrorStatus returnValue = SUCCESS;
GPIO_ResetBits(led->ledGpio.GPIO_Typedef, led->ledGpio.GPIO_InitStruct.GPIO_Pin);
led->status = false;
return returnValue;
}

View File

@@ -0,0 +1,203 @@
// -----------------------------------------------------------------------------
/// @file spi.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file spi.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "spi.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus SPI_construct(struct Spi* self, uint16_t SPI_Direction, uint16_t SPI_Mode, uint16_t SPI_DataSize, uint16_t SPI_CPOL, uint16_t SPI_CPHA, uint16_t SPI_NSS, uint16_t SPI_BaudRatePrescaler, uint16_t SPI_FirstBit, uint16_t SPI_CRCPolynomial, UBaseType_t txQueueSize, UBaseType_t rxQueueSize)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
//! Create semaphore to synchronize with USART interrupt handler
vSemaphoreCreateBinary(self->txSemaphore);
//! Create semaphore to avoid multiple usage
vSemaphoreCreateBinary(self->spiClaimed);
SPI_I2S_DeInit(self->SPI_TypeDef);
self->SPI_InitStruct.SPI_Direction = SPI_Direction;
self->SPI_InitStruct.SPI_Mode = SPI_Mode;
self->SPI_InitStruct.SPI_DataSize = SPI_DataSize;
self->SPI_InitStruct.SPI_CPOL = SPI_CPOL;
self->SPI_InitStruct.SPI_CPHA = SPI_CPHA;
self->SPI_InitStruct.SPI_NSS = SPI_NSS;
self->SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler;
self->SPI_InitStruct.SPI_FirstBit = SPI_FirstBit;
self->SPI_InitStruct.SPI_CRCPolynomial = SPI_CRCPolynomial;
SPI_Init(self->SPI_TypeDef, &self->SPI_InitStruct);
//! Enable USART interface
SPI_Cmd(self->SPI_TypeDef, ENABLE);
//! Create a new FREERTOS queue to handle data from app to USART output
self->txQueue = xQueueCreate(txQueueSize, sizeof(struct spiQueueItem));
//! Create a new FREERTOS queue to handle data from USART input to app
self->rxQueue = xQueueCreate(rxQueueSize, sizeof(struct spiQueueItem));
//! Queue identifier must not be 0 (0 means that the queue is not available)
if (self->txQueue == 0)
{
//! Queue identifier is 0 -> error
returnValue = ERROR; //! Set error flag
}
if (self->rxQueue == 0)
{
//! Queue identifier is 0 -> error
returnValue = ERROR; //! Set error flag
}
//! Queue identifier is not 0 -> queue is available
//! take txSemaphore
if (xSemaphoreTake(self->txSemaphore, 0) == pdFALSE)
{
//! An error has occurred
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
//! Enable the UART RX not empty interrupt
SPI_I2S_ITConfig(self->SPI_TypeDef, SPI_I2S_IT_RXNE, ENABLE);
}
if (returnValue == SUCCESS)
{
self->initialized = true;
}
}
return returnValue;
}
ErrorStatus SPI_destruct (struct Spi* self)
{
ErrorStatus returnValue = SUCCESS;
return returnValue;
}
ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length)
{
struct spiQueueItem txItem;
ErrorStatus returnValue = SUCCESS; //! Define return variable
int txCounter; //! Define a loop counter var
xSemaphoreTake(self->spi->spiClaimed, portMAX_DELAY);
self->spi->SPI_CE = &self->SPI_CE;
// De-select the current device to avoid start-issues
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
//! Copy the incoming data into BLUETOOTH data structure
for (txCounter = 0; txCounter < length; txCounter++)
{
txItem.byte = buffer[txCounter]; //! Copy current data in struct
//! Add the current set of data to bluetooth transmission queue
if (pdTRUE != xQueueSend(self->spi->txQueue, &txItem, 0))
{
//! Adding item was NOT successful - break out of loop
returnValue = ERROR; //! Set return value to FALSE
break;
}
}
if (returnValue == SUCCESS)
{
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
//! Semaphore has been taken
//! Enable the SPI TXE (transmission empty) interrupt
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_IT_TXE, ENABLE);
//! Try to take Semaphore - If the USART transmission is still busy, the
//! Semaphore cannot be taken - FREERTOS will suspend this task until the
//! Semaphore is released again
xSemaphoreTake(self->spi->txSemaphore, portMAX_DELAY);
/** Enabling the TX interrupt will immediately cause an interrupt because
* the transmission register is still empty. The ISR will get the data
* from the uart transmission queue and transmit byte-wise until the
* queue is empty.
* An empty queue will cause the transmission complete flag (TC) to be set,
* which is polled
*/
while (SPI_I2S_GetFlagStatus(self->spi->SPI_TypeDef, SPI_I2S_FLAG_BSY) == SET)
{
//! The software must wait until TXE=1. The TXE flag remains cleared during
//! all data transfers and it is set by hardware at the last frame's
//! end of transmission
}
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
xSemaphoreGive(self->spi->spiClaimed);
}
else
{
//! Do nothing
}
return (returnValue); //! Return result to caller
}

View File

@@ -0,0 +1,179 @@
// -----------------------------------------------------------------------------
/// @file uart.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file uart.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "FreeRTOS.h"
#include "semphr.h"
#include "stm32f10x_usart.h"
#include "uart.h"
#include "misc.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wordlength, uint16_t stopbits, uint16_t parity, uint16_t mode, uint16_t hwFlowControl, UBaseType_t txQueueSize, UBaseType_t rxQueueSize)
{
ErrorStatus returnValue = SUCCESS;
//! Create semaphore to synchronize with USART interrupt handler
vSemaphoreCreateBinary(_self->txSemaphore);
USART_DeInit(_self->USART_TypeDef);
_self->USART_ClockInitStruct->USART_Clock = USART_Clock_Enable;
_self->USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
_self->USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
_self->USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
//! Enable USART clock
USART_ClockInit(_self->USART_TypeDef, _self->USART_ClockInitStruct);
// Initialise the UART
_self->USART_InitStruct.USART_BaudRate = baudrate;
_self->USART_InitStruct.USART_WordLength = wordlength;
_self->USART_InitStruct.USART_StopBits = stopbits;
_self->USART_InitStruct.USART_Parity = parity;
_self->USART_InitStruct.USART_Mode = mode;
_self->USART_InitStruct.USART_HardwareFlowControl = hwFlowControl;
USART_Init(_self->USART_TypeDef, &_self->USART_InitStruct);
//! Enable USART interface
USART_Cmd(_self->USART_TypeDef, ENABLE);
//! Create a new FREERTOS queue to handle data from app to USART output
_self->txQueue = xQueueCreate(txQueueSize, sizeof(struct usartQueueItem));
//! Create a new FREERTOS queue to handle data from USART input to app
_self->rxQueue = xQueueCreate(rxQueueSize, sizeof(struct usartQueueItem));
//! Queue identifier must not be 0 (0 means that the queue is not available)
if (_self->txQueue == 0)
{
//! Queue identifier is 0 -> error
returnValue = ERROR; //! Set error flag
}
if (_self->rxQueue == 0)
{
//! Queue identifier is 0 -> error
returnValue = ERROR; //! Set error flag
}
//! Queue identifier is not 0 -> queue is available
//! take txSemaphore
if (xSemaphoreTake(_self->txSemaphore, 0) == pdFALSE)
{
//! An error has occurred
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
//! Enable the UART RX not empty interrupt
USART_ITConfig(_self->USART_TypeDef, USART_IT_RXNE, ENABLE);
}
return returnValue;
}
ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length)
{
struct usartQueueItem usartTxItem;
ErrorStatus returnValue = SUCCESS; //! Define return variable
int txCounter; //! Define a loop counter var
//! Copy the incoming data into BLUETOOTH data structure
for (txCounter = 0; txCounter < length; txCounter++)
{
usartTxItem.byte = buffer[txCounter]; //! Copy current data in struct
//! Add the current set of data to bluetooth transmission queue
if (pdTRUE != xQueueSend(_self->txQueue, &usartTxItem, 0))
{
//! Adding item was NOT successful - break out of loop
returnValue = ERROR; //! Set return value to FALSE
break;
}
}
if (returnValue == SUCCESS)
{
//! Semaphore has been taken
//! Enable the USARTx TXE (transmission empty) interrupt
USART_ITConfig(_self->USART_TypeDef, USART_IT_TXE, ENABLE);
//! Try to take Semaphore - If the USART transmission is still busy, the
//! Semaphore cannot be taken - FREERTOS will suspend this task until the
//! Semaphore is released again
xSemaphoreTake(_self->txSemaphore, portMAX_DELAY);
/** Enabling the TX interrupt will immediately cause an interrupt because
* the transmission register is still empty. The ISR will get the data
* from the uart transmission queue and transmit byte-wise until the
* queue is empty.
* An empty queue will cause the transmission complete flag (TC) to be set,
* which is polled
*/
while (USART_GetFlagStatus(_self->USART_TypeDef, USART_FLAG_TC) == RESET)
{
//! The software must wait until TC=1. The TC flag remains cleared during
//! all data transfers and it is set by hardware at the last frame's
//! end of transmission
}
}
else
{
//! Do nothing
}
return (returnValue); //! Return result to caller
}

View File

@@ -0,0 +1,47 @@
CROSS_COMPILE = arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OBJDIR = obj
SRCDIR = src/
ROOTDIR = ../../
LIBRARY_NAME = ../libPlatform.a
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb -DOLI_STM32_H107 \
-Iinc \
-I../Misc/inc \
-I$(ROOTDIR)/hsb-mrts/inc \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc \
-I$(ROOTDIR)/FreeRTOS/Source/include \
-I$(ROOTDIR)/FreeRTOS/Source/portable/GCC/ARM_CM3 \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x \
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
ARFLAGS = rs
OBJECTS = \
oli_stm32_h107.o \
vpath %.o $(OBJDIR)
vpath %.c \
$(SRCDIR)
all: $(LIBRARY_NAME)
$(LIBRARY_NAME): $(OBJDIR) $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(addprefix $(OBJDIR)/, $(OBJECTS))
%.o: %.c
$(CC) $(CCFLAGS) $< -o $(OBJDIR)/$@
$(OBJDIR):
mkdir -p $@
clean:
rm -rf $(OBJDIR) $(LIBRARY_NAME)
.PHONY: all clean

View File

@@ -0,0 +1,106 @@
// -----------------------------------------------------------------------------
/// @file platform.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {HAL} {group_description}
/// This file defines the properties for the Olimex STM32 H107 dev-kit
/// platform.
///
/// @file olx_stm32_h107.h
/// @ingroup {HAL}
#ifndef PLATFORM_INC_PLATFORM_H_
#define PLATFORM_INC_PLATFORM_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "FreeRTOSConfig.h"
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_spi.h"
#include "stm32f10x_usart.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
typedef struct
{
GPIO_TypeDef* GPIO_Typedef;
GPIO_InitTypeDef GPIO_InitStruct;
} T_PL_GPIO;
// Export of LEDs
extern struct Led* const ledGreen;
extern struct Led* const ledOrange;
// Export of UARTs
extern struct Uart* const uart1;
// Export of SPIs
extern struct Spi* const spi1;
extern struct Spi* const spi3;
extern struct SpiDevice* const spiDAC;
extern struct SpiDevice* const spiDisplay;
extern struct SpiDevice* const spiEEPROM;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* initPlatform
* Initialises the platform-specific properties like GPIO, peripheral systems
* and the like
*
* @return ErrorStatus SUCCESS if init was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus initPlatform(void);
/** ----------------------------------------------------------------------------
* destructPlatform
* Function de de-initialise (destruct) the platform-specific properties and
* safely remove all settings that have been set-up with the initPlatform
* function
*
* @return ErrorStatus SUCCESS if init was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus destructPlatform(void);
#endif /* PLATFORM_INC_PLATFORM_H_ */

View File

@@ -0,0 +1,289 @@
// -----------------------------------------------------------------------------
/// @file oli_stm32_h107.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file oli_stm32_h107.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdio.h>
#include "stm32f10x_gpio.h"
#include "stm32f10x_it.h"
#include "platform.h"
#include "led.h"
#include "spi.h"
#include "uart.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// UART1 Settings (Logger/Console)
#define UART_LOG_TYPEDEF (USART1)
#define UART_LOG_BAUDRATE (57600)
#define UART_LOG_WORDLENGTH (USART_WordLength_8b)
#define UART_LOG_STOPBITS (USART_StopBits_1)
#define UART_LOG_PARITY (USART_Parity_No)
#define UART_LOG_MODE (USART_Mode_Tx | USART_Mode_Rx)
#define UART_LOG_HW_FLOW_CONTROL (USART_HardwareFlowControl_None)
#define UART_LOG_RX_QUEUE (256)
#define UART_LOG_TX_QUEUE (256)
// SPI1 settings
#define SPI_DAC_TYPEDEF (SPI1)
#define SPI_DAC_Direction (SPI_Direction_2Lines_FullDuplex)
#define SPI_DAC_Mode (SPI_Mode_Master)
#define SPI_DAC_DataSize (SPI_DataSize_8b)
#define SPI_DAC_CPOL (SPI_CPOL_High)
#define SPI_DAC_CPHA (SPI_CPHA_2Edge)
#define SPI_DAC_NSS (SPI_NSS_Hard)
#define SPI_DAC_BaudRatePrescaler (SPI_BaudRatePrescaler_128)
#define SPI_DAC_FirstBit (SPI_FirstBit_MSB)
#define SPI_DAC_CRCPolynomial (7)
#define SPI_DAC_RX_QUEUE (32)
#define SPI_DAC_TX_QUEUE (32)
// SPI3 settings
#define SPI_LCD_TYPEDEF (SPI3)
#define SPI_LCD_Direction (SPI_Direction_2Lines_FullDuplex)
#define SPI_LCD_Mode (SPI_Mode_Master)
#define SPI_LCD_DataSize (SPI_DataSize_8b)
#define SPI_LCD_CPOL (SPI_CPOL_High)
#define SPI_LCD_CPHA (SPI_CPHA_2Edge)
#define SPI_LCD_NSS (SPI_NSS_Soft)
// Display has max SPI CLK of 100 kHz
#define SPI_LCD_BaudRatePrescaler (SPI_BaudRatePrescaler_128)
#define SPI_LCD_FirstBit (SPI_FirstBit_MSB)
#define SPI_LCD_CRCPolynomial (7)
#define SPI_LCD_RX_QUEUE (32)
#define SPI_LCD_TX_QUEUE (32)
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// The following static file-scope variables represent the actual storage of
// the IO/Peripheral object
// LEDs
static struct Led _ledGreen;
static struct Led _ledOrange;
// USART
static struct Uart _uart1;
// SPI
static struct Spi _spi1;
static struct SpiDevice _spiDAC;
static struct Spi _spi3;
static struct SpiDevice _spiDisplay;
static struct SpiDevice _spiEEPROM;
// The following pointers are for export (see platform.h) and external use.
// Note that the pointer content is marked "const"
struct Led* const ledGreen = &_ledGreen;
struct Led* const ledOrange = &_ledOrange;
struct Uart* const uart1 = &_uart1;
struct Spi* const spi1 = &_spi1;
struct Spi* const spi3 = &_spi3;
struct SpiDevice* const spiDAC = &_spiDAC;
struct SpiDevice* const spiDisplay = &_spiDisplay;
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus initIO (void);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
//#ifdef OLI_STM32_H107
ErrorStatus initPlatform(void)
{
ErrorStatus returnValue = SUCCESS;
if (returnValue == SUCCESS)
{
returnValue = initIO();
// Initialize the Console UART
IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE);
uart1->USART_TypeDef = UART_LOG_TYPEDEF;
returnValue = Uart_Init(uart1, UART_LOG_BAUDRATE, UART_LOG_WORDLENGTH, UART_LOG_STOPBITS, UART_LOG_PARITY, UART_LOG_MODE, UART_LOG_HW_FLOW_CONTROL, UART_LOG_TX_QUEUE, UART_LOG_RX_QUEUE);
IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
spi1->initialized = false;
spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
SPI_construct(spi1, SPI_DAC_Direction, SPI_DAC_Mode, SPI_DAC_DataSize, SPI_DAC_CPOL, SPI_DAC_CPHA, SPI_DAC_NSS, SPI_DAC_BaudRatePrescaler, SPI_DAC_FirstBit, SPI_DAC_CRCPolynomial, SPI_DAC_TX_QUEUE, SPI_DAC_RX_QUEUE);
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
spi3->initialized = false;
spi3->SPI_TypeDef = SPI_LCD_TYPEDEF;
SPI_construct(spi3, SPI_LCD_Direction, SPI_LCD_Mode, SPI_LCD_DataSize, SPI_LCD_CPOL, SPI_LCD_CPHA, SPI_LCD_NSS, SPI_LCD_BaudRatePrescaler, SPI_LCD_FirstBit, SPI_LCD_CRCPolynomial, SPI_LCD_TX_QUEUE, SPI_LCD_RX_QUEUE);
}
return returnValue;
}
//#endif
static ErrorStatus initIO (void)
{
ErrorStatus returnValue = SUCCESS;
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
//! Enable USART clock
/* Peripheral bus power --------------------------------------------------*/
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
/*LED IO initialisation --------------------------------------------------*/
// Init LED Green
_ledGreen.ledGpio.GPIO_Typedef = GPIOC;
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_ledGreen.ledGpio.GPIO_Typedef, &_ledGreen.ledGpio.GPIO_InitStruct);
// Init LED Orange
_ledOrange.ledGpio.GPIO_Typedef = GPIOC;
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_ledOrange.ledGpio.GPIO_Typedef, &_ledOrange.ledGpio.GPIO_InitStruct);
/* USART1 initialisation -------------------------------------------------*/
// Init TX line
_uart1.USART_TX.GPIO_Typedef = GPIOB;
_uart1.USART_TX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_uart1.USART_TX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
_uart1.USART_TX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_uart1.USART_TX.GPIO_Typedef, &_uart1.USART_TX.GPIO_InitStruct);
// Init RX line
_uart1.USART_RX.GPIO_Typedef = GPIOB;
_uart1.USART_RX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_uart1.USART_RX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
_uart1.USART_RX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_uart1.USART_RX.GPIO_Typedef, &_uart1.USART_RX.GPIO_InitStruct);
// Apply pin-remapping for UART1 I/Os (alternative I/Os usage)
GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
/* SPI initialisation ----------------------------------------------------*/
// SPI1 CLK
_spi1.SPI_CLK.GPIO_Typedef = GPIOA;
_spi1.SPI_CLK.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spi1.SPI_CLK.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
_spi1.SPI_CLK.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spi1.SPI_CLK.GPIO_Typedef, &_spi1.SPI_CLK.GPIO_InitStruct);
// SPI1 MISO
_spi1.SPI_MISO.GPIO_Typedef = GPIOA;
_spi1.SPI_MISO.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spi1.SPI_MISO.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
_spi1.SPI_MISO.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spi1.SPI_MISO.GPIO_Typedef, &_spi1.SPI_MISO.GPIO_InitStruct);
// SPI1 MOSI
_spi1.SPI_MOSI.GPIO_Typedef = GPIOA;
_spi1.SPI_MOSI.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spi1.SPI_MOSI.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
_spi1.SPI_MOSI.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spi1.SPI_MOSI.GPIO_Typedef, &_spi1.SPI_MOSI.GPIO_InitStruct);
// SPI1 CE
_spiDAC.SPI_CE.GPIO_Typedef = GPIOA;
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spiDAC.SPI_CE.GPIO_Typedef, &_spiDAC.SPI_CE.GPIO_InitStruct);
spiDAC->spi = &_spi1;
// SPI3 CLK
_spi3.SPI_CLK.GPIO_Typedef = GPIOC;
_spi3.SPI_CLK.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spi3.SPI_CLK.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
_spi3.SPI_CLK.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spi3.SPI_CLK.GPIO_Typedef, &_spi3.SPI_CLK.GPIO_InitStruct);
// SPI3 MISO
_spi3.SPI_MISO.GPIO_Typedef = GPIOC;
_spi3.SPI_MISO.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spi3.SPI_MISO.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
_spi3.SPI_MISO.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spi3.SPI_MISO.GPIO_Typedef, &_spi3.SPI_MISO.GPIO_InitStruct);
// SPI3 MOSI
_spi3.SPI_MOSI.GPIO_Typedef = GPIOC;
_spi3.SPI_MOSI.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
_spi3.SPI_MOSI.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
_spi3.SPI_MOSI.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spi3.SPI_MOSI.GPIO_Typedef, &_spi3.SPI_MOSI.GPIO_InitStruct);
// Apply pin-remapping for SPI3 I/Os (alternative I/Os usage)
GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
// SPI3 Display shares all parameters with SPI3 but the ChipEnable, which is different
_spiDisplay.spi = &_spi3;
// SPI3 CE EEPROM
_spiDisplay.SPI_CE.GPIO_Typedef = GPIOE;
_spiDisplay.SPI_CE.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
_spiDisplay.SPI_CE.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
_spiDisplay.SPI_CE.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spiDisplay.SPI_CE.GPIO_Typedef, &_spiDisplay.SPI_CE.GPIO_InitStruct);
// SPI3 EEPROM shares all parameters with SPI3 but the ChipEnable, which is different
_spiEEPROM.spi = &_spi3;
// SPI3 CE EEPROM
_spiEEPROM.SPI_CE.GPIO_Typedef = GPIOE;
_spiEEPROM.SPI_CE.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
_spiEEPROM.SPI_CE.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
_spiEEPROM.SPI_CE.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_spiEEPROM.SPI_CE.GPIO_Typedef, &_spiEEPROM.SPI_CE.GPIO_InitStruct);
return returnValue;
}