Device Tree Bindings For mipi-dsi - Allwinner R16 to DLPC3433 - linux-device-driver

I have a custom board that is supposed to use a MIPI-DSI video signal from the allwinner R16, that is supposed to be received by the TI DLPC3433.
[R16] >>>>>>> MIPI-DSI >>>>>>>> [DLPC3433]
Here are the datasheets:
https://www.ti.com/lit/ds/symlink/dlpc3433.pdf?ts=1601313127857&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FDLPC3433
https://linux-sunxi.org/images/b/b3/R16_Datasheet_V1.4_%281%29.pdf
I want to properly configure the device tree. So far, I don't have a perfect indication that any video signal is being produced. What do I need to put in my device tree configuration to make it work? I am having trouble knowing exactly with documentation and examples. Where do I need to define the properties of the DLPC3433? And how would I define the properties for the DLPC3433?
Please see parts of the device tree below:
&i2c1 {
pinctrl-names = "default";
pinctrl-0 = <&i2c1_pins_a>;
clock-frequency = <100000>; /* i2c bus frequency 100 KHz */
status = "okay";
dsi_hdmi_bridge#4d {
compatible = "ite,it6263";
reg = <0x4d>;
reset-gpios = <&pio 4 9 GPIO_ACTIVE_LOW>; /* PE9 */
port {
it6263_in_dsi: endpoint {
clock-lanes = <4>;
data-lanes = <0 1 2 3>;
remote-endpoint = <&dsi_out_it6263>;
};
};
};
};
...
&tcon0 {
// compatible = "allwinner,sun8i-a33-tcon";
status = "okay";
};
&dsi {
// compatible = "allwinner,sun6i-a31-mipi-dsi";
status = "okay";
ports {
port#1 {
reg = <1>;
dsi_out_it6263: endpoint {
remote-endpoint = <&it6263_in_dsi>;
};
};
};
};
&dphy {
// compatible = "allwinner,sun6i-a31-mipi-dphy";
status = "okay";
};
And here is what that device tree includes from the sun8i-a33.dtsi
dsi: dsi#1ca0000 {
compatible = "allwinner,sun6i-a31-mipi-dsi";
reg = <0x01ca0000 0x1000>;
interrupts = <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_MIPI_DSI>,
<&ccu CLK_DSI_SCLK>;
clock-names = "bus", "mod";
resets = <&ccu RST_BUS_MIPI_DSI>;
phys = <&dphy>;
phy-names = "dphy";
status = "disabled";
ports {
#address-cells = <1>;
#size-cells = <0>;
port#0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
dsi_in_tcon0: endpoint {
remote-endpoint = <&tcon0_out_dsi>;
};
};
};
};
dphy: d-phy#1ca1000 {
compatible = "allwinner,sun6i-a31-mipi-dphy";
reg = <0x01ca1000 0x1000>;
clocks = <&ccu CLK_BUS_MIPI_DSI>,
<&ccu CLK_DSI_DPHY>;
clock-names = "bus", "mod";
resets = <&ccu RST_BUS_MIPI_DSI>;
status = "disabled";
#phy-cells = <0>;
};
fe0: display-frontend#1e00000 {
compatible = "allwinner,sun8i-a33-display-frontend";
reg = <0x01e00000 0x20000>;
interrupts = <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_DE_FE>, <&ccu CLK_DE_FE>,
<&ccu CLK_DRAM_DE_FE>;
clock-names = "ahb", "mod",
"ram";
resets = <&ccu RST_BUS_DE_FE>;
ports {
#address-cells = <1>;
#size-cells = <0>;
fe0_out: port#1 {
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
fe0_out_be0: endpoint#0 {
reg = <0>;
remote-endpoint = <&be0_in_fe0>;
};
};
};
};
be0: display-backend#1e60000 {
compatible = "allwinner,sun8i-a33-display-backend";
reg = <0x01e60000 0x10000>, <0x01e80000 0x1000>;
reg-names = "be", "sat";
interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_DE_BE>, <&ccu CLK_DE_BE>,
<&ccu CLK_DRAM_DE_BE>, <&ccu CLK_BUS_SAT>;
clock-names = "ahb", "mod",
"ram", "sat";
resets = <&ccu RST_BUS_DE_BE>, <&ccu RST_BUS_SAT>;
reset-names = "be", "sat";
assigned-clocks = <&ccu CLK_DE_BE>;
assigned-clock-rates = <300000000>;
ports {
#address-cells = <1>;
#size-cells = <0>;
be0_in: port#0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
be0_in_fe0: endpoint#0 {
reg = <0>;
remote-endpoint = <&fe0_out_be0>;
};
};
be0_out: port#1 {
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
be0_out_drc0: endpoint#0 {
reg = <0>;
remote-endpoint = <&drc0_in_be0>;
};
};
};
};

Related

Linux i2c touch device driver probe not be called

I try to add focaltech touch driver to my board, the fts_ts_init() is worked, but the ->probe() not be called, I do not why. CONFIG_OF is opened.
Driver code:
static const struct i2c_device_id fts_ts_id[] = {
{FTS_DRIVER_NAME, 0},
{}
};
static const struct of_device_id fts_dt_match[] = {
{.compatible = "focaltech,fts", },
{}
};
MODULE_DEVICE_TABLE(of, fts_dt_match);
static struct i2c_driver fts_ts_driver = {
.probe = fts_ts_probe,
.remove = fts_ts_remove,
.driver = {
.name = FTS_DRIVER_NAME,
.owner = THIS_MODULE,
#if defined(CONFIG_PM) && FTS_PATCH_COMERR_PM
.pm = &fts_dev_pm_ops,
#endif
.of_match_table = of_match_ptr(fts_dt_match),
},
.id_table = fts_ts_id,
};
static int __init fts_ts_init(void)
{
int ret = 0;
FTS_FUNC_ENTER();
ret = i2c_add_driver(&fts_ts_driver);
printk("[FTS_TS] ret=%d\n", ret);
if (ret)
FTS_ERROR("Focaltech touch screen driver init failed!");
FTS_FUNC_EXIT();
return ret;
}
module_init(fts_ts_init);
Device Tree Source:
i2c4: i2c#0x10054000 {
compatible = "ingenic,x2000-i2c";
reg = <0x10054000 0x1000>;
interrupt-parent = <&core_intc>;
interrupts = <IRQ_I2C4>;
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
focaltech#38{
compatible = "focaltech,fts";
reg = <0x38>;
interrupt-parent = <&gpa>;
interrupts = <3 0x2>;
focaltech,reset-gpio = <&gpa 0 GPIO_ACTIVE_LOW >;
focaltech,irq-gpio = <&gpa 3 0x2 >;
focaltech,max-touch-number = <2>;
focaltech,display-coords = <0 0 800 480>;
status = "okay";
};
};
I try to write the node in /, and use a simple paltform drvier, of_match_table is the same, ->probe() is called.

mfrc522 spi connection via hal library

I am trying to make connection by HAL_SPI_*() API with mfrc522 and at least read VersionReg register , but what address I want to read return its address in data in other words it seems to has a echo!
Here is my SPI initialisation:
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
and here is my function to read a register:
HAL_GPIO_WritePin(RD_SS_Port, RD_SS_Pin, GPIO_PIN_RESET);
Address=0x37;
ucAddr = ((Address<<1)&0x7E)|0x80;
// ucAddr=0xb7;
d[0]=ucAddr;
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) { }
if (HAL_SPI_Transmit(&hspi1,d,2,20) != HAL_OK)
{
printf("send error\r\n");
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) { }
if (HAL_SPI_Receive(&hspi1,r,1,20) != HAL_OK)
{
printf("Receive error\r\n");
}
// printf("i2=%x s[0]=%x r[0]=%x r[1]=%x \r\n",i,s[0],r[0],r[1]);
ucResult=r[0];
return ucResult;
I will appreciate if some one can help me.
Actually the first read is ok and I can read VersionReg once after reset .
but even when I put it in a loop , just the first read is ok(0x92) and the others read (0xee) which is the thing I have sent to it.

Can't get file using "GetSectionFromAnyFv" or going over all files using firmware volume protocol->GetNextFile

I donwloaded BIOS rom and get list of files using UEFITool:
ROM Structure
So i know "names" of all files that exist. Then i tried to get file using "GetSectionFromAnyFv" but can't get all files, just files in volume under red arrow. For example volume under violet arrow also have files, but i can't get it.
LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NumberOfHandles, &HandleBuffer) return only 1 handle [NumberOfHandles = 1], but as i can see there are more than 1 volume.
Same if i try get file using for(for NumberOfHandles) and iterate over all files getting guids. Just can't get all files.
What could be the problem?
P.S.: ProcessFirmwareVolume for every FV2 HOBs return 20 so that means that "firmware volume block protocol" is alredy processed.
#include "FileByGuid.h"
EFI_GUID TextToGuid(CHAR16* stGUID)
{
EFI_GUID NameGuid;
stGUID[8] = '\0';
stGUID[13] = '\0';
stGUID[18] = '\0';
NameGuid.Data1 = (UINT32)StrHexToUintn(&stGUID[0]);
NameGuid.Data2 = (UINT16)StrHexToUintn(&stGUID[9]);
NameGuid.Data3 = (UINT16)StrHexToUintn(&stGUID[14]);
for (int i = 23; i < 37; i++)
{
Print(L"");
stGUID[i] = stGUID[i + 1];
}
UINTN D4 = StrHexToUintn(&stGUID[19]);
for (int i = 7; i >= 0; i--)
{
NameGuid.Data4[i] = (UINT8)(D4 & 0xFF);
D4 = D4 >> 8;
}
return NameGuid;
}
EFI_STATUS
EFIAPI
FileByGuidDriverEntryPoint(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE* SystemTable
)
{
EFI_FIRMWARE_VOLUME2_PROTOCOL* fv;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL* fvb;
EFI_DEVICE_PATH_PROTOCOL* dp;
EFI_BLOCK_IO2_PROTOCOL* bio;
EFI_BLOCK_IO_PROTOCOL* bio2;
EFI_FILE_PROTOCOL *OpenedFileHandle;
EFI_FILE_HANDLE Root;
EFI_STATUS Status, GetSectionStatus;
UINTN index;
EFI_HANDLE *sfsHandleBuffer = NULL;
EFI_HANDLE *fvHandleBuffer = NULL;
EFI_HANDLE *fvbHandleBuffer = NULL;
EFI_HANDLE* bioHandleBuffer = NULL;
EFI_HANDLE* bio2HandleBuffer = NULL;
EFI_HANDLE FvProtocolHandle;
UINTN sfsHandleCount = 0;
UINTN fvHandleCount = 0;
UINTN fvbHandleCount = 0;
UINTN bioHandleCount = 0;
UINTN bio2HandleCount = 0;
UINTN Size;
EFI_FV_FILETYPE FileType;
UINTN counter = 0;
VOID *Buffer;
VOID *Key;
EFI_GUID fvNameGuid;
EFI_GUID NameGuid;
CHAR16* stGUID = L"114CA60C-D965-4C13-BEF7-C4062248E1FA";
// UINTN EventIndex;
// EFI_INPUT_KEY Keys;
EFI_FV_FILE_ATTRIBUTES Attributes;
EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader;
EFI_PEI_HOB_POINTERS Hob;
// BOOLEAN MediaPresent;
// PARTITION_DETECT_ROUTINE* Routine;
// BOOLEAN MediaPresent;
// EFI_DISK_IO_PROTOCOL* DiskIo;
// EFI_DISK_IO2_PROTOCOL* DiskIo2;
gBS->SetWatchdogTimer(0, 0, 0, NULL);
gST = SystemTable;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiFirmwareVolumeBlock2ProtocolGuid, NULL, &fvbHandleCount, &fvbHandleBuffer);
AsciiPrint("\r\nfv2_block_HandleCount: %d\r\n", fvbHandleCount);
for (index = 0; index < (int)fvbHandleCount; index++)
{
//Status = gBS->OpenProtocol(fvbHandleBuffer[index], &gEfiFirmwareVolumeBlock2ProtocolGuid, (VOID**)&fvb, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
Status = gBS->HandleProtocol(fvbHandleBuffer[index], &gEfiFirmwareVolume2ProtocolGuid, &fvb);
AsciiPrint("-HP fv_block fv2 Status: %d; DevicePath: %s\r\n", Status, ConvertDevicePathToText(DevicePathFromHandle(fvbHandleBuffer[index]), TRUE, TRUE));
}
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &sfsHandleCount, &sfsHandleBuffer);
AsciiPrint("\r\nsfsHandleCount: %d\r\n", sfsHandleCount);
for (index = 0; index < (int)sfsHandleCount; index++)
AsciiPrint("-sfs[%d] handle: %d; device path: %s\r\n", index, sfsHandleBuffer[index], ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid, NULL, &sfsHandleCount, &sfsHandleBuffer);
AsciiPrint("\r\nDevicePathHandleCount: %d\r\n", sfsHandleCount);
//for (index = 0; index < (int)sfsHandleCount; index++)
// AsciiPrint("dp[%d] device path: %s\r\n", index, ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
AsciiPrint("\r\nHOB:\r\n");
for (Hob.Raw = GetHobList(); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob))
{
if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV2 || GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV || GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV3)
{
FvProtocolHandle = NULL;
FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)(UINTN)(Hob.FirmwareVolume->BaseAddress);
Status = gDS->ProcessFirmwareVolume(FirmwareVolumeHeader, Hob.FirmwareVolume2->Length, &FvProtocolHandle);
if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV3)
AsciiPrint("-FV3: Status: %d; FvProtocolHandle: %d; Extracted?:%d; AuthenStatus:%d;\r\n GUID:%g\r\n", Status, FvProtocolHandle, Hob.FirmwareVolume3->ExtractedFv, Hob.FirmwareVolume3->AuthenticationStatus, Hob.FirmwareVolume3->FvName);
else if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV2)
AsciiPrint("-FV2: Status: %d; FvProtocolHandle: %d; FileName: %g; \r\n GUID:%g\r\n", Status, FvProtocolHandle, Hob.FirmwareVolume2->FileName, Hob.FirmwareVolume2->FvName);
else
AsciiPrint("-FV: Status: %d; FvProtocolHandle: %d\r\n", Status, FvProtocolHandle);
}
}
AsciiPrint("End HOB\r\n");
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &fvHandleCount, &fvHandleBuffer);
AsciiPrint("\r\nfv2HandleCount: %d\r\n", fvHandleCount);
for (index = 0; index < (int) fvHandleCount; index++)
{
Status = gBS->HandleProtocol(fvHandleBuffer[index], &gEfiFirmwareVolume2ProtocolGuid, (VOID**) &fv);
AsciiPrint("-index: %d; HPfvStatus: %d; DevicePath: %s\r\n", index, Status, ConvertDevicePathToText(DevicePathFromHandle(fvbHandleBuffer[index]), TRUE, TRUE));
if (EFI_ERROR(Status))
continue;
FileType = EFI_FV_FILETYPE_ALL;
Key = AllocatePool(fv->KeySize);
ZeroMem(Key, fv->KeySize);
Status = fv->GetNextFile(fv, Key, &FileType, &fvNameGuid, &Attributes, &Size);
while (Status!= EFI_NOT_FOUND)
{
FileType = EFI_FV_FILETYPE_ALL;
counter++;
//if (counter % 15 == 0)
// AsciiPrint("Status: %d; __file_GUID:%g\r\n", Status, fvNameGuid);
Status = fv->GetNextFile(fv, Key, &FileType, &fvNameGuid, &Attributes, &Size);
}
AsciiPrint("sectionFilesCount: %d\r\n", counter);
counter = 0;
FreePool(Key);
}
NameGuid = TextToGuid(stGUID);
//AsciiPrint("\r\n%g\r\n", NameGuid);
GetSectionStatus = GetSectionFromAnyFv(&NameGuid, EFI_SECTION_ALL, 0, (VOID**)&Buffer, &Size);
AsciiPrint("GetSectionFromAnyFvStatus = %d\r\n", Status);
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &bioHandleCount, &bioHandleBuffer);
AsciiPrint("\r\nbioHandleCount: %d\r\n", bioHandleCount);
for (index = 0; index < (int)bioHandleCount; index++)
{
Status = gBS->HandleProtocol(bioHandleBuffer[index], &gEfiBlockIoProtocolGuid, &bio);
dp = DevicePathFromHandle(bioHandleBuffer[index]);
while (!IsDevicePathEnd(NextDevicePathNode(dp)))
dp = NextDevicePathNode(dp);
AsciiPrint("-HP BlockIO Status: %d; handle: %d; DevicePath: %s\r\n", Status, bioHandleBuffer[index], ConvertDevicePathToText(dp, TRUE, TRUE));
AsciiPrint("--MediaPresent: %d; RemovableMedia: %d; LogicalPartition: %d\r\n", bio->Media->MediaPresent, bio->Media->RemovableMedia, bio->Media->LogicalPartition);
}
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIo2ProtocolGuid, NULL, &bio2HandleCount, &bio2HandleBuffer);
AsciiPrint("\r\nbio2HandleCount: %d\r\n", bio2HandleCount);
for (index = 0; index < (int)bio2HandleCount; index++)
{
Status = gBS->HandleProtocol(bio2HandleBuffer[index], &gEfiBlockIo2ProtocolGuid, &bio2);
dp = DevicePathFromHandle(bio2HandleBuffer[index]);
while (!IsDevicePathEnd(NextDevicePathNode(dp)))
dp = NextDevicePathNode(dp);
AsciiPrint("-HP BlockIO2 Status: %d; handle: %d; DevicePath: %s\r\n", Status, bio2HandleBuffer[index], ConvertDevicePathToText(dp, TRUE, TRUE));
AsciiPrint("--MediaPresent: %d; RemovableMedia: %d; LogicalPartition: %d\r\n", bio2->Media->MediaPresent, bio2->Media->RemovableMedia, bio2->Media->LogicalPartition);
}
AsciiPrint("\r\n");
//save
if (!EFI_ERROR(GetSectionStatus))
{
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &sfsHandleCount, &sfsHandleBuffer);
for (index = 0; index < (int)sfsHandleCount; index++)
{
fs = NULL;
OpenedFileHandle = NULL;
Root = NULL;
Status = gBS->HandleProtocol(sfsHandleBuffer[index], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&fs);
if (EFI_ERROR(Status))
continue;
Status = fs->OpenVolume(fs, &Root);
Status = Root->Open(Root, &OpenedFileHandle, L"EFI\\Boot", EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status))
continue;
Status = Root->Open(Root, &OpenedFileHandle, L"file", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if (!EFI_ERROR(Status)) //уже существует
Root->Delete(OpenedFileHandle);
Status = Root->Open(Root, &OpenedFileHandle, L"file", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
if (!EFI_ERROR(Status))
{
Status = Root->Write(OpenedFileHandle, &Size, Buffer);
AsciiPrint("WriteSt:%d; DevicePath:%s\r\n", Status, ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
}
Status = Root->Close(OpenedFileHandle);
}
}
if (Buffer != NULL)
FreePool(Buffer);
return EFI_SUCCESS;
}
Getting all handles that support FV2 protocol;
Processing all HOBs so number of handles that support FV2 protocol may increase;
For FV2 protocol i get count of handles and then get Volume names (device path for handle that support FV2 protocol) and files count: Here i can see that not all volumes are processd;
GetSectionFromAnyFv(*) then not interresting part and last saving file using simple file system protocol.

STM32 cant send data with esp8266 thingspeak.what did I wrong?

I am working on a project about send PWM values and time values(with RTC) from stm32 to wifi module and bluetooth module at the same time.I wrote a code for esp8266 and esp8266 connected to my phone.But didnt send any value to bluetooth module or thingspeak.What did I wrong?(I cant use HAL Library for this project)
static void Clear_ESPBuffer(void)
{
uint16_t i;
for(i=0;i<ESP8266BUFFER_LENGHT;i++)
g_arrui8ESP8266Buf[i] = 0;
ESPWriteIndex=0;
}
//esp8266 configuration
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1, &USART_InitStruct);
//bluetooth modulu configuration
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_Init(USART3, &USART_InitStruct);
USART_Cmd(USART3, ENABLE); // USART3 aktif edilir.
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART1, ENABLE);
}
static void ESP8266_Init(void)
{
static uint8_t ESPInitCase=0;
switch(ESPInitCase)
{
case 0:
// Standart AT Komutu gonderilir , Cevabi OK olmalidir.
USART_puts(USART1,"AT\r\n");
Delay(1000000L);
ESPInitCase = 1;
break;
case 1:
if (strstr(g_arrui8ESP8266Buf,"OK") != NULL)
{
Clear_ESPBuffer();
USART_puts(USART3,"Module Erisildi\n");
ESPInitCase = 2;
}
else
{
Clear_ESPBuffer();
USART_puts(USART3,"Not Founded");
ESPInitCase = 0;
}
break;
case 2:
USART_puts(USART1,"AT+CWMODE?\r\n");
Delay(1000000L);
ESPInitCase = 3;
break;
case 3:
// Gelen cevap mode 1 'mi
if (strstr(g_arrui8ESP8266Buf,"+CWMODE:1") != NULL)
{
Clear_ESPBuffer();
USART_puts(USART3,"Config okey\n");
ESPInitCase = 4;
}
else
{
.
USART_puts(USART1,"AT+CWMODE=1\r\n");
USART_puts(USART1,"AT+RST\r\n");
Delay(1000000L);
Clear_ESPBuffer();
USART_puts(USART3,"Changed Mode.\n");
ESPInitCase = 2;
}
break;
case 4:
USART_puts(USART1,"AT+CWJAP=\"Wifi\",\"Password\"\r\n");
Delay(2000000L);
ESPInitCase = 5;
break;
case 5:
if (strstr(g_arrui8ESP8266Buf,"OK") != NULL)
{
Clear_ESPBuffer();
USART_puts(USART3,"Wifi Connected\n");
ESPInitCase = 6;
}
else
{
Delay(1000000L);
USART_puts(USART3,"waiting for wifi\n");
Delay(5000000L);
say2++;
if(say2==3)
{
USART_puts(USART3,"Not Connected\n");
ESPInitCase=8;
say2=0;
}
}
break;
case 6:
// For ıp adress
USART_puts(USART1,"AT+CIFSR\r\n");
Delay(1000000L);
ESPInitCase = 7;
break;
case 7:
if (strstr(g_arrui8ESP8266Buf,"ERROR") == NULL)
{
USART_puts(USART3," IP = \n");
USART_puts(USART3,&g_arrui8ESP8266Buf[11]);
Clear_ESPBuffer();
ESPInitCase=8;
}
else
{
Delay(1000000L);
USART_puts(USART3,"Try again.\n");
Clear_ESPBuffer();
ESPInitCase=6;
}
break;
case 8:
USART_puts(USART1,"AT+CIPSTART=\"TCP\",\"IP\",80\r\n");
// 1 saniye gecikme koyuyoruz.
Delay(1000000L);
ESPInitCase = 9;
break;
case 9:
if (strstr(g_arrui8ESP8266Buf,"CONNECT") != NULL)
{
Clear_ESPBuffer();
USART_puts(USART3,"connected to website\n");
ESPInitCase = 10;
}
else
{
Delay(1000000L);
USART_puts(USART3,"waiting for Website connection\n");
Delay(50000000L);
say++;
if(say==3)
{
USART_puts(USART3," Website didnt work .\n");
ESPInitCase=8;
say=0;
}
}
break;
case 10:
Value=Read_ADC(); // adc okunuyor
sprintf(transmitdata, "GET /update?key=9KT9JQA1PJXPTFJJ&field2=%d\r\n",value);
length=strlen(transmitdata);
length=length+2;
sprintf(transmitconf,"AT+CIPSEND=%d\r\n",length);
USART_puts(USART1,transmitconf);
Delay(10000000L);
if (strstr(g_arrui8ESP8266Buf,">") != NULL)
{
Clear_ESPBuffer();
USART_puts(USART1,transmitdata);
USART_puts(USART3,"transmitted data\n");
Delay(2000000L);
ESPInitCase=10;
}
else
{
Delay(3000000L);
USART_puts(USART3,"data length not okey\n");
ESPInitCase=8;
USART_puts(USART3,"trying to connect website again\n");
say3++;
if(say3==3)
{
USART_puts(USART3,"didnt connect.\n check config\n");
ESPInitCase=0;
say3=0;
}
}
break;
}
}
void USART1_IRQHandler(void)
{
if( USART_GetITStatus(USART1, USART_IT_RXNE) )
{
uint8_t Received_Byte = USART1->DR;
USART2->DR = Received_Byte;
if(Received_Byte != 0)
{
g_arrui8ESP8266Buf[ESPWriteIndex] = Received_Byte;
ESPWriteIndex++;
}
}
}

Sending messages through LoRaWAN using STM32

How do I send the messages through LoRaWAN?
static void PrepareTxFrame( uint8_t port )
{
switch( port ) {
case 10: {
int pos = 0;
pc.printf("Prepare message\n");
#if 0
uint32_t tempValue = ( uint32_t )( LightValue * 1000000.0 );
AppData[0] = LightMode;
AppData[1] = ( ( tempValue & 0xFF000000 ) >> 24 ) & 0xFF;
AppData[2] = ( ( tempValue & 0x00FF0000 ) >> 16 ) & 0xFF;
AppData[3] = ( ( tempValue & 0x0000FF00 ) >> 8 ) & 0xFF;
AppData[4] = ( tempValue & 0x000000FF );
#else
AppData[pos] = count;
pc.printf("\n\r");
pc.printf("The value of the counter is : %d", count);
count++;
pc.printf("\n\r");
time_t seconds = time(NULL);
printf("The time is %s", ctime(&seconds));
AppData[++pos] = seconds;
pc.printf("%d \n %d", AppData[0], AppData[1]);
pc.printf("\n\r");
#endif
pc.printf("Message Ready\n");
}
break;
case 15: {
int pos = 0;
AppData[pos++] = AppLedStateOn;
#if 0
if( IsTxConfirmed == true )
{
AppData[pos++] = LoRaMacDownlinkStatus.DownlinkCounter >> 8;
AppData[pos++] = LoRaMacDownlinkStatus.DownlinkCounter;
AppData[pos++] = LoRaMacDownlinkStatus.Rssi >> 8;
AppData[pos++] = LoRaMacDownlinkStatus.Rssi;
AppData[pos++] = LoRaMacDownlinkStatus.Snr;
}
#endif
AppDataSize = pos;
}
break;
case 224:
if( ComplianceTest.LinkCheck == true ) {
ComplianceTest.LinkCheck = false;
AppDataSize = 3;
AppData[0] = 5;
AppData[1] = ComplianceTest.DemodMargin;
AppData[2] = ComplianceTest.NbGateways;
ComplianceTest.State = 1;
} else {
switch( ComplianceTest.State ) {
case 4:
ComplianceTest.State = 1;
break;
case 1:
AppDataSize = 2;
AppData[0] = ComplianceTest.DownLinkCounter >> 8;
AppData[1] = ComplianceTest.DownLinkCounter;
break;
}
}
break;
default:
break;
}
}
/*!
* \brief
*
* Prepares the pay-load of the frame
*
* \retval [0: frame could be send, 1: error]
*/
static bool SendFrame( void )
{
McpsReq_t mcpsReq;
LoRaMacTxInfo_t txInfo;
if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK )
{
// Send empty frame in order to flush MAC commands
mcpsReq.Type = MCPS_UNCONFIRMED;
mcpsReq.Req.Unconfirmed.fBuffer = NULL;
mcpsReq.Req.Unconfirmed.fBufferSize = 0;
mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
LoRaMacUplinkStatus.Acked = false;
LoRaMacUplinkStatus.Port = 0;
LoRaMacUplinkStatus.Buffer = NULL;
LoRaMacUplinkStatus.BufferSize = 0;
SerialDisplayUpdateFrameType( false );
} else {
LoRaMacUplinkStatus.Acked = false;
LoRaMacUplinkStatus.Port = AppPort;
LoRaMacUplinkStatus.Buffer = AppData;
LoRaMacUplinkStatus.BufferSize = AppDataSize;
SerialDisplayUpdateFrameType( IsTxConfirmed );
if( IsTxConfirmed == false ) {
mcpsReq.Type = MCPS_UNCONFIRMED;
mcpsReq.Req.Unconfirmed.fPort = AppPort;
mcpsReq.Req.Unconfirmed.fBuffer = AppData;
mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize;
mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
} else {
mcpsReq.Type = MCPS_CONFIRMED;
mcpsReq.Req.Confirmed.fPort = AppPort;
mcpsReq.Req.Confirmed.fBuffer = AppData;
mcpsReq.Req.Confirmed.fBufferSize = AppDataSize;
mcpsReq.Req.Confirmed.NbTrials = 8;
mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
}
}
if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK ) {
return false;
}
return true;
}
Will the counter data and the time be sent? Also is the data in AppData the ones to be transmitted? I want the count and the timestamp to be sent every time the LoRa device transmits.
The payload to send (AppData) is given to the LoRaMAC layer through the MCPS (MAC Common Part Sublayer) request, e.g. for an unconfirmed frame:
mcpsReq.Req.Unconfirmed.fBuffer = AppData;
So physically (i.e. by RF), AppData is sent but it's encrypted and encapsulated before.
PrepareFrame() function builds the frame to send according to the PHYPayload scheme (See the "MAC Message Formats" part in the LoRaWAN™ Specification 1.0.2 document), following these fields:
MHDR (1 byte) Mac header
DevAddr (4 bytes) Address of the end-device
FCtrl (1 byte) Frame control
FCnt (2 bytes) Frame counter
FOpts (0 - 15 bytes) Frame options
FPort (0 - 1 byte) Port field
FRMPayload (0 - N bytes) MAC Frame Payload Encryption, your AppData encrypted
MIC (4 bytes) Message Integrity Code
FRMPayload is encrypted according to FPort. The encryption algorithm is based on AES 128.
If FPort = [1..255], the AppSKey key will be used to encrypt your payload.
Else (FPort = 0), it's encrypted by using the NwkSKey key.
See the LoRaMacPayloadEncrypt() function for more details.
PHYPayload will be encapsulated by the Radio PHY Layer and sent through RF.