moved platform specific stuff from core

master
Ondřej Hruška 7 years ago
parent 69720a955e
commit 8e85d44e59
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 59
      CMakeLists.txt
  2. 2
      GexCore
  3. 177
      GexUnits/test/unit_test.c
  4. 14
      GexUnits/test/unit_test.h
  5. 12
      GexUnits/units_manifest.h
  6. 76
      Inc/nrf_pins.h
  7. 109
      Inc/plat_compat.h
  8. 62
      Src/platform_resources.c

@ -1,3 +1,6 @@
# This is a dummy CmakeLists.txt file for CLion.
# It does not work, don't even try.
cmake_minimum_required(VERSION 3.9)
project(GEX_F072)
@ -20,6 +23,22 @@ add_definitions(
-DUSE_DEBUG_UART=1
-DGEX_PLAT_F072_ZERO
-DHAL_TSC_MODULE_ENABLED
-DENABLE_UNIT_1WIRE=1
-DENABLE_UNIT_ADC=1
-DENABLE_UNIT_DAC=1
-DENABLE_UNIT_DIGITAL_IN=1
-DENABLE_UNIT_DIGITAL_OUT=1
-DENABLE_UNIT_FCAP=1
-DENABLE_UNIT_I2C=1
-DENABLE_UNIT_NEOPIXEL=1
-DENABLE_UNIT_SIMPLE_PWM=1
-DENABLE_UNIT_SIPO=1
-DENABLE_UNIT_SPI=1
-DENABLE_UNIT_TEMPLATE=1
-DENABLE_UNIT_TEST=1
-DENABLE_UNIT_TOUCH=1
-DENABLE_UNIT_USART=1
)
FILE(GLOB_RECURSE SOURCE_FILES
@ -28,8 +47,10 @@ FILE(GLOB_RECURSE SOURCE_FILES
Drivers/*.h
Middlewares/*.c
Middlewares/*.h
User/*.c
User/*.h
GexCore/*.c
GexCore/*.h
GexUnits/*.c
GexUnits/*.h
Src/*.c
Src/*.h
)
@ -45,18 +66,18 @@ include_directories(
Drivers/STM32F0xx_HAL_Driver/Inc/Legacy
# USB Library
User/USB/STM32_USB_Device_Library/Core/Inc
GexCore/USB/STM32_USB_Device_Library/Core/Inc
# USB Device Classes
User/USB/STM32_USB_Device_Library/Class/AUDIO/Inc
User/USB/STM32_USB_Device_Library/Class/CDC/Inc
User/USB/STM32_USB_Device_Library/Class/CustomHID/Inc
User/USB/STM32_USB_Device_Library/Class/DFU/Inc
User/USB/STM32_USB_Device_Library/Class/HID/Inc
User/USB/STM32_USB_Device_Library/Class/MSC/Inc
User/USB/STM32_USB_Device_Library/Class/MSC_CDC
GexCore/USB/STM32_USB_Device_Library/Class/AUDIO/Inc
GexCore/USB/STM32_USB_Device_Library/Class/CDC/Inc
GexCore/USB/STM32_USB_Device_Library/Class/CustomHID/Inc
GexCore/USB/STM32_USB_Device_Library/Class/DFU/Inc
GexCore/USB/STM32_USB_Device_Library/Class/HID/Inc
GexCore/USB/STM32_USB_Device_Library/Class/MSC/Inc
GexCore/USB/STM32_USB_Device_Library/Class/MSC_CDC
# Other vendor libraries
User/USB/STM32_TouchSensing_Library/inc
GexCore/USB/STM32_TouchSensing_Library/inc
# FreeRTOS
Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
@ -65,15 +86,15 @@ include_directories(
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0
# Application
User
User/USB
User/utils
User/TinyFrame
User/framework
User/platform
User/tasks
User/units
GexCore
GexCore/USB
GexCore/utils
GexCore/TinyFrame
GexCore/framework
GexCore/platform
GexCore/tasks
Inc
GexUnits
)
add_executable(main ${SOURCE_FILES})

@ -1 +1 @@
Subproject commit b8909fca0658712186632a31e96d4722f2186c58
Subproject commit 20639b77a615eac5538941972f47fed717949e47

@ -1,177 +0,0 @@
//
// Created by MightyPork on 2017/11/25.
//
#include "comm/messages.h"
#include "unit_base.h"
#include "unit_test.h"
/** Private data structure */
struct priv {
uint32_t unused;
};
// ------------------------------------------------------------------------
/** Load from a binary buffer stored in Flash */
static void Tst_loadBinary(Unit *unit, PayloadParser *pp)
{
struct priv *priv = unit->data;
//
}
/** Write to a binary buffer for storing in Flash */
static void Tst_writeBinary(Unit *unit, PayloadBuilder *pb)
{
struct priv *priv = unit->data;
//
}
// ------------------------------------------------------------------------
/** Parse a key-value pair from the INI file */
static error_t Tst_loadIni(Unit *unit, const char *key, const char *value)
{
return E_BAD_KEY;
}
/** Generate INI file section for the unit */
static void Tst_writeIni(Unit *unit, IniWriter *iw)
{
struct priv *priv = unit->data;
//
}
// ------------------------------------------------------------------------
/** Allocate data structure and set defaults */
static error_t Tst_preInit(Unit *unit)
{
struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv));
if (priv == NULL) return E_OUT_OF_MEM;
//
return E_SUCCESS;
}
/** Finalize unit set-up */
static error_t Tst_init(Unit *unit)
{
bool suc = true;
struct priv *priv = unit->data;
//
return E_SUCCESS;
}
/** Tear down the unit */
static void Tst_deInit(Unit *unit)
{
struct priv *priv = unit->data;
//
// Free memory
free_ck(unit->data);
}
// ------------------------------------------------------------------------
enum PinCmd_ {
CMD_PING = 0,
CMD_ECHO = 1,
CMD_BULKREAD = 2,
CMD_BULKWRITE = 3,
};
// this is a very long text for testing bulk read
static const char *longtext = "The history of all hitherto existing societies is the history of class struggles.\n\nFreeman and slave, patrician and plebeian, lord and serf, guild-master and journeyman, in a word, oppressor and oppressed, stood in constant opposition to one another, carried on an uninterrupted, now hidden, now open fight, a fight that each time ended, either in a revolutionary re-constitution of society at large, or in the common ruin of the contending classes.\n\nIn the earlier epochs of history, we find almost everywhere a complicated arrangement of society into various orders, a manifold gradation of social rank. In ancient Rome we have patricians, knights, plebeians, slaves; in the Middle Ages, feudal lords, vassals, guild-masters, journeymen, apprentices, serfs; in almost all of these classes, again, subordinate gradations.\n\nThe modern bourgeois society that has sprouted from the ruins of feudal society has not done away with class antagonisms. It has but established new classes, new conditions of oppression, new forms of struggle in place of the old ones. Our epoch, the epoch of the bourgeoisie, possesses, however, this distinctive feature: it has simplified the class antagonisms. Society as a whole is more and more splitting up into two great hostile camps, into two great classes, directly facing each other: Bourgeoisie and Proletariat.\n\nFrom the serfs of the Middle Ages sprang the chartered burghers of the earliest towns. From these burgesses the first elements of the bourgeoisie were developed.\n\nThe discovery of America, the rounding of the Cape, opened up fresh ground for the rising bourgeoisie. The East-Indian and Chinese markets, the colonisation of America, trade with the colonies, the increase in the means of exchange and in commodities generally, gave to commerce, to navigation, to industry, an impulse never before known, and thereby, to the revolutionary element in the tottering feudal society, a rapid development.\n\nThe feudal system of industry, under which industrial production was monopolised by closed guilds, now no longer sufficed for the growing wants of the new markets. The manufacturing system took its place. The guild-masters were pushed on one side by the manufacturing middle class; division of labour between the different corporate guilds vanished in the face of division of labour in each single workshop.\n\nMeantime the markets kept ever growing, the demand ever rising. Even manufacture no longer sufficed. Thereupon, steam and machinery revolutionised industrial production. The place of manufacture was taken by the giant, Modern Industry, the place of the industrial middle class, by industrial millionaires, the leaders of whole industrial armies, the modern bourgeois.\n\nModern industry has established the world-market, for which the discovery of America paved the way. This market has given an immense development to commerce, to navigation, to communication by land. This development has, in its time, reacted on the extension of industry; and in proportion as industry, commerce, navigation, railways extended, in the same proportion the bourgeoisie developed, increased its capital, and pushed into the background every class handed down from the Middle Ages.\n\nWe see, therefore, how the modern bourgeoisie is itself the product of a long course of development, of a series of revolutions in the modes of production and of exchange.\n\nEach step in the development of the bourgeoisie was accompanied by a corresponding political advance of that class. An oppressed class under the sway of the feudal nobility, an armed and self-governing association in the mediaeval commune; here independent urban republic (as in Italy and Germany), there taxable \"third estate\" of the monarchy (as in France), afterwards, in the period of manufacture proper, serving either the semi-feudal or the absolute monarchy as a counterpoise against the nobility, and, in fact, corner-stone of the great monarchies in general, the bourgeoisie has at last, since the establishment of Modern Industry and of the world-market, conquered for itself, in the modern representative State, exclusive political sway. The executive of the modern State is but a committee for managing the common affairs of the whole bourgeoisie.";
static void br_longtext(struct bulk_read *bulk, uint32_t chunk, uint8_t *buffer)
{
// clean-up request
if (buffer == NULL) {
free_ck(bulk);
return;
}
memcpy(buffer, longtext+bulk->offset, chunk);
}
static void bw_dump(struct bulk_write *bulk, const uint8_t *chunk, uint32_t len)
{
// clean-up request
if (chunk == NULL) {
free_ck(bulk);
return;
}
dbg("\r\nBulk write at %d, len %d", (int)bulk->offset, (int)len);
PUTSN((const char *) chunk, (uint16_t) len);
PUTS("\r\n");
}
/** Handle a request message */
static error_t Tst_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
{
switch (command) {
case CMD_PING:
com_respond_ok(frame_id);
return E_SUCCESS;
case CMD_ECHO:;
uint32_t len;
const uint8_t *data = pp_tail(pp, &len);
com_respond_buf(frame_id, MSG_SUCCESS, data, len);
return E_SUCCESS;
case CMD_BULKREAD:;
BulkRead *br = malloc_ck(sizeof(struct bulk_read));
assert_param(br);
br->len = (uint32_t) strlen(longtext);
br->frame_id = frame_id;
br->read = br_longtext;
bulkread_start(comm, br);
return E_SUCCESS;
case CMD_BULKWRITE:;
BulkWrite *bw = malloc_ck(sizeof(struct bulk_write));
assert_param(bw);
bw->len = 10240;
bw->frame_id = frame_id;
bw->write = bw_dump;
bulkwrite_start(comm, bw);
return E_SUCCESS;
default:
return E_UNKNOWN_COMMAND;
}
}
// ------------------------------------------------------------------------
/** Unit template */
const UnitDriver UNIT_TEST = {
.name = "TEST",
.description = "Test unit",
// Settings
.preInit = Tst_preInit,
.cfgLoadBinary = Tst_loadBinary,
.cfgWriteBinary = Tst_writeBinary,
.cfgLoadIni = Tst_loadIni,
.cfgWriteIni = Tst_writeIni,
// Init
.init = Tst_init,
.deInit = Tst_deInit,
// Function
.handleRequest = Tst_handleRequest,
};

@ -1,14 +0,0 @@
//
// Created by MightyPork on 2017/11/25.
//
// Testing unit that uses most of the protocol to verify the core functionality
//
#ifndef U_TEST_H
#define U_TEST_H
#include "unit.h"
extern const UnitDriver UNIT_TEST;
#endif //U_TEST_H

@ -1,7 +1,7 @@
// This is a GEX units manifest file
// For a unit to be included in the firmware, it's uppercase name
// For a unit to be included in the firmware, its uppercase name
// must be included in the GEX_UNITS list in build.mk, and it must have
// a section here.
// an entry here.
#ifdef ENABLE_UNIT_1WIRE
#include "1wire/unit_1wire.h"
@ -47,14 +47,6 @@
#include "spi/unit_spi.h"
#endif
#ifdef ENABLE_UNIT_TEMPLATE
#include "template/unit_template.h"
#endif
#ifdef ENABLE_UNIT_TEST
#include "test/unit_test.h"
#endif
#ifdef ENABLE_UNIT_TOUCH
#include "touch/unit_touch.h"
#endif

@ -0,0 +1,76 @@
//
// Created by MightyPork on 2018/04/06.
//
#ifndef GEX_CORE_NRF_PINS_H
#define GEX_CORE_NRF_PINS_H
#include "platform.h"
#include "rsc_enum.h"
#if defined(GEX_PLAT_F072_DISCOVERY) || defined(GEX_PLAT_F072_HUB)
// This config was used only for development when NRF was enabled for those platforms. It is normally disabled.
#define NRF_SPI SPI1
#define NRF_R_SPI R_SPI1
#define NRF_IRQ_Pin LL_GPIO_PIN_10
#define NRF_IRQ_GPIO_Port GPIOB
#define NRF_R_IRQ R_PB10
#define NRF_EXTI_LINENUM 10
#define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTB
#define NRF_NSS_Pin LL_GPIO_PIN_11
#define NRF_NSS_GPIO_Port GPIOB
#define NRF_R_NSS R_PB11
#define NRF_CE_Pin LL_GPIO_PIN_12
#define NRF_CE_GPIO_Port GPIOB
#define NRF_R_CE R_PB12
#define NRF_RST_Pin LL_GPIO_PIN_13
#define NRF_RST_GPIO_Port GPIOB
#define NRF_R_RST R_PB13
#define NRF_R_SCK R_PA5
#define NRF_SCK_AF LL_GPIO_AF_0
#define NRF_R_MISO R_PA6
#define NRF_MISO_AF LL_GPIO_AF_0
#define NRF_R_MOSI R_PA7
#define NRF_MOSI_AF LL_GPIO_AF_0
#elif defined(GEX_PLAT_F072_ZERO)
#define NRF_SPI SPI2
#define NRF_R_SPI R_SPI2
#define NRF_IRQ_Pin LL_GPIO_PIN_15
#define NRF_IRQ_GPIO_Port GPIOC
#define NRF_R_IRQ R_PC15
#define NRF_EXTI_LINENUM 15
#define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTC
#define NRF_NSS_Pin LL_GPIO_PIN_13
#define NRF_NSS_GPIO_Port GPIOC
#define NRF_R_NSS R_PC13
#define NRF_CE_Pin LL_GPIO_PIN_14
#define NRF_CE_GPIO_Port GPIOC
#define NRF_R_CE R_PC14
#define NRF_RST_Pin LL_GPIO_PIN_12
#define NRF_RST_GPIO_Port GPIOC
#define NRF_R_RST R_PC12
#define NRF_R_SCK R_PB13
#define NRF_SCK_AF LL_GPIO_AF_0
#define NRF_R_MISO R_PC2
#define NRF_MISO_AF LL_GPIO_AF_1
#define NRF_R_MOSI R_PC3
#define NRF_MOSI_AF LL_GPIO_AF_1
#else
#error "Missing NRF config for this platform."
#endif
#endif //GEX_NRF_PINS_H

@ -0,0 +1,109 @@
//
// Created by MightyPork on 2018/07/07.
//
#ifndef GEX_PLAT_COMPAT_H
#define GEX_PLAT_COMPAT_H
#define PLAT_AHB_MHZ 48
#define PLAT_APB1_MHZ 48
#include <stm32f0xx.h>
#include <stm32f0xx_ll_adc.h>
#include <stm32f0xx_ll_bus.h>
#include <stm32f0xx_ll_comp.h>
#include <stm32f0xx_ll_cortex.h>
#include <stm32f0xx_ll_crc.h>
#include <stm32f0xx_ll_crs.h>
#include <stm32f0xx_ll_dac.h>
#include <stm32f0xx_ll_dma.h>
#include <stm32f0xx_ll_exti.h>
#include <stm32f0xx_ll_gpio.h>
#include <stm32f0xx_ll_i2c.h>
#include <stm32f0xx_ll_iwdg.h>
#include <stm32f0xx_ll_pwr.h>
#include <stm32f0xx_ll_rcc.h>
#include <stm32f0xx_ll_rtc.h>
#include <stm32f0xx_ll_spi.h>
#include <stm32f0xx_ll_system.h>
#include <stm32f0xx_ll_tim.h>
#include <stm32f0xx_ll_usart.h>
#include <stm32f0xx_ll_utils.h>
#include <stm32f0xx_ll_wwdg.h>
#define GEX_PLAT_F072 1
// size, determines position of the flash storage
#define FLASH_SIZE (128*1024)
#define SETTINGS_BLOCK_SIZE (1024*2) // this must be a multiple of FLASH pages
#define SETTINGS_FLASH_ADDR (0x08000000 + FLASH_SIZE - SETTINGS_BLOCK_SIZE)
// Number of GPIO ports A,B,C,D,E,F
#define PORTS_COUNT 6
#define PLAT_USB_PU_CTL 1
#if defined(GEX_PLAT_F072_DISCOVERY)
// platform name for the version string
#define GEX_PLATFORM "STM32F072-Discovery"
// Lock jumper config
#define LOCK_JUMPER_PORT 'A'
#define LOCK_JUMPER_PIN 0
#define PLAT_LOCK_BTN 1 // toggle button instead of a jumper
#define PLAT_LOCK_1CLOSED 1 // toggle button active in log. 1
// Status LED config
#define STATUS_LED_PORT 'C'
#define STATUS_LED_PIN 6 // RED LED "UP"
#elif defined(GEX_PLAT_F072_HUB)
// platform name for the version string
#define GEX_PLATFORM "STM32F072-HUB"
#define PLAT_FULL_XTAL 1
// Lock jumper config
#define LOCK_JUMPER_PORT 'D'
#define LOCK_JUMPER_PIN 2
#define PLAT_LOCK_BTN 1 // toggle button instead of a jumper
#define PLAT_LOCK_1CLOSED 0 // toggle button active in log. 1
// Status LED config
#define STATUS_LED_PORT 'A'
#define STATUS_LED_PIN 15 // RED LED "UP"
#elif defined(GEX_PLAT_F072_ZERO)
// platform name for the version string
#define GEX_PLATFORM "STM32F072-ZERO"
#define PLAT_FULL_XTAL 1
// Lock jumper config
#define LOCK_JUMPER_PORT 'D'
#define LOCK_JUMPER_PIN 2
#define PLAT_LOCK_BTN 1 // toggle button instead of a jumper
#define PLAT_LOCK_1CLOSED 1 // toggle button active in log. 1
// Status LED config
#define STATUS_LED_PORT 'A'
#define STATUS_LED_PIN 15
#define SUPPORT_NRF 1
#else
#error Bad platform
#endif
// Debug UART
#define DEBUG_USART_BAUD 115200
#define DEBUG_USART USART1
#define DEBUG_USART_RSC R_USART1
#define DEBUG_USART_PORT 'A'
#define DEBUG_USART_PIN 9
#define DEBUG_USART_AF 1
#define DEBUG_USART_PCLK PLAT_APB1_HZ
// FreeRTOS config
#define PLAT_FREERTOS_LOWEST_INTERRUPT_PRIORITY 3
#define PLAT_FREERTOS_MAX_SYSCALL_INTERRUPT_PRIORITY 1
#define PLAT_FREERTOS_PRIO_BITS 2
#define PLAT_FREERTOS_USE_PORT_OPTIMISED_TASK_SELECTION 0
#endif //GEX_PLAT_COMPAT_H

@ -0,0 +1,62 @@
//
// Created by MightyPork on 2018/07/07.
//
#include "platform.h"
#include "resources.h"
uint32_t plat_init_resources2(void)
{
uint32_t rv = 0; // accumulate error codes
// Free all present resources
{
rsc_free(NULL, R_ADC1);
// rsc_free(NULL, R_CAN1);
// rsc_free_range(NULL, R_COMP1, R_COMP2);
rsc_free(NULL, R_DAC1);
// rsc_free(NULL, R_HDMI_CEC);
rsc_free(NULL, R_TSC);
rsc_free_range(NULL, R_I2C1, R_I2C2);
// rsc_free_range(NULL, R_I2S1, R_I2S2);
rsc_free_range(NULL, R_SPI1, R_SPI2);
rsc_free_range(NULL, R_TIM1, R_TIM3);
rsc_free_range(NULL, R_TIM6, R_TIM7);
rsc_free_range(NULL, R_TIM14, R_TIM17);
rsc_free_range(NULL, R_USART1, R_USART4);
rsc_free_range(NULL, R_DMA1_1, R_DMA1_7);
rsc_free_range(NULL, R_PA0, R_PA15);
rsc_free_range(NULL, R_PB0, R_PB15);
rsc_free_range(NULL, R_PC0, R_PC15);
rsc_free(NULL, R_PD2);
rsc_free_range(NULL, R_PF0, R_PF1);
}
// Claim resources not available due to board layout or internal usage
{
// HAL timebase
rv |= rsc_claim(&UNIT_SYSTEM, R_TIM17);
// HSE crystal
rv |= rsc_claim(&UNIT_SYSTEM, R_PF0);
#if PLAT_FULL_XTAL
rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode
#endif
// SWD
// rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
// rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
// USB
rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
#if defined(GEX_PLAT_F072_ZERO)
// unconnected pins
rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC0, R_PC1);
rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC4, R_PC9);
#endif
}
return rv;
}
Loading…
Cancel
Save